In this video, we are going to create a controller to find details about a user.
So let's get back to the controllers and users.
And here we go.
We are done the profile for now.
So let's work with the user details.
The logic is going to be the same, but for this one is going to be public, meaning that any user can
have access to view this user details, for example, the name and the full name.
But if you want to take an action, for example, if we want to update the profile of this particular
user, we cannot.
And for this one, we are protecting it.
So let's see how we can have access to that.
So inside here we have access of the ID of the user and that red dot params.
So if I console dot log the rec dot params, let's see what we have.
Let's get back to the tender client and for the details when I hit send, let's look at the terminal.
And we have the ID, which is a27, which matches this one.
And we have a property called ID and that is what we specified inside the root.
So let's get back to the root users and then let's locate the details controller, which is down here,
and that is this.
So if I change this one to let's say something, I'm going to have it as something and then the ID,
So let's make the request and let's check the terminal.
And you can see we have something, but ideally we use what is called ID.
So let me bring it back as ID.
So inside here we have access of the ID inside the param.
So here as gets user ID from params, so going to be as const, then the user id is equal to the rec.
Dot params.
Darts ID so now I can go ahead and find the user.
I'm going to be as cost user is equal to await the user model.
Dot find by ID and that is the user ID.
So let's send the response as data and then the user.
So let's make the request and let's see the error that we are going to get.
And we can see we have what is called cost error, meaning that the ID we passed in here is not valid
MongoDB ID, so let's provide the right ID of the user that I want to find more details about that so
I can go back to one database and inside the user.
For now we have only one user and that is John.
So let me copy the ID and inside the request here, let me change this one to the write ID and let's
hit send.
And now we have the same response.
All right.
So the next video, let's see how a user can update the details.
For example, if the user want to update full name or email or password, let's see how we are going
to implement that.