WEBVTT

1
00:00.770 --> 00:02.180
Hi everyone!

2
00:02.600 --> 00:11.240
I already talked about the module in previous video, and in this video let me show you how to create

3
00:11.270 --> 00:12.410
the modules.

4
00:12.890 --> 00:16.490
Okay, now the application right now is very messy.

5
00:16.490 --> 00:22.160
I think I will remove the all of the test right here, tesst controller test repository and test service

6
00:22.430 --> 00:22.730
okay.

7
00:22.760 --> 00:29.540
Remove all the that and inside the module let me remove here okay.

8
00:29.570 --> 00:30.140
Remove here.

9
00:30.920 --> 00:31.280
Sorry.

10
00:32.990 --> 00:34.070
Here here and here.

11
00:36.800 --> 00:47.060
Now the application right now, in order to create the some module we usually create a new folder okay.

12
00:47.420 --> 00:50.840
For example I will create the blog post application.

13
00:50.840 --> 00:55.460
So I will create a post folder okay.

14
00:56.090 --> 00:57.950
Now what's inside the post

15
00:57.950 --> 01:05.420
I will create a structure like application controller, app module and app service.

16
01:05.450 --> 01:08.870
Okay, so I will create the app.

17
01:08.900 --> 01:09.440
Sorry.

18
01:09.710 --> 01:12.110
The post.controller

19
01:12.230 --> 01:15.080
.ts

20
01:15.380 --> 01:15.800
post.

21
01:15.800 --> 01:16.730
service

22
01:16.910 --> 01:17.270
.ts

23
01:18.620 --> 01:23.990
And the very important a post.module.ts

24
01:24.080 --> 01:25.820
Okay, this is the most important.

25
01:27.590 --> 01:31.730
Now let me see how I can create the controller.

26
01:32.210 --> 01:42.800
Firstly, I will create a controller in the controller from Nestjs/common and

27
01:42.800 --> 01:45.920
The class will be post controller.

28
01:47.930 --> 01:51.050
And create a method called get all.

29
01:51.470 --> 01:55.310
Okay, we will get all the posts and I will return.

30
01:56.150 --> 01:57.650
Well, what's a return for now?

31
01:57.650 --> 02:02.750
I will return empty string and I will return inside the service later.

32
02:02.990 --> 02:06.490
But let me fix this error is a little bit annoying.

33
02:07.510 --> 02:11.110
Now let let me show you how I can find the solution.

34
02:11.260 --> 02:13.570
Actually, this is the error, right?

35
02:13.600 --> 02:17.230
I think I will copy this and paste it into the stackoverflow.

36
02:19.270 --> 02:21.250
I click something topic

37
02:22.630 --> 02:28.240
And if I scroll down into here, we can set the end of line will be auto.

38
02:29.710 --> 02:30.130
Okay.

39
02:30.160 --> 02:33.460
Let me find the eslint right here.

40
02:34.720 --> 02:35.530
Inside the rule

41
02:35.890 --> 02:36.700
Inside the rule

42
02:37.990 --> 02:42.010
Actually, is it prettier, I think.

43
02:49.690 --> 02:52.000
Let me find some solution.

44
02:55.510 --> 02:56.320
Eslint

45
02:56.350 --> 02:57.190
Inside a rule

46
03:00.400 --> 03:02.590
I think inside here

47
03:02.950 --> 03:03.880
I will copy.

48
03:03.910 --> 03:06.280
Let me scroll up into the top one.

49
03:07.660 --> 03:09.370
No, that's what we want.

50
03:13.210 --> 03:13.480
Here.

51
03:14.200 --> 03:15.280
And let me paste it, work

52
03:15.280 --> 03:15.580
Or not.

53
03:17.260 --> 03:18.640
And actually, it's work, right?

54
03:18.850 --> 03:21.310
So we will be in here.

55
03:22.120 --> 03:26.140
And this is a rule of estlint.js

56
03:28.690 --> 03:31.510
And let's go to the application.

57
03:32.740 --> 03:35.410
In the get all, I will create a service.

58
03:35.590 --> 03:39.730
Okay I will create a service post service

59
03:40.240 --> 03:40.600
Sorry.

60
03:40.600 --> 03:41.050
Class.

61
03:41.080 --> 03:41.950
Post Service

62
03:44.350 --> 03:47.680
And in here I will create a get all also

63
03:49.150 --> 03:49.480
Okay.

64
03:49.510 --> 03:53.200
The same name is still acceptable.

65
03:53.950 --> 03:55.480
And in here I will return.

66
03:55.840 --> 03:58.000
I will return something like this.

67
03:58.240 --> 04:01.270
And I think I will ignore the repository right now.

68
04:01.300 --> 04:03.820
I will create the data.

69
04:03.850 --> 04:04.750
I will mock the data.

70
04:05.260 --> 04:12.760
Data with object ID:1, title plus one description.

71
04:14.020 --> 04:16.300
Will be post 1 description

72
04:17.500 --> 04:18.310
Something like this.

73
04:20.200 --> 04:26.650
Let me copy & paste 2 times

74
04:26.920 --> 04:30.880
And here we will be three and I will return directly right here.

75
04:31.450 --> 04:31.930
Okay.

76
04:31.960 --> 04:36.190
Later we will fetch by database

77
04:36.610 --> 04:37.000
Okay.

78
04:37.750 --> 04:40.330
And inside here we will use the dependency injection.

79
04:40.360 --> 04:40.960
Right.

80
04:42.310 --> 04:46.780
So for that reason firstly we will mark it in the injectable

81
04:49.300 --> 04:50.380
Make sure we call that

82
04:52.030 --> 04:55.120
And secondly will be inside the post module.

83
04:55.120 --> 04:59.470
And actually I don't know I don't remember the code inside the module.

84
04:59.500 --> 04:59.800
Okay.

85
04:59.830 --> 05:01.810
Never in my life I remember the code.

86
05:01.840 --> 05:08.080
So I will copy all of that inside the app module and paste it inside the post module right here.

87
05:08.140 --> 05:14.280
And I we will remove everything and rename it into the post module.

88
05:15.930 --> 05:16.530
Okay.

89
05:16.890 --> 05:17.430
That is.

90
05:17.940 --> 05:20.070
And now let.

91
05:20.160 --> 05:24.660
Let's pause the video right here and try to make the post work.

92
05:25.530 --> 05:26.010
Okay.

93
05:26.040 --> 05:29.340
If you have a little bit tricky, I will show you.

94
05:29.730 --> 05:31.950
Don't worry, let pause the video.

95
05:35.040 --> 05:35.430
Okay.

96
05:35.460 --> 05:36.840
How about your solution?

97
05:37.050 --> 05:37.710
This work or not?

98
05:39.030 --> 05:40.050
Anyway, let me show you.

99
05:40.080 --> 05:42.840
Firstly, in the controller I will mark.

100
05:42.840 --> 05:44.550
That will be the post controller.

101
05:45.510 --> 05:51.600
And inside the provider here we will register for the injectable class.

102
05:51.720 --> 05:54.450
We will post service

103
05:56.280 --> 05:59.940
And inside here I will use a get decorator.

104
06:01.440 --> 06:04.770
For example I use the /posts

105
06:06.990 --> 06:08.880
And in here I will create a constructor.

106
06:10.500 --> 06:13.470
private post service

107
06:15.990 --> 06:19.110
And I will return this.postService

108
06:19.140 --> 06:19.890
get all

109
06:23.100 --> 06:25.320
Also, we must have a curly brackets.

110
06:26.220 --> 06:27.660
Now let me run.

111
06:27.690 --> 06:30.000
For example, I will run the post right here.

112
06:31.290 --> 06:32.730
Unfortunately, it does not work.

113
06:36.060 --> 06:37.170
Why it's not work?

114
06:38.520 --> 06:44.400
Because the nestjs right now doesn't have any idea about the post

115
06:45.330 --> 06:45.870
Okay.

116
06:45.990 --> 06:47.520
It doesn't have any idea about post.

117
06:48.120 --> 06:55.350
It's don't know what is the module of the post, because in here you can see it's not correct.

118
06:57.420 --> 06:59.130
For example, this is the post module.

119
07:04.230 --> 07:08.310
It must somehow connect in with the application module.

120
07:08.310 --> 07:09.030
Right.

121
07:09.840 --> 07:14.550
But right now this independently.

122
07:15.090 --> 07:16.230
It's just a post

123
07:19.080 --> 07:19.410
Okay?

124
07:19.410 --> 07:21.420
It's just a post.

125
07:21.450 --> 07:25.410
And it doesn't have the connection between the application and the post.

126
07:25.410 --> 07:29.220
So for that reason, it's not work right now, how we can do that?

127
07:30.180 --> 07:33.330
And that's the purpose of the export statement

128
07:34.020 --> 07:35.520
Now let me show you.

129
07:35.580 --> 07:38.370
I must export the entire model.

130
07:38.910 --> 07:41.370
The entire module will be the post module.

131
07:41.400 --> 07:41.760
Okay.

132
07:41.790 --> 07:42.360
Export that

133
07:42.750 --> 07:52.290
And inside inside the app module, inside the import of app module, we will import the post module.

134
07:53.460 --> 07:56.670
Now let's see, it's work or not, refresh

135
07:56.700 --> 07:59.790
Now you can see it's already returned for me the data.

136
07:59.880 --> 08:00.630
Right.

137
08:02.190 --> 08:05.730
And that's it, that's how to create a module.

138
08:05.730 --> 08:12.570
And we already understand what is import and export. Let's me summarize.

139
08:12.590 --> 08:13.010
Firstly

140
08:14.150 --> 08:14.930
Firstly

141
08:19.160 --> 08:21.350
Let me show you.

142
08:22.100 --> 08:22.520
Firstly

143
08:22.550 --> 08:25.190
I will create a post module.

144
08:27.050 --> 08:27.530
Right?

145
08:28.820 --> 08:31.580
But the application right now is.

146
08:31.760 --> 08:35.120
Don't have any idea about what is the post module.

147
08:35.150 --> 08:41.900
We need some way to create a connection between the post and the application module.

148
08:41.930 --> 08:42.320
Right.

149
08:42.350 --> 08:46.310
And for that reason, in the post module, we must "export".

150
08:46.970 --> 08:49.370
We must export "itself" okay.

151
08:49.400 --> 08:50.450
We must export itself.

152
08:51.170 --> 08:54.410
And inside the application module we will import.

153
08:57.890 --> 08:58.310
Okay.

154
08:58.340 --> 09:02.000
We must import the post module.

155
09:02.240 --> 09:06.320
And it will create a connection between the post and the application module.

156
09:06.890 --> 09:07.400
Okay.

157
09:07.910 --> 09:10.700
That's the everything about module.

158
09:11.150 --> 09:12.770
I hope you understand this video.

159
09:12.860 --> 09:14.720
I will see you in the next one.