1
00:00:00,240 --> 00:00:00,640
All right.

2
00:00:00,660 --> 00:00:04,170
And once are all middleware functionality is complete.

3
00:00:04,710 --> 00:00:11,610
Next, I want to work in the update user where essentially we're going to be looking for four properties

4
00:00:11,610 --> 00:00:12,630
in the body.

5
00:00:13,110 --> 00:00:16,620
And I'll cover this one in more detail once we actually start setting us up.

6
00:00:16,950 --> 00:00:18,480
Essentially, what I'm looking for for.

7
00:00:19,440 --> 00:00:21,150
What if one of them is missing?

8
00:00:21,570 --> 00:00:27,600
We're going to go with police, provide of ours pretty much like we did in the logging one and the register

9
00:00:27,600 --> 00:00:28,620
one, I believe, as well.

10
00:00:29,040 --> 00:00:32,340
And then in here, we want to go with find one.

11
00:00:32,820 --> 00:00:34,470
So that's the method.

12
00:00:34,770 --> 00:00:44,100
And on the user, I'm going to check for any user who's I.D. matches that of the wreck user and then

13
00:00:44,100 --> 00:00:44,730
user already.

14
00:00:45,360 --> 00:00:52,260
So I showed you in the last video that we have Rick user and I'll simply grab the user whose I.D. matches.

15
00:00:52,590 --> 00:00:56,370
And then one by one, I'll update the property of ours.

16
00:00:57,190 --> 00:01:03,150
So email all the way to location, and then we'll use the instant method that is available on all the

17
00:01:03,150 --> 00:01:03,700
documents.

18
00:01:04,200 --> 00:01:06,450
And that one is dot save.

19
00:01:06,690 --> 00:01:08,220
And some say there's a synchronous.

20
00:01:08,460 --> 00:01:11,010
We go with 08, so we get back our instance.

21
00:01:11,250 --> 00:01:18,960
And then I just call user Darksaber and I'm purposely not using, for example, find one by ID and update

22
00:01:18,960 --> 00:01:23,910
and all that because I want to show guys how this one will trigger, not preach, save hook we already

23
00:01:23,910 --> 00:01:25,380
set up in the user model.

24
00:01:25,770 --> 00:01:32,190
And as a result, there's actually going to be an error when we try to update our user info with our

25
00:01:32,190 --> 00:01:32,790
current set up.

26
00:01:33,240 --> 00:01:35,880
But don't worry in next video we'll fix it.

27
00:01:36,000 --> 00:01:38,640
And then we have this interesting question.

28
00:01:39,120 --> 00:01:43,110
Now do we need to create another JWT?

29
00:01:44,040 --> 00:01:47,310
Like we did already in the register and log in one.

30
00:01:47,640 --> 00:01:48,990
Well, let's take a look.

31
00:01:49,260 --> 00:01:52,470
So in the user model, what are we passing in here?

32
00:01:52,950 --> 00:01:55,650
We're passing in as far as the payload just user.

33
00:01:56,550 --> 00:01:56,910
Correct.

34
00:01:57,300 --> 00:02:00,210
Now are we changing any of these hours over here?

35
00:02:00,780 --> 00:02:04,530
Are we changing the I.D. in this list?

36
00:02:04,890 --> 00:02:06,210
And the answer is no.

37
00:02:06,720 --> 00:02:11,610
So this is really up to you as far as the required.

38
00:02:11,620 --> 00:02:12,930
No, it's not required.

39
00:02:13,410 --> 00:02:16,680
You can technically just send back the user and location.

40
00:02:17,310 --> 00:02:22,530
So essentially, those are the two things that we are potentially changing here.

41
00:02:23,040 --> 00:02:28,860
Now, as far as my preference, I still prefer setting up token from the scratch because I like the

42
00:02:28,860 --> 00:02:31,680
fact that now I set up a new expiration.

43
00:02:32,070 --> 00:02:36,390
Keep in mind that since we're building this project together, I will be expecting this on a frontend.

44
00:02:36,660 --> 00:02:41,530
So yes, this is the case where as far as why we're building this project, you will have to send back

45
00:02:41,530 --> 00:02:42,870
the token just like me.

46
00:02:43,200 --> 00:02:44,550
Otherwise you'll have the box.

47
00:02:44,550 --> 00:02:44,880
But.

48
00:02:45,700 --> 00:02:50,580
When it comes to your own project, remember that technically you don't have to.

49
00:02:51,160 --> 00:02:59,950
So if you were changing some properties that you're setting up here in the token, when you're setting

50
00:02:59,950 --> 00:03:06,850
up the payload, then yes, it's a very, very, very good idea to issue a new token simply because

51
00:03:07,120 --> 00:03:09,820
otherwise you'll have this token that has some old data.

52
00:03:10,510 --> 00:03:16,240
But in this case, technically it is optional, but it's still my preference to issue that new token.

53
00:03:16,540 --> 00:03:20,500
So let's get cracking, and I want to start here in the off controller.

54
00:03:20,740 --> 00:03:22,360
I want to get my update user.

55
00:03:22,360 --> 00:03:28,510
And yes, I will discuss why I'm looking for all four properties, so I'm going to go here to email,

56
00:03:28,810 --> 00:03:33,130
then name one last name and then also a location.

57
00:03:33,400 --> 00:03:36,790
And all of that is coming from Rick and body.

58
00:03:37,120 --> 00:03:38,290
So that is coming in.

59
00:03:38,560 --> 00:03:39,160
What's next?

60
00:03:39,190 --> 00:03:44,880
Well, let's quickly check whether we have all the values and in this case, our email and password

61
00:03:44,890 --> 00:03:45,130
now.

62
00:03:45,160 --> 00:03:50,890
We're not going to be checking for password because this is not update password that is very, very

63
00:03:50,890 --> 00:03:51,310
important.

64
00:03:51,610 --> 00:03:57,730
I simply want to look for name, email as well as the last name and location.

65
00:03:58,240 --> 00:04:01,690
And if one of them is missing, then we throw the error.

66
00:04:01,810 --> 00:04:05,890
So let's add another or and we're looking for the location.

67
00:04:06,010 --> 00:04:13,330
Now you're probably wondering, OK, well, if last name and location are not required and we right

68
00:04:13,330 --> 00:04:14,650
away have some default values?

69
00:04:14,890 --> 00:04:16,149
Well, why are we sending this up?

70
00:04:16,450 --> 00:04:18,070
Well, let's take a look at the user model.

71
00:04:18,920 --> 00:04:19,630
Let's keep on scrolling.

72
00:04:19,630 --> 00:04:19,870
Yep.

73
00:04:20,170 --> 00:04:24,070
So name is required and the same goes for email password again.

74
00:04:24,310 --> 00:04:27,520
We're not updating the password, but it's important to mention that.

75
00:04:27,760 --> 00:04:33,190
But then when it comes to last name and location, we already have them as defaults.

76
00:04:33,610 --> 00:04:39,370
And again, it really comes down to my preference, where essentially if the user is trying to submit

77
00:04:39,790 --> 00:04:45,820
the empty form value were already right away, this play the alert where say, Hey, listen, please

78
00:04:45,820 --> 00:04:46,840
provide all the values.

79
00:04:47,590 --> 00:04:53,500
And since we're doing that already on front end, I might as well do the same thing on the back end

80
00:04:53,980 --> 00:04:54,310
then.

81
00:04:54,640 --> 00:04:55,630
Is that a big deal gnome?

82
00:04:55,630 --> 00:04:57,490
But that is at least my preference.

83
00:04:57,500 --> 00:05:01,660
And just to give you another hand, technically if this is empty.

84
00:05:02,610 --> 00:05:08,400
The request won't come in here anyway, because we will right away stop it on the front end.

85
00:05:08,760 --> 00:05:12,420
So then we want to grab the user who's I.D. matches.

86
00:05:12,510 --> 00:05:14,850
So we're going to go here with concert.

87
00:05:14,850 --> 00:05:21,090
I get the user now that is equal to weight and then we go with a user and then find one.

88
00:05:21,810 --> 00:05:24,840
And then let's take a look at the user who ID.

89
00:05:25,560 --> 00:05:34,440
So underscore karate matches, rec user and then user I.D. So once I get the user now one by one, I'll

90
00:05:34,440 --> 00:05:37,050
update those values, so I get back my object.

91
00:05:37,320 --> 00:05:41,780
Now I just want to go user email, not as equal to an email.

92
00:05:42,160 --> 00:05:46,230
Then we can copy and paste and we can right away set up architectures.

93
00:05:46,590 --> 00:05:48,720
And in this case, we're looking for the name again.

94
00:05:49,110 --> 00:05:49,920
Copy and paste.

95
00:05:49,920 --> 00:05:56,190
If we want to go for last name, I believe that was my property value and then the last one will be

96
00:05:56,190 --> 00:05:56,820
location.

97
00:05:57,210 --> 00:06:04,020
So we provide all of the values we update and then remember, we are going to go with user or not say,

98
00:06:04,270 --> 00:06:05,010
serve the user.

99
00:06:05,280 --> 00:06:07,920
Now I'm not going to go over the various set ups again.

100
00:06:08,340 --> 00:06:13,740
I hope that I convey that message in the very beginning, and let's create a new token.

101
00:06:13,920 --> 00:06:20,970
So I'm going to go token, then user, then create and create the waiting time was the function and

102
00:06:20,970 --> 00:06:22,300
then let's send the response.

103
00:06:22,320 --> 00:06:29,340
And since I already have pretty much everything set up here, minus we'll copy this line of code and

104
00:06:29,340 --> 00:06:35,580
just be disabled, but where I'm going to remove the console.log and allow the user token location,

105
00:06:35,820 --> 00:06:37,740
as well as the user location.

106
00:06:38,100 --> 00:06:43,140
And then this is the case where remember, password is select false.

107
00:06:43,560 --> 00:06:45,360
So if everything is correct?

108
00:06:46,430 --> 00:06:49,100
The password shouldn't be here in the user object.

109
00:06:49,610 --> 00:06:51,380
So let's test everything out.

110
00:06:51,710 --> 00:06:56,540
Where I'm going to navigate back to my postman before I do anything, I just want to make sure that

111
00:06:56,540 --> 00:06:58,280
I have the valid token.

112
00:06:58,580 --> 00:07:02,000
And then let's come up with whatever updates we want to make.

113
00:07:02,330 --> 00:07:08,760
And in order again, to speed this up, I'll just grab the name, email, last name and location and

114
00:07:08,760 --> 00:07:09,710
we'll just change one.

115
00:07:10,130 --> 00:07:11,240
So we're going to go to update.

116
00:07:11,240 --> 00:07:17,510
User authorization is in place and we want to go with body roar and we're looking for Jason.

117
00:07:17,990 --> 00:07:19,160
What's the object?

118
00:07:19,160 --> 00:07:25,280
Let's set up the properties, and let's say that I'll change my name to a beta.

119
00:07:25,730 --> 00:07:26,990
So let's send it here.

120
00:07:27,200 --> 00:07:31,160
And once we send, like I just said, we're going to get back the error.

121
00:07:31,640 --> 00:07:35,120
So we'll discuss that error in more detail in next video.

122
00:07:35,420 --> 00:07:41,570
For now, simply what I want you to do is go to the user schema where we have this pretty safe, OK,

123
00:07:41,990 --> 00:07:44,570
and just comment these two stickers out.

124
00:07:44,870 --> 00:07:50,180
So these two lines of code and I'll discuss everything in greater detail in the next video.

125
00:07:50,600 --> 00:07:54,350
And then once we do that now, once we send, check it out.

126
00:07:54,740 --> 00:07:57,560
First, we successfully updated the user.

127
00:07:57,950 --> 00:08:06,200
So we went from named John to a name beta and second notice how in our response, we don't have the

128
00:08:06,200 --> 00:08:06,680
password.

129
00:08:07,040 --> 00:08:13,550
So that underscores something that I have been pretty much repeating for many, many videos that if

130
00:08:13,550 --> 00:08:21,380
we go with password and we set it equal to select false, what is going to happen when we use, for

131
00:08:21,380 --> 00:08:25,100
example, query find one, the password won't be returned.

132
00:08:25,490 --> 00:08:26,480
Hopefully this makes sense.

133
00:08:26,480 --> 00:08:31,940
And then now we can start working on the modified Barth's functionality.

134
00:08:32,210 --> 00:08:38,990
And essentially, we'll take a look at why we got back this error where we were sending the initial

135
00:08:38,990 --> 00:08:39,500
request.

