WEBVTT

00:03.880 --> 00:05.290
Hey, did everyone they share?

00:05.290 --> 00:08.180
And in this video we are going to work through with the setup of the roots.

00:08.200 --> 00:12.580
I first thought that we are going to create all the controller first, but I then realized let's go

00:12.580 --> 00:14.980
with the same flow that we have been working so far.

00:15.040 --> 00:16.870
So let's go ahead and create another route.

00:16.870 --> 00:21.610
So I'm going to go ahead and open up this route, right click, and create a new file and call this

00:21.610 --> 00:24.520
one as order or orders.

00:24.550 --> 00:25.330
Order is fine.

00:25.330 --> 00:26.630
Order dot DJ's.

00:26.860 --> 00:29.670
Now let's go ahead and bring some information from the product.

00:29.740 --> 00:33.400
Geez, I think this all we can bring at the very top.

00:33.580 --> 00:40.870
Let's go ahead and grab all of this and let's place it up here in the order route.

00:41.170 --> 00:45.310
We are not going to need we are going to need everything from here.

00:45.460 --> 00:47.740
Let's remove all of this.

00:47.740 --> 00:51.090
And the controller at this time is not going to be the product controller like this.

00:51.100 --> 00:52.750
It's going to be order controller.

00:52.990 --> 00:57.580
So we're going to go ahead and say, hey, remove this one and bring in order controller.

00:57.670 --> 01:02.320
And that is just one route here or one method, which is create order.

01:02.470 --> 01:03.500
This is all good.

01:03.520 --> 01:08.470
Let's also bring from the product route the export.

01:08.860 --> 01:09.820
Copy that.

01:10.420 --> 01:13.780
And at the very end of it exported the router.

01:13.900 --> 01:18.460
And then we are going to need just one route to copy that and edit that.

01:19.210 --> 01:23.830
So this is what so how this route is going to work, we are going to just place simply an order.

01:23.830 --> 01:26.620
So let's go ahead and say this is going to be order create.

01:26.650 --> 01:31.330
This route is going to be handled by this method since a lot of information is coming in.

01:31.330 --> 01:35.650
Let's call this one as post, as simple as it could be, but creating of the route.

01:35.650 --> 01:40.330
Obviously we are extracting some information from the user who is the user who is placing the order

01:40.360 --> 01:41.170
automatically.

01:41.170 --> 01:43.270
So this should be authenticated route.

01:43.270 --> 01:43.840
So there we go.

01:43.840 --> 01:48.700
Now we have done verification from the back end user can do it on the front end as well or the front

01:48.700 --> 01:49.540
end programmer.

01:49.540 --> 01:50.860
But we have done this one.

01:50.860 --> 01:53.500
Now let's go ahead and work on with the ABCs.

01:53.560 --> 01:56.100
All we got to do is bring in up here the route.

01:56.110 --> 01:57.520
Let's go ahead and bring in here.

01:57.790 --> 02:00.130
Let's call this one as simply order.

02:00.550 --> 02:04.360
And the route that is going to come in is going to be slash order.

02:04.750 --> 02:08.860
And let's go ahead and inject another middleware slash API slash V one.

02:08.860 --> 02:14.680
And this time all the routes are going to be managed here and that's pretty much it.

02:14.710 --> 02:20.230
Now, when I, I expect that if I hit this route slash order, slash, create, I should receive some

02:20.230 --> 02:23.470
of the error message, not something like I don't find this route.

02:24.310 --> 02:26.620
Let's go ahead and minimize this, minimize this.

02:26.890 --> 02:28.630
And there is a user, there is a product.

02:28.630 --> 02:30.460
We don't have anything to test for Payment Gateway.

02:30.460 --> 02:37.060
But let's go ahead and have something for this is add folder and this one is going to be for orders.

02:38.320 --> 02:41.860
And inside the order, I'm going to go ahead and add a request.

02:42.630 --> 02:47.070
So this one, this request is going to be for create order.

02:48.600 --> 02:49.320
There we go.

02:49.320 --> 02:52.510
And this one is actually a post request, so save that.

02:52.530 --> 03:00.720
Now, let's close this one because this was just a test and we can actually go ahead and copy this and

03:00.720 --> 03:01.950
close rest of them.

03:02.490 --> 03:03.780
We don't need it.

03:04.760 --> 03:06.650
Get one product, order everything.

03:06.650 --> 03:09.860
So this is okay and we're going to paste this one, save this.

03:09.860 --> 03:11.570
Now all I want to do is one more time.

03:11.570 --> 03:16.070
Probably it's being long, so I'm going to go ahead and log in so that all my tokens and everything

03:16.070 --> 03:16.760
is being refreshed.

03:16.760 --> 03:17.750
So that is fine.

03:17.750 --> 03:19.700
I can go ahead and close this one now.

03:19.910 --> 03:23.330
So I'm pretty sure I am aware of it that now the things are there.

03:23.450 --> 03:30.350
So now all I have to do is remove this one and say Order slash, create, and we should be.

03:30.350 --> 03:34.850
Even if I send the post request on this one, we should receive some of the errors that a lot of fields

03:34.850 --> 03:35.300
are missing.

03:35.300 --> 03:39.780
So order validation failed shipping info dot country path and hold these things.

03:39.780 --> 03:40.430
So I required.

03:40.460 --> 03:41.930
You haven't passed me on this.

03:42.320 --> 03:46.640
Okay, now let's go ahead and do a small testing.

03:46.640 --> 03:49.430
This is a little bit so I am giving you this file here.

03:49.430 --> 03:53.180
Inside the utils there is a test ordered or JSON which has all the data.

03:53.180 --> 03:57.950
I know this data would have taken a little bit while to write, so that's why I'm giving it to you again.

03:57.950 --> 03:58.610
It's nothing much.

03:58.610 --> 04:03.860
Shipping info is an object which has all these properties being mentioned or the item is having all

04:03.860 --> 04:07.550
these array with a property being mentioned in the product itself.

04:07.550 --> 04:11.780
We are trying since we are not placing any check to strictly check whether this is an object or something.

04:11.780 --> 04:13.160
We are going to try this.

04:13.160 --> 04:17.270
If this doesn't work, we are going to remove the required field from the module and then we are going

04:17.270 --> 04:19.490
to just inject it and we'll try this out.

04:19.670 --> 04:23.690
So let's go ahead and copy this and see if this works.

04:23.690 --> 04:29.240
So we're going to say that, hey, inject this into the body raw and this should be JSON.

04:29.510 --> 04:33.350
So let's go ahead and place all of this information and let's try this out.

04:33.350 --> 04:36.680
I'm going to go ahead and send this one and it says, hey, order is success.

04:36.680 --> 04:40.520
But again, I'm shouting, literally shouting this again to you.

04:40.550 --> 04:42.770
This what we have done here is the product.

04:42.770 --> 04:44.390
This is absolutely bad.

04:44.390 --> 04:45.680
This is really, really bad.

04:45.680 --> 04:46.790
It shouldn't be like that.

04:46.790 --> 04:48.050
This is not a reason.

04:48.050 --> 04:51.920
This is just a simple string that we have injected here.

04:51.920 --> 04:55.490
Let's refresh our database and see what we got in the orders.

04:55.490 --> 04:56.630
So this is the order.

04:56.630 --> 05:03.500
Notice here the object ID user is having an object ID, but if I open up this order item, this is an

05:03.500 --> 05:04.160
object.

05:04.160 --> 05:05.780
And notice here the product is.

05:06.050 --> 05:08.540
Thank goodness that it has taken this one as an object idea.

05:08.540 --> 05:13.220
So this is really nice that there are some updation in the mongoose, but still wrong is wrong.

05:13.220 --> 05:19.370
We are having this one when we actually inject it by properly having a place being by request or something

05:19.370 --> 05:20.000
that it goes up.

05:20.000 --> 05:24.200
But this is really nice that it has taken this an object ID really nice and super happy.

05:24.200 --> 05:25.430
There has been some update.

05:25.430 --> 05:28.100
So again, my, my worries are all gone.

05:28.400 --> 05:29.510
So this is all good.

05:29.510 --> 05:34.580
And now I'll give this test order JSON file to you so that you can modify it a little bit later and

05:34.580 --> 05:36.800
can inject that this is going to save you some time.

05:36.890 --> 05:38.420
And there we go, test it out.

05:38.420 --> 05:42.620
In fact, the test is okay as well, that whatever the controller we have designed, this order controller

05:42.620 --> 05:44.690
is working absolutely fine.

05:44.690 --> 05:50.120
Let's move into the next video and see that how we can pass on one single order and just see that how

05:50.120 --> 05:50.630
it works.

05:50.630 --> 05:52.310
Let's go ahead and catch up in the next video.
