WEBVTT

1
00:00.800 --> 00:02.660
Hi everyone.

2
00:02.720 --> 00:06.560
In this video I will show you how to validation.

3
00:08.780 --> 00:17.180
For the "DTO", Data transfer object and let's click on inside the validation topics here.

4
00:17.330 --> 00:20.900
Firstly we will install 2 packages right here.

5
00:20.930 --> 00:21.650
Let me copy.

6
00:28.160 --> 00:38.990
And the first one will be class validator for validation object and transformer.

7
00:39.020 --> 00:43.970
We will use that later okay let's focus on the class validator.

8
00:45.320 --> 00:52.460
If I scroll down a little bit right here, now you can see it has a some decorator.

9
00:52.460 --> 00:57.800
Something like this is email is not empty okay.

10
00:58.070 --> 01:00.830
This is from the class validator.

11
01:00.830 --> 01:13.310
And class validator library already provides some built-in validation rules.

12
01:13.340 --> 01:14.030
Right.

13
01:14.450 --> 01:16.340
For that reason we can use that.

14
01:16.910 --> 01:20.900
Let me show you in the createDto here.

15
01:20.900 --> 01:25.430
I will use @IsNotEmpty()

16
01:25.700 --> 01:29.780
And I will copy this and pass it inside the description.

17
01:31.550 --> 01:32.270
Let's see.

18
01:32.900 --> 01:40.970
Okay, let's see what happens if I use something like this, I will remove the title.

19
01:41.870 --> 01:46.730
And I send, you can see it's created right.

20
01:47.420 --> 01:49.010
And that's not what we want.

21
01:49.040 --> 01:52.280
The reason because we NOT.

22
01:58.820 --> 02:01.670
Let me see, let me scroll down a little bit.

23
02:02.240 --> 02:06.710
We NOT you the validation pipe right here.

24
02:06.860 --> 02:09.950
We must use the Global Pipes.

25
02:10.610 --> 02:10.880
Okay.

26
02:10.880 --> 02:15.770
Let me copy this line right here and go to the main.ts

27
02:15.800 --> 02:21.080
And right here I will pass this and validation pipe from.

28
02:21.620 --> 02:24.740
nestjs/common, okay

29
02:26.180 --> 02:29.630
Make sure we use the global pipe.

30
02:30.950 --> 02:39.040
And let me send again. Now you may see, it already format for me the message right here.

31
02:39.430 --> 02:40.030
Very cool.

32
02:40.060 --> 02:40.720
Right.

33
02:40.750 --> 02:48.280
If I remove the description also and I will send, this title should not be empty or description should

34
02:48.280 --> 02:48.940
not be empty.

35
02:49.390 --> 02:49.810
Right?

36
02:49.840 --> 02:50.620
Very cool.

37
02:50.650 --> 02:59.530
And in order to read more about the class validator you can search the class validator.

38
03:02.830 --> 03:03.430
Right here.

39
03:07.300 --> 03:11.800
Now you can see we have many more validator.

40
03:11.830 --> 03:20.260
For example a min or max is this is email, Len something like this right.

41
03:20.290 --> 03:23.020
You can read more about that and try a little bit with that.

42
03:24.850 --> 03:27.070
I will leave that job for you okay.

43
03:29.320 --> 03:35.920
And in this course we will use more and more class validator.

44
03:35.950 --> 03:37.030
Don't worry about that.

45
03:37.960 --> 03:40.960
And it's also very popular package right.

46
03:43.870 --> 03:48.280
So that's how we can validation.

47
03:48.700 --> 03:50.890
I will see you in the next one.