WEBVTT

1
00:00.770 --> 00:02.150
Hi everyone.

2
00:02.180 --> 00:03.530
Let me customize this.

3
00:03.770 --> 00:07.970
Now you can notice because this is the class okay.

4
00:08.000 --> 00:09.890
This interceptor is a class.

5
00:09.890 --> 00:12.560
So we have a constructor.

6
00:13.220 --> 00:22.010
How we use that, private readonly I will call here will be "dtoClass"

7
00:24.710 --> 00:25.070
Okay.

8
00:25.100 --> 00:26.000
That's what we want

9
00:26.030 --> 00:29.990
And here I will replace this.dtoClass

10
00:30.800 --> 00:33.290
And if you hover it will be the any.

11
00:33.320 --> 00:33.980
Right.

12
00:33.980 --> 00:45.230
And here we also any, actually we don't need to fix that.

13
00:45.260 --> 00:47.030
Because we want to reuse.

14
00:49.910 --> 00:59.720
And if I remove now inside the post controller, post controller right here.

15
01:08.950 --> 01:10.150
I will use the new 

16
01:13.120 --> 01:14.590
Right on the new

17
01:14.830 --> 01:18.970
And the new, it take one argument will be the dtoClass, right?

18
01:19.000 --> 01:23.500
For that reason I will pass the ResponseDTO right here

19
01:24.040 --> 01:24.550
Okay.

20
01:25.060 --> 01:26.620
And that's all.

21
01:28.480 --> 01:31.930
If I send okay, it also work.

22
01:31.930 --> 01:32.350
Right?

23
01:33.640 --> 01:41.050
And later if we have a userDTO, we can easily change it inside the user DTO right here.

24
01:42.190 --> 01:42.790
Okay.

25
01:43.600 --> 01:55.720
And let me show you one more way how to increase the code a little bit because it's very hard to remember.

26
01:55.750 --> 01:56.350
Right.

27
01:56.380 --> 02:02.760
So for that reason we will use the concept called Custom decorator.

28
02:03.150 --> 02:06.660
Let me go to the topic right here and I will copy everything.

29
02:06.930 --> 02:07.380
Okay.

30
02:08.280 --> 02:16.680
And inside the src, I will create decorators and I will give it a transform

31
02:19.350 --> 02:23.850
transform-dto.decorator.ts

32
02:24.840 --> 02:27.300
And then let me paste everything right here.

33
02:33.000 --> 02:41.700
Oh actually I think I don't need to use

34
02:43.860 --> 02:46.140
Sorry, I don't need that.

35
02:47.370 --> 02:48.270
My bad, my bad.

36
02:49.050 --> 02:51.450
I don't need the here

37
02:51.930 --> 02:58.350
I only need, convert it inside a function, and it will be enough.

38
03:01.170 --> 03:01.770
Right.

39
03:03.860 --> 03:04.550
Let me see.

40
03:28.670 --> 03:32.030
I will go to the transform DTO interceptor

41
03:38.240 --> 03:38.660
Okay.

42
03:39.170 --> 03:41.330
The code right here is a little bit.

43
03:43.340 --> 03:44.450
Long, right.

44
03:44.570 --> 03:49.760
So I will show you how we can customize one more step.

45
03:54.350 --> 03:54.710
Okay.

46
03:56.660 --> 03:59.780
So here I think I will create.

47
04:02.010 --> 04:04.500
The function will be.

48
04:07.080 --> 04:08.010
use

49
04:14.670 --> 04:29.490
I will cut this line here and UseTransform or TransformDTO, okay. paste it

50
04:29.790 --> 04:31.290
I will return the code right here.

51
04:33.570 --> 04:35.970
And in here I will pass the DTO.

52
04:38.760 --> 04:39.300
pass dto

53
04:40.020 --> 04:44.910
Directly right here, and I will export the function.

54
04:45.780 --> 04:52.380
And right now I can use the @TransformDTO and pass

55
04:52.410 --> 04:53.040
The.

56
04:56.760 --> 04:58.740
DTO

57
04:58.740 --> 05:01.140
ResponsePostDTO

58
05:01.140 --> 05:01.590
....

59
05:03.020 --> 05:03.560
Okay.

60
05:03.620 --> 05:04.430
So.

61
05:07.040 --> 05:10.190
That's it, that for the class right here.

62
05:11.030 --> 05:17.300
And if I get all of that, now you can see it already worked, right?

63
05:20.900 --> 05:21.590
Very cool.

64
05:31.310 --> 05:35.360
But if you want

65
05:35.390 --> 05:37.670
Mark is not "any" inside here.

66
05:38.690 --> 05:47.930
If you want to add a little bit of TypeScript checking, we can use the class.

67
05:50.180 --> 05:55.190
The class constructor from class transformer.

68
05:56.300 --> 05:56.690
Okay.

69
05:56.900 --> 06:00.710
With class constructor, we can pass the decorator concept.

70
06:01.910 --> 06:04.900
And in here I will pass the decorator.

71
06:06.610 --> 06:07.330
And in here.

72
06:07.330 --> 06:07.750
also

73
06:18.130 --> 06:18.790
Using the T 

74
06:18.820 --> 06:19.630
right here

75
06:20.380 --> 06:20.920
Okay.

76
06:22.450 --> 06:24.820
This is just the generic concept.

77
06:25.060 --> 06:25.480
Okay.

78
06:25.510 --> 06:27.760
But actually we don't need to care about that.

79
06:29.140 --> 06:31.930
Just make sure this is the class.

80
06:31.960 --> 06:35.140
Because for example, if I want something like this.

81
06:35.680 --> 06:36.130
Right.

82
06:36.160 --> 06:39.280
It will not work if you use any.

83
06:40.210 --> 06:42.040
This is work, right?

84
06:42.610 --> 06:45.460
I want to ask a little bit of checking.

85
06:45.490 --> 06:52.630
For that reason, I used the some thing called class constructor from class transformer.

86
06:54.100 --> 06:56.260
So that's for the video.

87
06:59.230 --> 07:01.990
And I will see you in the next one.