In this video let's implement updating and employee.
So back to the controller here and that is the update.
So let's see how we are going to update.
So inside a try, let me collapse this one to have some enough room to work with.
So here you go.
Const updated employee is equal to await the employee model and here you are going to find by ID and
update and the ID can be found under red dot params dot ID.
The next event is going to be it's supposed to be params and the next argument is going to be the payload,
meaning the field that we want to update.
So here we can pass in the entire request by name.
So like I said, you need to specify the field that we need to update so we can decide that to update
an employee, you can only update your full name or your city, or if you want the user to update any
payload we can pass in here.
So if I say name dot rec, dot body, and then the name here, it means that I'm allowing a user to
update only his or her name, but I want all the fields.
So here we go.
Siri is going to be as red dot body dot Siri again for this one too.
You can structure the request body.
So here Dot is married and then the salary is going to be rec dot batting dot salary and he is going
to be separated.
So lastly, let's pass in some configuration and here we go.
What we need is what we call new.
It means that we want to have the updated data on the fly.
So here, if you say true, as soon as we update, we are going to see the updated and send to the user.
And here we have what is called run validators, meaning that we want to stick to the validation schema
and that is it.
Lastly, I need to send back the updated employee.
So now moment of truth.
Oh sorry, it's supposed to be updated employee this one.
So let's create one more.
Employee Here, let me call this one as E Manuel and then from my C and then my salary is 90,000 and
I'm not married.
Let me hit send and I have two employees, so let me fetch all employees and let me see if I'm going
to have that.
Great.
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
provide us an ID here and provide it here and now.
I'll provide what I want to update.
I want to update my name to 21 and now let me hit send and you can see that the name has been changed
to one.
If I fetch all employees, you can see that there is no Emmanuel, but instead we have 21 inside.
That is great.