WEBVTT

00:03.790 --> 00:05.180
Hey there, everyone, that they share.

00:05.200 --> 00:08.680
And in this video we're going to work through with update a single user.

00:08.710 --> 00:13.390
It's really simple and probably one of the easiest video of all because we don't need to do it again.

00:13.390 --> 00:14.520
We have already done this.

00:14.530 --> 00:16.360
We just need to borrow that method.

00:16.480 --> 00:18.400
So let's shrink up all of this.

00:18.400 --> 00:22.750
So notice here when we were updating the user details, we were doing almost kind of a same thing.

00:22.750 --> 00:26.290
So this is almost exactly same, but on the admin end this time.

00:26.290 --> 00:28.210
So let's go ahead and copy this one.

00:28.210 --> 00:35.590
And I will say you go up here after admin, get one user, we're going to say admin update one user

00:35.590 --> 00:37.900
because obviously you are updating one user at a time.

00:37.900 --> 00:39.760
This is not a bulk functionality.

00:39.760 --> 00:41.350
So we're going to say.

00:42.090 --> 00:49.500
Let's say admin update of one user details.

00:49.620 --> 00:53.880
He had a really long name, but it is very explanation explanatory, so I'll just keep that.

00:54.210 --> 00:59.100
And since we are not allowing user to update the files or request, you can actually allow it to do

00:59.100 --> 00:59.670
that as well.

00:59.670 --> 01:05.370
In that case, you have to grab the user from the ID, grab the photos and all of that so you can go

01:05.370 --> 01:06.210
ahead and do that.

01:06.210 --> 01:07.530
It's a little bit of a more work.

01:07.530 --> 01:08.820
Nothing like we cannot do it.

01:08.820 --> 01:14.430
But I'm going to go ahead and skip that because this is obviously a little bit too much of a work already.

01:14.430 --> 01:17.160
This course is too long, so we are not doing that.

01:17.580 --> 01:21.990
So first let's actually grab and find a user based on this.

01:21.990 --> 01:26.280
So first, we are going to say that, hey, if we want to update the user, you give me the new data

01:26.280 --> 01:30.660
itself, which is going to be obviously in the body, but we'll also provide admin and functionality

01:30.660 --> 01:32.580
to update the role request.

01:32.580 --> 01:34.440
Dot body, dot role.

01:34.470 --> 01:39.930
Now again, the most important thing is users or the admin should only give me the roles which are available.

01:39.930 --> 01:44.940
So probably a dropdown is going to be fantastic thing in the front end because if we get the role which

01:44.940 --> 01:47.850
is not defined or we haven't rolled any controller, it's going to be bad.

01:47.850 --> 01:54.780
So dropdown is a best guess in this case and we will be extracting the user from the params this time

01:54.780 --> 01:56.730
because obviously this will come up again.

01:56.730 --> 01:58.920
Remember, I didn't magically got this one.

01:58.920 --> 02:01.680
I get this from slash admin slash user slash ID.

02:01.710 --> 02:05.040
The reason this is only written in this way because this is a get request.

02:05.040 --> 02:08.820
This is a put request for updating the things and this is the delete request.

02:08.820 --> 02:13.830
So same route can be used for performing three different things based on what request is coming in,

02:13.830 --> 02:15.900
get put or post accordingly.

02:15.900 --> 02:17.730
The controller will fire upon that.

02:17.910 --> 02:20.010
So we're going to go ahead and fire up this one.

02:20.010 --> 02:27.270
And we are going to say, I want to grab this one from request dot params dot ID and I'm giving you

02:27.270 --> 02:28.260
all the new data.

02:28.260 --> 02:30.270
These things are absolutely fine.

02:30.270 --> 02:31.350
Success is true.

02:31.350 --> 02:32.430
So that is fantastic.

02:32.430 --> 02:34.770
Remember, we didn't draw any single line of code.

02:34.800 --> 02:40.500
Now, in this case, if you want to update more data on the user itself, then okay, just go ahead,

02:40.500 --> 02:45.060
grab the user from request dot params dot id, hold that into a user variable.

02:45.060 --> 02:49.830
Then further go ahead and check whether the request files actually consist of photo.

02:49.860 --> 02:54.780
If the photo is there, then go ahead and update that just like we previously did that use cloud to

02:54.780 --> 02:56.400
delete a photo and update the photo.

02:56.400 --> 03:01.230
Save that into a into this new data as photo use ID and secure the URL.

03:01.230 --> 03:02.370
Surely you can do this.

03:02.370 --> 03:05.460
I'm absolutely 100% sure on you on this part.

03:05.490 --> 03:06.810
It's a little bit time consuming.

03:06.810 --> 03:07.410
That's it.

03:07.770 --> 03:15.240
Okay, let's go ahead and use this admin update one user detail and bring that into the roots itself.

03:15.240 --> 03:15.990
There we go.

03:16.020 --> 03:21.000
Now, the best thing what I want to show here is that, remember, we have this root slash admin slash

03:21.000 --> 03:22.170
user slash ID.

03:22.200 --> 03:24.150
This one was get request.

03:24.150 --> 03:30.360
Now on the same root, I'll remove this colon and I'll say that this time we have a put request.

03:31.140 --> 03:34.830
So on the put request first we have to say that it should be logged in.

03:34.830 --> 03:40.290
So admin also needs to log in and then we are going to go ahead and provide a simple custom role and

03:40.290 --> 03:42.480
that custom role is only available for admin.

03:42.480 --> 03:43.020
In this case.

03:43.020 --> 03:46.530
Make sure you keep everything as lowercase and further down the road.

03:46.530 --> 03:50.730
This should be run through this one, which is admin update one user.

03:50.730 --> 03:56.250
So remember this is a get root, this is a put root and then I need to bring that in.

03:57.270 --> 04:03.120
So save this and this is all what we got to do to update the user in case admin wants to update anything.

04:03.120 --> 04:06.780
He has to pass on the field and everything and we won't be doing any testing.

04:06.780 --> 04:08.790
I leave that as a simple exercise for you.

04:08.790 --> 04:14.040
So in the very last video, the next video, we are going to work on deleting the user, which is exactly

04:14.040 --> 04:14.700
almost same.

04:14.700 --> 04:19.470
I recommend you to go ahead and further do it before me as well, or at least try to read in the Mongoose

04:19.470 --> 04:21.780
that what is the method used to delete the object?

04:21.780 --> 04:23.760
Let's go ahead and catch up in the next video.
