WEBVTT

1
00:00.740 --> 00:02.660
Hi everyone.

2
00:02.750 --> 00:11.840
Before I go into the validation step, I want to talk a little bit more about "DTO".

3
00:11.930 --> 00:22.190
Now in previous video we already see, when we send the data we will send the "DTO", right?

4
00:22.220 --> 00:28.400
And when we response the data from the server we need the "DTO".

5
00:28.640 --> 00:38.510
Because you can see in here we don't need to check the "Id" or the or actually we need the ID, but we

6
00:38.510 --> 00:41.390
don't need the "__v" right here.

7
00:41.420 --> 00:42.140
Right?

8
00:42.350 --> 00:43.190
I don't want that

9
00:43.370 --> 00:48.770
So I can easily remove that using the DTO.

10
00:51.230 --> 01:01.210
And you can see right here, we can easily do something like, like this Right here.

11
01:01.210 --> 01:03.370
We will save that into the variable.

12
01:04.210 --> 01:04.660
Right.

13
01:05.020 --> 01:09.490
data = await

14
01:12.940 --> 01:14.320
Sorry, it's same name.

15
01:14.320 --> 01:18.040
I will use the "post" right here.

16
01:20.650 --> 01:26.260
And with the "post" I can return the title.

17
01:27.190 --> 01:30.100
What's the title and description?

18
01:35.470 --> 01:37.270
post.description

19
01:37.600 --> 01:38.170
Right.

20
01:38.740 --> 01:40.540
We can do that.

21
01:43.810 --> 01:47.320
And let's see I will undo

22
01:55.330 --> 01:57.250
Here you can say very good.

23
01:57.280 --> 01:57.730
Right.

24
01:57.850 --> 02:08.460
And if you want the "id", you can say the _id: post._id, right here

25
02:08.760 --> 02:16.050
It also return. But let me write it in the best way with the "DTO".

26
02:16.080 --> 02:21.600
So in the DTO here I will create one more detail called the.

27
02:24.330 --> 02:28.560
response-post.dto.ts

28
02:29.040 --> 02:36.930
And I will copy the class right here, paste it to here because it's very similar, response post

29
02:36.930 --> 02:37.410
DTO

30
02:40.740 --> 02:42.000
Okay, this is the class.

31
02:42.030 --> 02:51.630
And in here, I can write a helper methods to convert the entities into the class.

32
02:51.660 --> 02:53.670
But right now I will not do that.

33
02:54.420 --> 02:57.930
I will show you the easy way right here.

34
02:58.080 --> 03:02.090
I will create a postDto = new ResponsePostDTO()

35
03:04.220 --> 03:05.240
Post DTO

36
03:08.570 --> 03:12.290
And with the postDto, I can use postDto.title

37
03:12.320 --> 03:17.780
= post.title

38
03:17.810 --> 03:18.230
post

39
03:20.660 --> 03:21.020
._id

40
03:22.490 --> 03:22.790
Sorry.

41
03:22.790 --> 03:23.120
Sorry.

42
03:23.990 --> 03:24.470
post

43
03:24.470 --> 03:30.230
post.title, postDto.description

44
03:30.260 --> 03:32.570
post.description

45
03:32.570 --> 03:35.840
And if we need the ID, we will provide the ID right here.

46
03:36.920 --> 03:37.460
string

47
03:41.750 --> 03:48.710
postDto.id actually "_id" is best.

48
03:53.630 --> 03:54.800
= post.

49
03:54.830 --> 03:55.280
post

50
03:59.520 --> 04:00.000
._id

51
04:00.450 --> 04:02.400
And we will return.

52
04:05.520 --> 04:11.430
Oh because the "_id" here is the "TypeId" and we can convert this using string if you want.

53
04:11.730 --> 04:12.120
Okay.

54
04:12.150 --> 04:17.040
I will convert this .toString() here

55
04:17.940 --> 04:18.270
Okay.

56
04:18.300 --> 04:21.420
That's the purpose of the "DTO".

57
04:21.900 --> 04:23.250
And I will return right here.

58
04:25.110 --> 04:31.500
Now you can see what happened right now I can use the typescript right here okay.

59
04:31.530 --> 04:32.100
Promise.

60
04:35.610 --> 04:41.340
With the ResponsePostDTO

61
04:42.090 --> 04:42.600
Right.

62
04:42.630 --> 04:43.410
Very cool.

63
04:43.740 --> 04:46.290
And because we will wrap it inside the promise.

64
04:46.290 --> 04:47.850
Because we use the async.

65
04:48.180 --> 04:50.880
And async always return promise.

66
04:51.360 --> 04:54.270
Okay, this is the JavaScript knowledge.

67
04:56.310 --> 04:57.420
If I send it again.

68
05:05.420 --> 05:06.380
Very cool, right?

69
05:06.410 --> 05:11.960
We have a "_id" "description", we no longer have the "__v" anymore

70
05:12.860 --> 05:21.410
And actually, if you want, you can easily remove the underscore.

71
05:21.410 --> 05:21.740
v

72
05:23.330 --> 05:23.840
Okay.

73
05:24.050 --> 05:31.730
But in the MVC architecture we usually use the "DTO"

74
05:32.000 --> 05:42.110
To access when we send a request or when we return the response, we use the "DTO".

75
05:44.930 --> 05:48.020
So that's it, that's for the video.

76
05:48.560 --> 05:54.080
And in the next video I will show you how we can validation when we send a request.

77
05:54.590 --> 05:55.010
Right.

78
05:55.040 --> 05:56.720
I will see you in the next one.