1
00:00:00,550 --> 00:00:08,140
In this video, we are going to create a controller for allowing a user to update his or her details.

2
00:00:08,320 --> 00:00:11,950
So for updating, we're going to have four controllers.

3
00:00:11,950 --> 00:00:19,000
One controller is going to update only the details about the user with the exception of the password

4
00:00:19,000 --> 00:00:25,690
and then the profile image and then the cover image and going to have separate controllers for updating

5
00:00:25,690 --> 00:00:31,850
the password or changing the profile image or updating the cover image.

6
00:00:31,870 --> 00:00:36,310
So first is let's start with updating the user with the other details.

7
00:00:36,310 --> 00:00:40,980
With the exception of the password and then the profile or the cover image.

8
00:00:40,990 --> 00:00:44,950
So let me collapse this one and then the profile as well.

9
00:00:44,950 --> 00:00:48,880
So let's start with the update user, which is this.

10
00:00:48,880 --> 00:00:52,360
So let's have the roadmap for updating.

11
00:00:52,390 --> 00:01:01,240
The first step is that we are going to check if the email is taken, meaning that if a user is updating

12
00:01:01,240 --> 00:01:06,640
an email which has been used by different user, we need to avoid that.

13
00:01:06,670 --> 00:01:10,960
So first of all, let's go ahead and then structure the payload.

14
00:01:10,960 --> 00:01:19,780
So for this we are going to allow the user to update the full name email and then the password only

15
00:01:20,320 --> 00:01:26,470
and going to be as equal to rec dot body.

16
00:01:26,950 --> 00:01:31,090
So first step is let's check if the email is taken.

17
00:01:31,090 --> 00:01:33,310
So the comment goes like this.

18
00:01:33,310 --> 00:01:40,510
So here, if the user provide an email, then we are going to check for the email.

19
00:01:40,540 --> 00:01:42,910
So we are going to be as concerned.

20
00:01:42,940 --> 00:01:54,700
Email ticking is equal to weight and then the user does not find one and you are going to find by the

21
00:01:54,700 --> 00:01:55,390
email.

22
00:01:59,040 --> 00:01:59,290
I.

23
00:01:59,310 --> 00:02:00,720
Is that so?

24
00:02:00,720 --> 00:02:01,890
In here.

25
00:02:01,950 --> 00:02:04,770
If we have a male taking.

26
00:02:05,760 --> 00:02:08,509
Then you go ahead and throw an error.

27
00:02:08,520 --> 00:02:18,570
So let's pass next year and we are going to return from this function and connect and pass in our app

28
00:02:18,570 --> 00:02:19,770
error function.

29
00:02:19,770 --> 00:02:22,620
And you say that email is taken.

30
00:02:23,650 --> 00:02:28,840
And for this, let's pass in the status code RS 400.

31
00:02:29,080 --> 00:02:37,510
So if the email is not taken, then we can go ahead and update the user and it goes like this const

32
00:02:37,540 --> 00:02:48,490
user is equal to a weight user and then going to be as fined by ID and update, which is this.

33
00:02:48,490 --> 00:02:55,240
And the ID can be found under red dot params dot ID.

34
00:02:55,840 --> 00:02:56,350
All right.

35
00:02:56,350 --> 00:03:02,350
The first argument, the next argument is going to be the properties that I want to update and I want

36
00:03:02,350 --> 00:03:06,970
the user to update the full name and then the email.

37
00:03:07,890 --> 00:03:14,340
So for the password, I'm not going to allow the user to update the password and I want the user to

38
00:03:14,340 --> 00:03:17,770
update the full name and then the email only.

39
00:03:17,790 --> 00:03:19,140
So here we go.

40
00:03:19,170 --> 00:03:25,800
The last step is that I need to sign the data as that's going to be the user.

41
00:03:26,490 --> 00:03:26,970
All right.

42
00:03:26,970 --> 00:03:35,070
So for this, if I want to have the updated record, I'm going to pass in additional configuration as

43
00:03:35,070 --> 00:03:35,550
that.

44
00:03:35,550 --> 00:03:38,480
And here I'll provide new to true.

45
00:03:40,360 --> 00:03:41,170
Perfect.

46
00:03:41,200 --> 00:03:47,370
So let's go ahead and make the request to make sure that everything works fine by inside here.

47
00:03:47,380 --> 00:03:55,600
Let's call next and you're going to pass in the error to our app error function as error.

48
00:03:56,760 --> 00:03:58,200
Dot message.

49
00:03:59,310 --> 00:04:05,250
Okay, so let's get back to the tender client and this is the update, which is this.

50
00:04:05,250 --> 00:04:10,320
And for this I need to provide the right ID of the user.

51
00:04:10,350 --> 00:04:13,290
So let's locate a thing.

52
00:04:13,290 --> 00:04:15,750
We have the ID here, which is this.

53
00:04:15,990 --> 00:04:25,440
So inside the update user here, I'm going to provide the ID and then the data that I want to change

54
00:04:25,440 --> 00:04:26,250
for this one.

55
00:04:26,250 --> 00:04:33,030
I want to change the full name and I'll make this one as do and that is it.

56
00:04:33,030 --> 00:04:41,190
So when I hit send, let's see, we can see that we have changed the full name from John to Doe and

57
00:04:41,190 --> 00:04:52,860
I can also go ahead and change the email and going to be as DOE at gmail.com and hit send.

58
00:04:54,640 --> 00:05:00,570
And you can see that the email is being changed or other properties remains the same.

59
00:05:00,580 --> 00:05:05,890
So if I go ahead and look in with the for my email, let's see.

60
00:05:06,860 --> 00:05:13,280
You can see that you go by the message as invalid login credentials because I've made changes to the

61
00:05:13,280 --> 00:05:16,850
email, so now it's door at gmail.com.

62
00:05:17,600 --> 00:05:19,850
And everything works fine.

63
00:05:19,850 --> 00:05:24,530
So this how we can update the user property in the next video.

64
00:05:24,530 --> 00:05:28,190
Let's see how we can change the user password.

