Hey, did everyone they share?
And in this video we are going to work through with the setup of the roots.
I first thought that we are going to create all the controller first, but I then realized let's go
with the same flow that we have been working so far.
So let's go ahead and create another route.
So I'm going to go ahead and open up this route, right click, and create a new file and call this
one as order or orders.
Order is fine.
Order dot DJ's.
Now let's go ahead and bring some information from the product.
Geez, I think this all we can bring at the very top.
Let's go ahead and grab all of this and let's place it up here in the order route.
We are not going to need we are going to need everything from here.
Let's remove all of this.
And the controller at this time is not going to be the product controller like this.
It's going to be order controller.
So we're going to go ahead and say, hey, remove this one and bring in order controller.
And that is just one route here or one method, which is create order.
This is all good.
Let's also bring from the product route the export.
Copy that.
And at the very end of it exported the router.
And then we are going to need just one route to copy that and edit that.
So this is what so how this route is going to work, we are going to just place simply an order.
So let's go ahead and say this is going to be order create.
This route is going to be handled by this method since a lot of information is coming in.
Let's call this one as post, as simple as it could be, but creating of the route.
Obviously we are extracting some information from the user who is the user who is placing the order
automatically.
So this should be authenticated route.
So there we go.
Now we have done verification from the back end user can do it on the front end as well or the front
end programmer.
But we have done this one.
Now let's go ahead and work on with the ABCs.
All we got to do is bring in up here the route.
Let's go ahead and bring in here.
Let's call this one as simply order.
And the route that is going to come in is going to be slash order.
And let's go ahead and inject another middleware slash API slash V one.
And this time all the routes are going to be managed here and that's pretty much it.
Now, when I, I expect that if I hit this route slash order, slash, create, I should receive some
of the error message, not something like I don't find this route.
Let's go ahead and minimize this, minimize this.
And there is a user, there is a product.
We don't have anything to test for Payment Gateway.
But let's go ahead and have something for this is add folder and this one is going to be for orders.
And inside the order, I'm going to go ahead and add a request.
So this one, this request is going to be for create order.
There we go.
And this one is actually a post request, so save that.
Now, let's close this one because this was just a test and we can actually go ahead and copy this and
close rest of them.
We don't need it.
Get one product, order everything.
So this is okay and we're going to paste this one, save this.
Now all I want to do is one more time.
Probably it's being long, so I'm going to go ahead and log in so that all my tokens and everything
is being refreshed.
So that is fine.
I can go ahead and close this one now.
So I'm pretty sure I am aware of it that now the things are there.
So now all I have to do is remove this one and say Order slash, create, and we should be.
Even if I send the post request on this one, we should receive some of the errors that a lot of fields
are missing.
So order validation failed shipping info dot country path and hold these things.
So I required.
You haven't passed me on this.
Okay, now let's go ahead and do a small testing.
This is a little bit so I am giving you this file here.
Inside the utils there is a test ordered or JSON which has all the data.
I know this data would have taken a little bit while to write, so that's why I'm giving it to you again.
It's nothing much.
Shipping info is an object which has all these properties being mentioned or the item is having all
these array with a property being mentioned in the product itself.
We are trying since we are not placing any check to strictly check whether this is an object or something.
We are going to try this.
If this doesn't work, we are going to remove the required field from the module and then we are going
to just inject it and we'll try this out.
So let's go ahead and copy this and see if this works.
So we're going to say that, hey, inject this into the body raw and this should be JSON.
So let's go ahead and place all of this information and let's try this out.
I'm going to go ahead and send this one and it says, hey, order is success.
But again, I'm shouting, literally shouting this again to you.
This what we have done here is the product.
This is absolutely bad.
This is really, really bad.
It shouldn't be like that.
This is not a reason.
This is just a simple string that we have injected here.
Let's refresh our database and see what we got in the orders.
So this is the order.
Notice here the object ID user is having an object ID, but if I open up this order item, this is an
object.
And notice here the product is.
Thank goodness that it has taken this one as an object idea.
So this is really nice that there are some updation in the mongoose, but still wrong is wrong.
We are having this one when we actually inject it by properly having a place being by request or something
that it goes up.
But this is really nice that it has taken this an object ID really nice and super happy.
There has been some update.
So again, my, my worries are all gone.
So this is all good.
And now I'll give this test order JSON file to you so that you can modify it a little bit later and
can inject that this is going to save you some time.
And there we go, test it out.
In fact, the test is okay as well, that whatever the controller we have designed, this order controller
is working absolutely fine.
Let's move into the next video and see that how we can pass on one single order and just see that how
it works.
Let's go ahead and catch up in the next video.