Hey there, everyone, that they share.
And in this video we're going to work through with update a single user.
It's really simple and probably one of the easiest video of all because we don't need to do it again.
We have already done this.
We just need to borrow that method.
So let's shrink up all of this.
So notice here when we were updating the user details, we were doing almost kind of a same thing.
So this is almost exactly same, but on the admin end this time.
So let's go ahead and copy this one.
And I will say you go up here after admin, get one user, we're going to say admin update one user
because obviously you are updating one user at a time.
This is not a bulk functionality.
So we're going to say.
Let's say admin update of one user details.
He had a really long name, but it is very explanation explanatory, so I'll just keep that.
And since we are not allowing user to update the files or request, you can actually allow it to do
that as well.
In that case, you have to grab the user from the ID, grab the photos and all of that so you can go
ahead and do that.
It's a little bit of a more work.
Nothing like we cannot do it.
But I'm going to go ahead and skip that because this is obviously a little bit too much of a work already.
This course is too long, so we are not doing that.
So first let's actually grab and find a user based on this.
So first, we are going to say that, hey, if we want to update the user, you give me the new data
itself, which is going to be obviously in the body, but we'll also provide admin and functionality
to update the role request.
Dot body, dot role.
Now again, the most important thing is users or the admin should only give me the roles which are available.
So probably a dropdown is going to be fantastic thing in the front end because if we get the role which
is not defined or we haven't rolled any controller, it's going to be bad.
So dropdown is a best guess in this case and we will be extracting the user from the params this time
because obviously this will come up again.
Remember, I didn't magically got this one.
I get this from slash admin slash user slash ID.
The reason this is only written in this way because this is a get request.
This is a put request for updating the things and this is the delete request.
So same route can be used for performing three different things based on what request is coming in,
get put or post accordingly.
The controller will fire upon that.
So we're going to go ahead and fire up this one.
And we are going to say, I want to grab this one from request dot params dot ID and I'm giving you
all the new data.
These things are absolutely fine.
Success is true.
So that is fantastic.
Remember, we didn't draw any single line of code.
Now, in this case, if you want to update more data on the user itself, then okay, just go ahead,
grab the user from request dot params dot id, hold that into a user variable.
Then further go ahead and check whether the request files actually consist of photo.
If the photo is there, then go ahead and update that just like we previously did that use cloud to
delete a photo and update the photo.
Save that into a into this new data as photo use ID and secure the URL.
Surely you can do this.
I'm absolutely 100% sure on you on this part.
It's a little bit time consuming.
That's it.
Okay, let's go ahead and use this admin update one user detail and bring that into the roots itself.
There we go.
Now, the best thing what I want to show here is that, remember, we have this root slash admin slash
user slash ID.
This one was get request.
Now on the same root, I'll remove this colon and I'll say that this time we have a put request.
So on the put request first we have to say that it should be logged in.
So admin also needs to log in and then we are going to go ahead and provide a simple custom role and
that custom role is only available for admin.
In this case.
Make sure you keep everything as lowercase and further down the road.
This should be run through this one, which is admin update one user.
So remember this is a get root, this is a put root and then I need to bring that in.
So save this and this is all what we got to do to update the user in case admin wants to update anything.
He has to pass on the field and everything and we won't be doing any testing.
I leave that as a simple exercise for you.
So in the very last video, the next video, we are going to work on deleting the user, which is exactly
almost same.
I recommend you to go ahead and further do it before me as well, or at least try to read in the Mongoose
that what is the method used to delete the object?
Let's go ahead and catch up in the next video.