1
00:00:09,530 --> 00:00:13,640
In this video let's implement updating and employee.

2
00:00:13,640 --> 00:00:17,300
So back to the controller here and that is the update.

3
00:00:17,300 --> 00:00:20,240
So let's see how we are going to update.

4
00:00:20,240 --> 00:00:25,940
So inside a try, let me collapse this one to have some enough room to work with.

5
00:00:26,000 --> 00:00:27,140
So here you go.

6
00:00:27,170 --> 00:00:37,670
Const updated employee is equal to await the employee model and here you are going to find by ID and

7
00:00:37,670 --> 00:00:43,730
update and the ID can be found under red dot params dot ID.

8
00:00:44,000 --> 00:00:51,920
The next event is going to be it's supposed to be params and the next argument is going to be the payload,

9
00:00:51,920 --> 00:00:54,620
meaning the field that we want to update.

10
00:00:54,620 --> 00:00:58,460
So here we can pass in the entire request by name.

11
00:00:58,550 --> 00:01:05,780
So like I said, you need to specify the field that we need to update so we can decide that to update

12
00:01:05,780 --> 00:01:13,160
an employee, you can only update your full name or your city, or if you want the user to update any

13
00:01:13,220 --> 00:01:15,170
payload we can pass in here.

14
00:01:15,200 --> 00:01:23,750
So if I say name dot rec, dot body, and then the name here, it means that I'm allowing a user to

15
00:01:23,750 --> 00:01:28,130
update only his or her name, but I want all the fields.

16
00:01:28,130 --> 00:01:29,240
So here we go.

17
00:01:29,270 --> 00:01:35,720
Siri is going to be as red dot body dot Siri again for this one too.

18
00:01:35,750 --> 00:01:39,230
You can structure the request body.

19
00:01:39,230 --> 00:01:49,640
So here Dot is married and then the salary is going to be rec dot batting dot salary and he is going

20
00:01:49,640 --> 00:01:51,380
to be separated.

21
00:01:51,590 --> 00:01:56,930
So lastly, let's pass in some configuration and here we go.

22
00:01:57,530 --> 00:01:59,900
What we need is what we call new.

23
00:01:59,930 --> 00:02:04,550
It means that we want to have the updated data on the fly.

24
00:02:04,580 --> 00:02:11,960
So here, if you say true, as soon as we update, we are going to see the updated and send to the user.

25
00:02:12,110 --> 00:02:18,800
And here we have what is called run validators, meaning that we want to stick to the validation schema

26
00:02:18,800 --> 00:02:19,790
and that is it.

27
00:02:19,790 --> 00:02:24,290
Lastly, I need to send back the updated employee.

28
00:02:24,440 --> 00:02:26,720
So now moment of truth.

29
00:02:26,720 --> 00:02:30,290
Oh sorry, it's supposed to be updated employee this one.

30
00:02:30,680 --> 00:02:32,630
So let's create one more.

31
00:02:32,630 --> 00:02:50,540
Employee Here, let me call this one as E Manuel and then from my C and then my salary is 90,000 and

32
00:02:50,540 --> 00:02:51,680
I'm not married.

33
00:02:51,770 --> 00:02:59,330
Let me hit send and I have two employees, so let me fetch all employees and let me see if I'm going

34
00:02:59,330 --> 00:03:00,230
to have that.

35
00:03:00,560 --> 00:03:01,130
Great.

36
00:03:01,130 --> 00:03:08,990
So let's say that I want to change my name to 21, so I'll copy the ID and get back to the update and

37
00:03:08,990 --> 00:03:13,430
provide us an ID here and provide it here and now.

38
00:03:13,430 --> 00:03:16,070
I'll provide what I want to update.

39
00:03:16,130 --> 00:03:24,980
I want to update my name to 21 and now let me hit send and you can see that the name has been changed

40
00:03:24,980 --> 00:03:25,910
to one.

41
00:03:26,360 --> 00:03:34,670
If I fetch all employees, you can see that there is no Emmanuel, but instead we have 21 inside.

42
00:03:34,850 --> 00:03:36,200
That is great.

