In this video, we are going to create a controller for allowing a user to update his or her details.
So for updating, we're going to have four controllers.
One controller is going to update only the details about the user with the exception of the password
and then the profile image and then the cover image and going to have separate controllers for updating
the password or changing the profile image or updating the cover image.
So first is let's start with updating the user with the other details.
With the exception of the password and then the profile or the cover image.
So let me collapse this one and then the profile as well.
So let's start with the update user, which is this.
So let's have the roadmap for updating.
The first step is that we are going to check if the email is taken, meaning that if a user is updating
an email which has been used by different user, we need to avoid that.
So first of all, let's go ahead and then structure the payload.
So for this we are going to allow the user to update the full name email and then the password only
and going to be as equal to rec dot body.
So first step is let's check if the email is taken.
So the comment goes like this.
So here, if the user provide an email, then we are going to check for the email.
So we are going to be as concerned.
Email ticking is equal to weight and then the user does not find one and you are going to find by the
email.
I.
Is that so?
In here.
If we have a male taking.
Then you go ahead and throw an error.
So let's pass next year and we are going to return from this function and connect and pass in our app
error function.
And you say that email is taken.
And for this, let's pass in the status code RS 400.
So if the email is not taken, then we can go ahead and update the user and it goes like this const
user is equal to a weight user and then going to be as fined by ID and update, which is this.
And the ID can be found under red dot params dot ID.
All right.
The first argument, the next argument is going to be the properties that I want to update and I want
the user to update the full name and then the email.
So for the password, I'm not going to allow the user to update the password and I want the user to
update the full name and then the email only.
So here we go.
The last step is that I need to sign the data as that's going to be the user.
All right.
So for this, if I want to have the updated record, I'm going to pass in additional configuration as
that.
And here I'll provide new to true.
Perfect.
So let's go ahead and make the request to make sure that everything works fine by inside here.
Let's call next and you're going to pass in the error to our app error function as error.
Dot message.
Okay, so let's get back to the tender client and this is the update, which is this.
And for this I need to provide the right ID of the user.
So let's locate a thing.
We have the ID here, which is this.
So inside the update user here, I'm going to provide the ID and then the data that I want to change
for this one.
I want to change the full name and I'll make this one as do and that is it.
So when I hit send, let's see, we can see that we have changed the full name from John to Doe and
I can also go ahead and change the email and going to be as DOE at gmail.com and hit send.
And you can see that the email is being changed or other properties remains the same.
So if I go ahead and look in with the for my email, let's see.
You can see that you go by the message as invalid login credentials because I've made changes to the
email, so now it's door at gmail.com.
And everything works fine.
So this how we can update the user property in the next video.
Let's see how we can change the user password.