WEBVTT

00:03.790 --> 00:08.020
Hey, did everyone that they share and in this video we are going to work through that how admin can

00:08.020 --> 00:11.080
delete a product or delete product is really, really simple.

00:11.080 --> 00:13.000
Shouldn't be a much bigger of a deal.

00:13.000 --> 00:15.760
So let's go ahead and copy this and there we go.

00:16.060 --> 00:17.920
Now we got all of this.

00:17.920 --> 00:22.600
Let's go ahead and minimize this one and we'll be working with the bottom one.

00:22.600 --> 00:23.320
There we go.

00:23.500 --> 00:30.130
So first thing is, we need to update that, which is admin delete one product, obviously one.

00:30.130 --> 00:34.300
So we're going to hold the product just by the same logic we did in the last video.

00:34.300 --> 00:37.120
So product is going to be requested params not ID.

00:37.150 --> 00:40.150
If we are not able to find the product then this is an issue.

00:40.150 --> 00:41.830
So this needs to be go up there.

00:41.860 --> 00:44.530
We don't need to hold the reference of the array itself.

00:44.530 --> 00:49.540
So we're going to go ahead and let's expand how we are handling the files now for the handling of the

00:49.540 --> 00:55.450
file part, I would say that rather requesting the file itself, let's go ahead and cut out this logic

00:55.450 --> 00:56.860
where we destroy the files.

00:56.860 --> 00:59.740
So let's go ahead and cut this out and place it outside.

00:59.740 --> 01:03.790
Because if we have found the product, then we would like to delete them.

01:03.790 --> 01:06.820
So product photos, dot length and let's go ahead and destroy all of them.

01:06.820 --> 01:07.870
Just deleting the model.

01:07.870 --> 01:12.310
It is not good because we are placing the file somewhere else, so let's go ahead and remove that.

01:12.340 --> 01:14.260
We don't need to hold the reference.

01:14.260 --> 01:17.620
We can actually remove this entire part of the code and that's it.

01:17.620 --> 01:19.210
That should also be fine.

01:19.450 --> 01:23.410
We are not uploading any photos, so this shouldn't be needed.

01:23.410 --> 01:26.110
So this should all this all can go away.

01:26.110 --> 01:33.190
We are not checking for the files inside the body so that can also go away and this looks okay so far.

01:33.190 --> 01:36.190
So we have found the product, we have removed the images.

01:36.190 --> 01:39.220
We don't need to update anything from this area or something.

01:39.220 --> 01:41.290
We just need to run a method to remove that.

01:41.290 --> 01:43.300
So this should all the good.

01:43.300 --> 01:44.740
Let's go ahead and work on with that.

01:44.920 --> 01:47.320
Now removing is really, really simple.

01:47.320 --> 01:51.490
All you got to do is simply say, hey, product and remember we are holding now.

01:51.490 --> 01:56.170
We are not running this query directly on the product model itself, but the object that we have received

01:56.170 --> 01:57.280
from this model.

01:57.280 --> 02:00.490
So we're going to go ahead and say, hey, we want to just remove.

02:00.490 --> 02:01.810
And that's pretty much it.

02:01.810 --> 02:04.870
Since this is a database operation, we are going to go ahead and wait.

02:04.900 --> 02:08.290
Maybe you want to hold the result into a response or available.

02:08.290 --> 02:09.010
That's up to you.

02:09.010 --> 02:11.140
But we are going to go ahead and just do that.

02:11.320 --> 02:17.000
And we don't need to run this query, obviously, so we can go ahead and remove this status.

02:17.000 --> 02:22.990
Success is true, and we're going to go ahead and send a simple message that product was deleted.

02:22.990 --> 02:29.440
So product product was deleted with an exclamation.

02:29.440 --> 02:30.280
There we go.

02:30.370 --> 02:32.830
And that's all we'll be sending up.

02:32.830 --> 02:35.080
Maybe you want to send what was the product being removed?

02:35.080 --> 02:35.980
Do you want to send that?

02:35.980 --> 02:38.380
That's up to you, but I don't think it's necessary.

02:38.530 --> 02:39.280
So there we go.

02:39.280 --> 02:43.810
Let's go ahead and bring this throughout and just update the previous route which we got.

02:43.810 --> 02:45.520
So let's go ahead at that top.

02:45.520 --> 02:46.480
There we go.

02:46.810 --> 02:49.630
And housecleaning, purpose, extra comma.

02:49.810 --> 02:50.590
Okay, let's see.

02:50.590 --> 02:53.710
In the last route, we are having an admin product and ID.

02:53.710 --> 02:55.210
We were updating that.

02:55.210 --> 02:57.310
So this is a small bug.

02:57.340 --> 02:58.990
It should be put.

02:58.990 --> 03:01.090
I'm pretty sure you might have already noticed that.

03:01.210 --> 03:07.930
And we need to change it on another method which is going to be simply dot not there.

03:08.830 --> 03:12.160
There we go and dot delete.

03:14.170 --> 03:14.680
There we go.

03:14.710 --> 03:15.550
Dot delete.

03:16.120 --> 03:20.880
And in the deletion case also will be following the same routine that user should be logged in.

03:20.890 --> 03:21.940
He should be admin.

03:21.940 --> 03:23.650
So custom role.

03:23.740 --> 03:26.230
The role should be admin obviously.

03:26.230 --> 03:30.130
And then we can actually add this one for the deleting of the product.

03:30.130 --> 03:34.390
So the same route, wherever you are sending me the ID, if you send me a port request, I'll update

03:34.390 --> 03:34.720
it.

03:34.750 --> 03:37.090
If you send me a delete request, I'll delete that.

03:37.810 --> 03:38.500
Looks great.

03:38.500 --> 03:40.450
Looks fantastic, actually.

03:41.200 --> 03:41.830
So there we go.

03:41.830 --> 03:47.080
We have all the admin routes and in fact, at this point we can go ahead and put up a comment so we

03:47.080 --> 03:55.750
can say these are admin admin only controllers and these are basic regular user controller.

03:55.750 --> 03:56.530
So there we go.

03:56.530 --> 03:58.270
We can actually minimise this one.

03:58.750 --> 03:59.200
There we go.

03:59.230 --> 04:00.160
Looks fantastic.

04:00.160 --> 04:03.130
Absolutely clean code and absolutely readable code.

04:03.130 --> 04:04.540
So that's it for this one.

04:04.540 --> 04:06.400
Let's go in and catch up in the next one.
