Hey there, everyone that they share.
And from the last video, I remember that I haven't got you into this trouble situation for a long while.
So in this video, we're going to deliberately go into some trouble and we'll see that where the problems
are.
So this is going to be a fun situation and you're going to enjoy this one.
The goal of this, this particular video is simply to grab all the orders by the user who is logged
in.
So basically if I'm logged in, I should be able to find all of my orders.
That's pretty much it.
Let's go ahead and break it down to you.
So let's go ahead and make a copy of this one.
Zip it up and expand this one.
There we go.
And this one is get one order and this is get logged in user order.
So we're going to say get logged in orders.
Orders.
There we go.
So this is the basic and we are going to keep this one as it is now.
All we got to do is how we are going to find this.
Previously this was coming up as the requested parameter ID.
So let's evaluate that how this is going to happen.
Let's go ahead and check it out into the base itself.
So this is my order data and I do have a ability to find out who is logged in.
I can just go ahead and say request dot, user dot, underscore ID and do we have any field which can
actually do this?
Yes, we have a field we can actually filter based on the user.
So if my request dot user dot underscore ID matches with this user, I can easily go ahead and select
only those particular user.
We saw that while designing the manager field that we can find anything based on particular these fields.
So let's go ahead and extract that.
So let's go ahead and say that, hey, I want to go ahead and this time not find my ID.
I just want to go ahead and use find method in the fine method.
I have to say that how do you want to find the user?
So I'll pass you a kind of a wade clause in this.
I'm going to go ahead and say, hey user, how you're going to get the user request a dot user, which
is our middleware.
And in that dot underscore ID, that's pretty much it.
Yeah.
Request dot user dot underscore ID.
So let's go ahead.
And we don't need to populate this field, so let's go ahead and remove this one.
And we're going to say if there is no order, please check the order ID, we'll test this out and we're
going to go ahead and send this one.
Okay.
So it looks okay to me now.
Let's go ahead and create a root and let's create some of the problems and issues for our cell.
Let's go ahead and copy this one.
And this one will go up here just like that.
And now we have to simply say that, hey, whoever is logged in, we should actually get that.
So I'm going to go ahead and say, hey, let's go ahead and say simply order, slash my order.
And this field, obviously, he should be logged in and we are going to go ahead and use this one.
Let's go ahead and save this one and test out that order.
Slash my order.
Does it work or not?
Let's go ahead and save this one.
And this one will go into order.
And I'm going to call this one as get my order and save this one.
So what was the root?
It was slash order, slash my order and a simple get request.
And we haven't actually told that how you're going to get.
We don't need to say any ID.
My bad.
Just for thinking ahead of myself again, let's go ahead and say that this is the root again.
There we go.
Slash order.
Slash my order.
Let's go ahead and send this one.
And we are receiving a simple error that says, hey, cost to object ID failed for the value.
And this is a really classic error.
You're going to see this quite a number of times.
Let me break it to you directly now.
What is happening?
The order of the routes actually matters a lot in this case.
We are saying slash order, slash create.
So that is being handled first.
After that, we say it's slash order slash ID.
So no matter what you say after that or how many doubts you declare after that, it's always going to
evaluate this route first.
So after slash order, it always expected that, hey, you are going to give me an ID and it is teetering
my order as an ID as well.
And that's why it's giving a problem.
This is a very common error.
I've seen a lot of beginners actually do this and this is totally okay.
So what you can do this is you can actually say simply, since this is a simple get request, you can
just go ahead and say, hey, this is a route which says simply my order and this is all going to be
all fine.
In fact, you can go ahead and say simply like orders or get order or something like this.
If I just go ahead and say my order, this is going to fix this one.
So, yes, the designing the route itself takes sometimes a little bit of an effort.
So let's go ahead and simply say my order and let's go ahead and send this one.
And now you are getting the users, whoever the user who is logged in, actually getting all the orders
up here.
So pretty nice and easy.
And you have learned one more thing, which is about how to arrange these orders.
So remember, either expect this order ID at the very end.
So whatever the what are the routes you are expecting, the ID plays them at the very end.
So all the above things are evaluated.
But if you are passing up some IDs or something like this, be very cautious on that.
This is a very classic error, happens quite a lot.
Let's go ahead and catch up in the next video.