1
00:00:00,140 --> 00:00:00,770
All right.

2
00:00:00,860 --> 00:00:07,200
And while we're still on a roll, let's also set up a structure for user routes.

3
00:00:07,220 --> 00:00:14,030
So effectively, we'll create three more routes and controllers, one to get the current user.

4
00:00:14,030 --> 00:00:18,270
And that is very important because we're sending back the JWT in a cookie.

5
00:00:18,380 --> 00:00:24,860
So it's not like we're sending back with a request and then we can store it on the front end.

6
00:00:24,890 --> 00:00:31,880
No, we're sending back in a cookie and therefore we need the actual route, which gives us info about,

7
00:00:31,880 --> 00:00:34,430
well, what is the actual user?

8
00:00:34,460 --> 00:00:39,020
Then also we want to set up application stats and this is going to be the admin route.

9
00:00:39,020 --> 00:00:43,250
So we'll take a look how we can restrict access even more.

10
00:00:43,310 --> 00:00:45,500
And also we want to update the user.

11
00:00:45,920 --> 00:00:50,930
So let's say I want to change the name, maybe email and all that cool stuff.

12
00:00:51,170 --> 00:00:54,210
And let's start by navigating to controllers.

13
00:00:54,230 --> 00:00:56,780
We want to create a new one user.

14
00:00:58,080 --> 00:00:58,950
Controller.

15
00:01:00,500 --> 00:01:01,340
Jess.

16
00:01:01,900 --> 00:01:07,930
Let's start by importing few things and then we'll set up our controllers.

17
00:01:07,930 --> 00:01:12,370
So for starters, I'm going to look for status codes.

18
00:01:13,460 --> 00:01:15,560
That's going to be the first one in here.

19
00:01:15,560 --> 00:01:21,530
We'll have two models, user and job since we'll get the application stats.

20
00:01:21,530 --> 00:01:24,260
So therefore let's go with user.

21
00:01:25,160 --> 00:01:27,320
Import then user.

22
00:01:27,320 --> 00:01:31,520
And for some reason it just keeps suggesting this user model.

23
00:01:31,790 --> 00:01:33,200
That's not what I want to do.

24
00:01:33,770 --> 00:01:39,800
I want to go with JS in here and then also we want to grab the job.

25
00:01:40,400 --> 00:01:41,840
So the same deal over here.

26
00:01:42,630 --> 00:01:43,810
Let's go with job.

27
00:01:43,830 --> 00:01:46,620
So those are the three imports.

28
00:01:46,650 --> 00:01:50,880
Now, eventually there's going to be a little bit more, but for now, let's not worry about it.

29
00:01:50,910 --> 00:01:54,030
We want to right away export, as always.

30
00:01:54,610 --> 00:01:57,040
First one is going to be get current user.

31
00:01:57,040 --> 00:02:04,510
And again, this is going to be very typical setup because we're not storing that user info technically

32
00:02:04,510 --> 00:02:05,530
on the front end.

33
00:02:05,560 --> 00:02:11,950
We're just using that cookie to send the token to the front end and then front end right away sends

34
00:02:11,950 --> 00:02:12,370
back.

35
00:02:12,370 --> 00:02:19,720
But we do need to get the info about the actual user, for example, the username, and therefore we'll

36
00:02:19,720 --> 00:02:26,530
set up this get current user, which as a side note, we're going to run every time user navigates to

37
00:02:26,530 --> 00:02:27,370
the dashboard.

38
00:02:27,370 --> 00:02:30,040
Something of course will set up a little bit later.

39
00:02:30,250 --> 00:02:34,240
As far as the response logic, let's just go with the rest dot status.

40
00:02:34,630 --> 00:02:39,130
Let's pass in the status codes and we want to go with Okay.

41
00:02:39,250 --> 00:02:44,200
And yes, I'll set up some messages, but eventually, of course we'll send something else.

42
00:02:44,200 --> 00:02:46,660
But for now I just want to see whether everything works.

43
00:02:46,660 --> 00:02:50,080
So I'm just going to say get current user.

44
00:02:50,110 --> 00:02:57,230
Then we want to select this copy and paste two times and we want to change some values over here.

45
00:02:57,230 --> 00:03:01,310
So for starters, it's going to be get application stats.

46
00:03:01,310 --> 00:03:07,070
So this is an admin route where we can check how many users we have and how many jobs.

47
00:03:07,070 --> 00:03:12,710
Now of course sky's the limit, but that's what I picked for this application as far as the admin.

48
00:03:12,980 --> 00:03:15,170
So we're going to go here with application stats.

49
00:03:15,170 --> 00:03:17,600
Yep, it's still going to be 200.

50
00:03:17,600 --> 00:03:22,610
And then with update user, well this is where we'll change the properties.

51
00:03:22,610 --> 00:03:25,820
So I'm going to go with update user.

52
00:03:26,030 --> 00:03:31,040
And then when it comes to message, we're going to go here with update user.

53
00:03:31,370 --> 00:03:38,450
A quick, quick, quick, quick side note in the auth middleware, you can actually remove this async.

54
00:03:38,780 --> 00:03:42,140
So I just placed it here by mistake.

55
00:03:42,560 --> 00:03:46,910
Then let's navigate to the routes.

56
00:03:47,120 --> 00:03:52,250
We want to create a new file and we'll call this user router.

57
00:03:52,430 --> 00:03:58,260
JS And let's start by pretty much repeating the same steps.

58
00:03:58,280 --> 00:03:58,820
And you know what?

59
00:03:58,820 --> 00:04:05,030
I think it's going to be faster if I just take a look at the auth one and delete some stuff.

60
00:04:05,240 --> 00:04:08,480
Basically let me navigate to user router copy and paste.

61
00:04:08,480 --> 00:04:11,780
So these two lines stay the same.

62
00:04:12,670 --> 00:04:16,740
Let's remove this one and then default router.

63
00:04:16,750 --> 00:04:18,459
Yep, that stays the same.

64
00:04:18,519 --> 00:04:23,440
But as far as the routes, the first one is going to be get.

65
00:04:24,070 --> 00:04:27,850
So this is going to be for current user for application stats.

66
00:04:27,850 --> 00:04:29,440
It's also going to be get.

67
00:04:29,440 --> 00:04:32,440
And then for update user, it's going to be patch.

68
00:04:32,590 --> 00:04:41,410
Then the URL is going to be API version one users and then in order to get the current user.

69
00:04:42,320 --> 00:04:47,560
We're just going to go here with current user as far as the application stats.

70
00:04:47,570 --> 00:04:48,950
I'll add the admin.

71
00:04:49,600 --> 00:04:55,360
Just to signal that this is actually just for admin and I'll call it app stats.

72
00:04:55,360 --> 00:04:59,170
And the last one will be update hyphen user.

73
00:05:00,110 --> 00:05:01,400
So let's set up over here.

74
00:05:01,400 --> 00:05:02,900
Forward slash update.

75
00:05:03,780 --> 00:05:07,080
All right, friend, end user now when it comes to.

76
00:05:07,920 --> 00:05:11,280
The controllers would pretty much want to import, of course, all of them.

77
00:05:12,250 --> 00:05:16,450
And eventually for the update user will also set up.

78
00:05:17,530 --> 00:05:20,020
A validation layer, but not for now.

79
00:05:20,020 --> 00:05:23,560
So for starters, let's start with get current user.

80
00:05:23,590 --> 00:05:24,700
Let's import.

81
00:05:24,730 --> 00:05:26,860
Let's make sure we have a JS over here.

82
00:05:27,950 --> 00:05:31,010
Then we also want to grab the get application stats.

83
00:05:31,830 --> 00:05:35,130
And then lastly, let's go with update users.

84
00:05:35,130 --> 00:05:36,810
So we import all of these things.

85
00:05:36,810 --> 00:05:39,480
Now we just want to navigate to the server.

86
00:05:40,190 --> 00:05:42,020
Let me copy and paste.

87
00:05:42,020 --> 00:05:43,150
And here's the kicker.

88
00:05:43,160 --> 00:05:49,040
We want to place this authenticate user in front of it, just like we do with jobs.

89
00:05:49,040 --> 00:05:51,290
So in order to check.

90
00:05:52,910 --> 00:05:54,080
What is the current user?

91
00:05:54,080 --> 00:05:56,750
Yes, the user will have to log in first.

92
00:05:56,900 --> 00:05:58,920
Same deal with update user.

93
00:05:58,940 --> 00:06:04,820
And when it comes to admin, not only will check for current user but will also check whether the user

94
00:06:04,820 --> 00:06:06,050
is actually an admin.

95
00:06:06,050 --> 00:06:09,050
So I'll place it here right after.

96
00:06:09,050 --> 00:06:15,920
I think it's easier to read and we'll just go with authenticate user first and then we'll go with user

97
00:06:15,920 --> 00:06:18,980
router, which we haven't imported yet.

98
00:06:18,980 --> 00:06:20,450
So user router.

99
00:06:20,450 --> 00:06:23,810
And as far as the URL, you know what, let's go with users.

100
00:06:23,810 --> 00:06:26,060
And now of course we just want to navigate up.

101
00:06:26,840 --> 00:06:29,540
Copy and paste and change this value.

102
00:06:29,840 --> 00:06:34,430
So instead of auth router, we're going to go with user.

103
00:06:35,190 --> 00:06:36,270
And router.

104
00:06:36,600 --> 00:06:37,620
Okay, good.

105
00:06:37,620 --> 00:06:38,700
Let me check.

106
00:06:39,430 --> 00:06:42,040
Whether everything is working in a console.

107
00:06:42,040 --> 00:06:47,440
And now, of course, I just want to navigate to the Thunder client.

108
00:06:47,470 --> 00:06:49,300
I want to make sure that I'm logged in.

109
00:06:49,630 --> 00:06:50,600
Okay, good.

110
00:06:50,620 --> 00:06:53,430
And then let's set up more routes over here.

111
00:06:53,440 --> 00:06:55,300
So these are job routes then?

112
00:06:55,300 --> 00:06:56,320
Auth routes.

113
00:06:56,710 --> 00:06:58,750
So let's create a new one.

114
00:06:59,810 --> 00:07:01,400
Let's create a new folder.

115
00:07:01,790 --> 00:07:03,530
Let's call this user.

116
00:07:04,390 --> 00:07:05,050
Route.

117
00:07:05,290 --> 00:07:06,580
And then.

118
00:07:07,260 --> 00:07:08,190
In here.

119
00:07:08,340 --> 00:07:10,950
Let's start by setting up a new request.

120
00:07:11,160 --> 00:07:13,320
And I'm going to call this get.

121
00:07:14,230 --> 00:07:15,580
Rent user.

122
00:07:16,260 --> 00:07:16,740
Okay, good.

123
00:07:16,740 --> 00:07:18,100
It's a getter out.

124
00:07:18,120 --> 00:07:19,990
Then we want to go with URL.

125
00:07:20,920 --> 00:07:28,330
Forward slash users and then I believe it was current user, so current and then user.

126
00:07:28,330 --> 00:07:31,240
And if everything is correct, we should see.

127
00:07:31,330 --> 00:07:32,050
Yep.

128
00:07:32,290 --> 00:07:34,120
Message get current user.

129
00:07:34,120 --> 00:07:36,010
So now let's copy and paste.

130
00:07:36,010 --> 00:07:41,230
So basically duplicate once and twice or here let's rename first.

131
00:07:42,420 --> 00:07:45,270
Let's call this get application stats.

132
00:07:47,120 --> 00:07:48,560
Or simply application stats.

133
00:07:48,560 --> 00:07:50,450
That's irrelevant over here.

134
00:07:51,400 --> 00:07:57,040
We're looking for users, then admin, then forward slash, then app.

135
00:07:57,690 --> 00:07:58,210
Stats.

136
00:07:58,470 --> 00:07:59,390
Let's send that one.

137
00:07:59,400 --> 00:07:59,820
Okay.

138
00:07:59,850 --> 00:08:00,810
Application stats.

139
00:08:00,840 --> 00:08:02,400
We have that one over here.

140
00:08:02,620 --> 00:08:04,290
And the last one is going to be the patch one.

141
00:08:04,290 --> 00:08:05,670
We just want to rename it.

142
00:08:05,940 --> 00:08:08,850
We're going to go with update user root.

143
00:08:09,530 --> 00:08:09,890
Okay.

144
00:08:09,920 --> 00:08:11,510
Good batch.

145
00:08:12,380 --> 00:08:17,360
And it's going to be users and update user.

146
00:08:17,840 --> 00:08:18,410
Good.

147
00:08:18,410 --> 00:08:19,550
Let's send it on.

148
00:08:19,550 --> 00:08:27,230
If you see 200 for all these three requests, we are in good shape and we can move on to the next step.

