1
00:00:00,240 --> 00:00:06,870
In this video, we are going to create a controller to find details about a user.

2
00:00:06,900 --> 00:00:10,920
So let's get back to the controllers and users.

3
00:00:10,920 --> 00:00:12,540
And here we go.

4
00:00:12,570 --> 00:00:15,180
We are done the profile for now.

5
00:00:15,180 --> 00:00:17,440
So let's work with the user details.

6
00:00:17,460 --> 00:00:25,440
The logic is going to be the same, but for this one is going to be public, meaning that any user can

7
00:00:25,440 --> 00:00:31,030
have access to view this user details, for example, the name and the full name.

8
00:00:31,050 --> 00:00:37,440
But if you want to take an action, for example, if we want to update the profile of this particular

9
00:00:37,440 --> 00:00:38,970
user, we cannot.

10
00:00:38,970 --> 00:00:41,750
And for this one, we are protecting it.

11
00:00:41,760 --> 00:00:44,180
So let's see how we can have access to that.

12
00:00:44,190 --> 00:00:50,640
So inside here we have access of the ID of the user and that red dot params.

13
00:00:50,640 --> 00:00:59,400
So if I console dot log the rec dot params, let's see what we have.

14
00:00:59,430 --> 00:01:06,510
Let's get back to the tender client and for the details when I hit send, let's look at the terminal.

15
00:01:07,500 --> 00:01:13,500
And we have the ID, which is a27, which matches this one.

16
00:01:13,500 --> 00:01:19,520
And we have a property called ID and that is what we specified inside the root.

17
00:01:19,530 --> 00:01:27,630
So let's get back to the root users and then let's locate the details controller, which is down here,

18
00:01:27,630 --> 00:01:28,980
and that is this.

19
00:01:28,980 --> 00:01:35,820
So if I change this one to let's say something, I'm going to have it as something and then the ID,

20
00:01:35,850 --> 00:01:40,350
So let's make the request and let's check the terminal.

21
00:01:41,850 --> 00:01:47,250
And you can see we have something, but ideally we use what is called ID.

22
00:01:47,280 --> 00:01:49,990
So let me bring it back as ID.

23
00:01:50,010 --> 00:01:54,930
So inside here we have access of the ID inside the param.

24
00:01:54,930 --> 00:02:07,740
So here as gets user ID from params, so going to be as const, then the user id is equal to the rec.

25
00:02:09,550 --> 00:02:11,050
Dot params.

26
00:02:12,860 --> 00:02:18,080
Darts ID so now I can go ahead and find the user.

27
00:02:20,160 --> 00:02:26,490
I'm going to be as cost user is equal to await the user model.

28
00:02:29,650 --> 00:02:33,970
Dot find by ID and that is the user ID.

29
00:02:34,000 --> 00:02:41,440
So let's send the response as data and then the user.

30
00:02:41,770 --> 00:02:46,630
So let's make the request and let's see the error that we are going to get.

31
00:02:46,930 --> 00:02:54,580
And we can see we have what is called cost error, meaning that the ID we passed in here is not valid

32
00:02:54,580 --> 00:03:03,790
MongoDB ID, so let's provide the right ID of the user that I want to find more details about that so

33
00:03:03,790 --> 00:03:08,030
I can go back to one database and inside the user.

34
00:03:08,200 --> 00:03:11,620
For now we have only one user and that is John.

35
00:03:11,620 --> 00:03:20,200
So let me copy the ID and inside the request here, let me change this one to the write ID and let's

36
00:03:20,200 --> 00:03:21,040
hit send.

37
00:03:22,080 --> 00:03:25,320
And now we have the same response.

38
00:03:25,620 --> 00:03:26,130
All right.

39
00:03:26,130 --> 00:03:31,140
So the next video, let's see how a user can update the details.

40
00:03:31,140 --> 00:03:37,650
For example, if the user want to update full name or email or password, let's see how we are going

41
00:03:37,650 --> 00:03:38,760
to implement that.

