1
00:00:06,570 --> 00:00:07,650
In this video.

2
00:00:07,650 --> 00:00:11,640
Let's finish up with the MVC design pattern.

3
00:00:11,670 --> 00:00:20,010
You may be thinking that this one is okay because now on a server file, we have few lines of code because

4
00:00:20,010 --> 00:00:23,460
now on a server file, we don't have the business logic.

5
00:00:23,700 --> 00:00:28,740
And again, if you are developing, let's say, small application, this one is okay.

6
00:00:28,860 --> 00:00:32,180
But let's say you are building enterprise application.

7
00:00:32,189 --> 00:00:36,630
You need to use what is called the MVC design pattern completely.

8
00:00:36,660 --> 00:00:39,270
So let's see how we are going to implement that.

9
00:00:39,300 --> 00:00:39,800
Great.

10
00:00:39,810 --> 00:00:44,760
So now inside the folder of the controller, it's time to work with it.

11
00:00:44,790 --> 00:00:48,550
So now let's locate the roots here.

12
00:00:48,570 --> 00:00:55,500
The responsibility of the root is to render a root, but not with the business logic.

13
00:00:55,620 --> 00:01:00,360
So looking at this one, our business logic is our handler.

14
00:01:00,660 --> 00:01:07,290
So what we are going to do is that we are going to extract this one from this function and then put

15
00:01:07,290 --> 00:01:14,730
it inside the controller, and that is it, because it's here that we are going to implement our business

16
00:01:14,760 --> 00:01:15,360
logic.

17
00:01:15,390 --> 00:01:22,050
For example, if employee has been registered, then we are going to throw an error that, hey, you

18
00:01:22,050 --> 00:01:27,480
have been registered and this is a business logic and this where the action is being taken.

19
00:01:27,510 --> 00:01:29,040
So let's get going.

20
00:01:29,070 --> 00:01:34,410
So inside the controllers, you are going to create a file for a specific model.

21
00:01:34,440 --> 00:01:38,630
Because for this one, we have only one model and that is the employee.

22
00:01:38,640 --> 00:01:41,350
So let's see how we are going to implement that.

23
00:01:41,370 --> 00:01:48,210
So I would name the file as a name of my model, and that is the employee controller.

24
00:01:49,680 --> 00:01:52,140
And then going to be dot g's.

25
00:01:52,320 --> 00:01:55,050
So like I say, we are going to extract this one.

26
00:01:55,050 --> 00:01:58,500
So again, we are moving this one from here again.

27
00:01:58,500 --> 00:02:02,610
And now let me cut it and I'm back to the end controller.

28
00:02:02,610 --> 00:02:03,600
I will pass it.

29
00:02:03,630 --> 00:02:09,780
Now you can see how we are moving this function from the server file to route and now to the controller.

30
00:02:09,780 --> 00:02:14,160
It means that this function is tired about moving around.

31
00:02:15,270 --> 00:02:17,940
All right, guys, so let's continue to finish up this.

32
00:02:18,090 --> 00:02:24,120
So here we are going to create a function and assign this function to it, and that is it.

33
00:02:24,120 --> 00:02:26,430
And lastly, we are going to export it.

34
00:02:26,430 --> 00:02:27,780
So here we go.

35
00:02:27,780 --> 00:02:34,590
Let's have some space and let's make a function counts as create an employee.

36
00:02:36,660 --> 00:02:39,700
And our ad controller tweet is equal to that.

37
00:02:39,720 --> 00:02:43,560
Now, I've done this, my controller function.

38
00:02:44,220 --> 00:02:50,070
So now if I save this one and I make a request to create, let's see the error.

39
00:02:50,160 --> 00:02:58,580
You can see that there is no right for that because on the router we don't have the logic or the handler.

40
00:02:58,590 --> 00:03:01,650
So we need to require the handler here.

41
00:03:01,800 --> 00:03:04,860
So we need to export this one from this file.

42
00:03:04,860 --> 00:03:11,220
And remember, this file is going to contain all the operation for the employees.

43
00:03:11,610 --> 00:03:18,920
So we are going to export this one as an object and going to be key and value per.

44
00:03:18,930 --> 00:03:26,620
And I would like to use the key as a value, so I will maintain one as the create employee controller.

45
00:03:27,210 --> 00:03:27,930
Save it.

46
00:03:28,050 --> 00:03:32,610
Now let's get back to the router and now let's require the controller.

47
00:03:32,610 --> 00:03:36,270
And here you go, I have the auto import.

48
00:03:36,460 --> 00:03:42,840
Lastly, I need to bring in here as a second element to this function call and that is it.

49
00:03:43,020 --> 00:03:45,450
So let me save it and let me hit send.

50
00:03:45,450 --> 00:03:47,910
And now everything works fine.

51
00:03:48,210 --> 00:03:55,500
So if you want to give us a challenge, I advise you to refactor the rest of the route to use the MVC

52
00:03:55,500 --> 00:03:56,790
design palette.

53
00:03:56,970 --> 00:03:59,580
You can put this video and give it a shot.

54
00:04:04,730 --> 00:04:05,200
Great.

55
00:04:05,210 --> 00:04:09,290
Again, we are going to catch the handler from here.

56
00:04:09,410 --> 00:04:11,390
And now back to the file.

57
00:04:11,420 --> 00:04:12,830
Let me pass it here.

58
00:04:12,980 --> 00:04:15,860
So the first one is let me add a comment.

59
00:04:15,860 --> 00:04:17,000
Say, great.

60
00:04:18,560 --> 00:04:21,820
And here is going to be as fetch.

61
00:04:21,829 --> 00:04:22,730
All right.

62
00:04:22,730 --> 00:04:31,490
Yeah, fetch or let me see all employees and cons going to be get and implore.

63
00:04:32,870 --> 00:04:34,730
Gees meaning poorer.

64
00:04:34,850 --> 00:04:43,130
I'm going to add as comptroller and I'll pace that and I'm done and our export this one as get employees

65
00:04:43,580 --> 00:04:52,220
and here I need to extract or pull out that controller and that is gets employees so here I'll pass

66
00:04:52,220 --> 00:04:56,450
in here as a second agreement as get employees.

67
00:04:56,570 --> 00:04:57,350
Great.

68
00:04:57,380 --> 00:04:59,750
Next step is going to be the update.

69
00:04:59,750 --> 00:05:01,580
So our card is one from here.

70
00:05:01,700 --> 00:05:03,760
And now here we go.

71
00:05:03,770 --> 00:05:16,430
So I have a comment as update and cost update employee that is singular controller.

72
00:05:16,430 --> 00:05:19,430
And then here I'll that and that is it.

73
00:05:19,430 --> 00:05:23,840
So let me collapse this one and this and now let's work on this one.

74
00:05:24,050 --> 00:05:26,870
So let me export the update.

75
00:05:28,070 --> 00:05:31,700
And now here, let's require it here as.

76
00:05:32,770 --> 00:05:41,050
I did and let me pass in here on the second argument as update next one going to be the delete.

77
00:05:41,050 --> 00:05:43,210
So I'll cut this one from here.

78
00:05:43,810 --> 00:05:46,450
And now let's get back to the employees.

79
00:05:46,450 --> 00:05:48,760
And now let me have a comment.

80
00:05:48,790 --> 00:05:52,510
You're going to be as I forgot is delete.

81
00:05:53,770 --> 00:05:55,150
All right, guys.

82
00:05:55,150 --> 00:05:58,720
So delete and I'm going to be as concerned.

83
00:05:58,930 --> 00:05:59,770
Delete.

84
00:06:00,610 --> 00:06:02,170
Employee.

85
00:06:04,120 --> 00:06:08,890
Controller is equal to the handler and that is it.

86
00:06:08,920 --> 00:06:12,060
Collapse it and let's export that one.

87
00:06:12,070 --> 00:06:13,690
And here we go.

88
00:06:13,720 --> 00:06:18,760
So here let's require the delete and that is it.

89
00:06:18,970 --> 00:06:21,730
Next one is going to be fixed single.

90
00:06:21,730 --> 00:06:32,440
So our Kurdistan from here and now back here is going to be details and going to be us get employee

91
00:06:32,470 --> 00:06:33,850
for singular.

92
00:06:35,180 --> 00:06:40,300
Controller is equal to the callback function and that is it.

93
00:06:40,310 --> 00:06:47,300
And let me export this one from here as gate employee, which is this.

94
00:06:47,720 --> 00:06:52,280
So here lets require the gate employee.

95
00:06:52,730 --> 00:06:53,060
Great.

96
00:06:53,060 --> 00:07:04,190
So now let's pass the delete here as delete and here as gets come and gets employee save it.

97
00:07:04,190 --> 00:07:07,690
And now let's test all the endpoint guys.

98
00:07:07,700 --> 00:07:18,830
First one is create a great or a it works update a it works delete a it works single a it works.

99
00:07:18,830 --> 00:07:29,060
So guys here and the complete MVC design pattern and we're happy to finish out this section because

100
00:07:29,060 --> 00:07:33,110
this one is really important as Node.js developer.

101
00:07:33,470 --> 00:07:33,950
Great.

102
00:07:33,950 --> 00:07:38,930
So now we don't have the actual logic, but the design pattern is complete.

103
00:07:39,230 --> 00:07:44,660
What has left is to fill up the controller with a rare logic.

104
00:07:44,660 --> 00:07:50,990
So the next video will go ahead and then register employee using our model.

105
00:07:50,990 --> 00:07:55,780
And we are going to fetch all we are going to update, we are going to delete and you are going to find

106
00:07:55,790 --> 00:07:57,530
single employee.

107
00:07:57,560 --> 00:08:00,140
Let's get into that the next video.

