1
00:00:01,050 --> 00:00:09,480
And once we have set up the controllers for create task and get all tasks next, I want to work on that

2
00:00:09,480 --> 00:00:12,570
task and effectively on our application.

3
00:00:13,230 --> 00:00:16,260
That route provides info about specific task.

4
00:00:16,890 --> 00:00:19,500
Sharon here and see all the tasks.

5
00:00:19,500 --> 00:00:25,560
I can create one, of course, but if I want to edit it, I'm going to click on edit button and then

6
00:00:25,560 --> 00:00:31,980
notice how I'm getting the info about the specific task now, which normally you wouldn't share the

7
00:00:31,980 --> 00:00:34,560
idea, but in this case I just wanted to provide more info.

8
00:00:34,800 --> 00:00:37,020
So not just in name, but also an ID.

9
00:00:37,290 --> 00:00:41,990
So that way you can clearly see that this info is just about this task.

10
00:00:42,270 --> 00:00:49,620
And similarly, I can go to the next one and again, I'll get the ID, I'll get the name and whether

11
00:00:49,620 --> 00:00:50,760
it's completed or not.

12
00:00:51,090 --> 00:00:57,230
Now, in this video, of course, we won't set up the edit, but at least we'll get that specific info.

13
00:00:57,510 --> 00:01:03,260
And General, the setup is going to be pretty similar to the one we have with get all tasks.

14
00:01:03,690 --> 00:01:13,110
However, we'll also have to implement a specific response if the ID that we pass in doesn't match any

15
00:01:13,110 --> 00:01:15,620
of the tasks that we currently have.

16
00:01:16,110 --> 00:01:21,290
And in order to get up and running, never get back to the docks, to the mongoose docs.

17
00:01:21,630 --> 00:01:28,980
And in this case, we're looking for to find one static helper function, just like we used find in

18
00:01:28,980 --> 00:01:35,490
this case, we're looking for find one open up new browser window and then notice as far as the parameters

19
00:01:35,700 --> 00:01:37,440
we go with conditions.

20
00:01:37,860 --> 00:01:39,930
So we pass in conditions object.

21
00:01:40,230 --> 00:01:45,180
And they're very helpful here where they say find one adventure.

22
00:01:45,180 --> 00:01:48,090
Whose country is Krischer otherwise known?

23
00:01:48,510 --> 00:01:51,720
So essentially we use O8 just for convenience.

24
00:01:52,020 --> 00:01:56,940
We have our model, then we have to find one and then we pass in the object.

25
00:01:57,390 --> 00:02:01,950
And in that object we set up what will we set up the commission.

26
00:02:02,400 --> 00:02:04,410
And in this case they look for the country.

27
00:02:04,410 --> 00:02:08,970
In our case, of course, we will look for a task and we'll use the array.

28
00:02:09,690 --> 00:02:16,410
So I'll say get me the task whose ID is equal to whatever I'm getting from the primes.

29
00:02:16,800 --> 00:02:18,470
Otherwise we'll get back now.

30
00:02:18,870 --> 00:02:20,190
So let's now get back.

31
00:02:20,410 --> 00:02:26,390
I'm looking for get to ask and remember in here, of course, I'm getting that Broms idea.

32
00:02:26,910 --> 00:02:31,980
And before we type anything here in the controller, I just want to set it correctly.

33
00:02:32,160 --> 00:02:37,350
My idea, because of course, initially, no, I was just passing here to be here.

34
00:02:37,680 --> 00:02:39,540
But of course, that's not the case anymore.

35
00:02:39,810 --> 00:02:45,330
And since I want to use the ID that I'm getting back from the Mongo, I'm going to go to all the tasks.

36
00:02:45,480 --> 00:02:46,140
I'll run it.

37
00:02:46,570 --> 00:02:47,850
Of course I get my list.

38
00:02:47,860 --> 00:02:48,330
Awesome.

39
00:02:48,630 --> 00:02:50,550
And then pick any of the tasks.

40
00:02:51,050 --> 00:02:52,270
Doesn't really matter which one.

41
00:02:52,290 --> 00:02:57,690
Just look for the ID, copy this one and then go back to the single task.

42
00:02:57,930 --> 00:03:02,520
And then of course, instead of Peter passed in the area and sent.

43
00:03:02,520 --> 00:03:10,560
And if you get back the ID key with this value, with that long string value, which is an idea, then

44
00:03:10,560 --> 00:03:11,670
of course we're in good shape.

45
00:03:11,940 --> 00:03:15,630
And I'm doing this just so we don't have to console log here on a server.

46
00:03:16,050 --> 00:03:17,160
You can definitely do so.

47
00:03:17,160 --> 00:03:23,320
But I just think that it's more convenient for us to see those logs here in Postman.

48
00:03:23,860 --> 00:03:28,800
And then once we have everything in a place, I want to go with my get task.

49
00:03:29,250 --> 00:03:30,890
And here, what's the logic?

50
00:03:31,140 --> 00:03:37,290
Well, we could start by setting up, I think, of course, because we'll use the awide, then we'll

51
00:03:37,290 --> 00:03:41,640
go with our try catch block and then I'll move this sucker up.

52
00:03:41,880 --> 00:03:46,650
And then first we just want to get that ID out of the primes.

53
00:03:46,980 --> 00:03:48,450
So because you can write it the long way.

54
00:03:48,450 --> 00:03:55,980
But I always like to do the structuring first, so I'll go here with const ID and then I always prefer

55
00:03:55,980 --> 00:03:58,230
giving a somewhat useful alias.

56
00:03:58,560 --> 00:04:03,210
Otherwise you just end up with a bunch of ideas and then once in a while is just confusing.

57
00:04:03,210 --> 00:04:05,360
Which idea is for what.

58
00:04:05,580 --> 00:04:12,600
So I'll say grab me the ID, which is coming from the programs but use the areas of task ID from now

59
00:04:12,600 --> 00:04:12,840
on.

60
00:04:13,230 --> 00:04:16,890
And then I set it equal of course to Iraq that primes.

61
00:04:17,459 --> 00:04:19,440
So it's the same object that I'm getting.

62
00:04:19,769 --> 00:04:21,930
And then of course we want to use that find one.

63
00:04:21,930 --> 00:04:22,380
Correct.

64
00:04:23,160 --> 00:04:24,420
So we're going to go with const.

65
00:04:24,810 --> 00:04:30,840
This is going to be our document that we're getting back if we're successful and we'll go with a wait

66
00:04:31,200 --> 00:04:35,040
and then task and then find find one.

67
00:04:35,310 --> 00:04:37,950
And then like I said, we passed in the object.

68
00:04:38,220 --> 00:04:41,130
And in this case I'm going to be looking for underscore ID.

69
00:04:41,580 --> 00:04:46,470
So not the name but on the already which matches to that in the programs.

70
00:04:46,860 --> 00:04:55,560
So we'll use your task and then ID and if I'm successful, beautiful, we'll send back the task.

71
00:04:56,010 --> 00:04:59,700
If not, then we'll have to send back the four of us.

72
00:05:00,260 --> 00:05:07,130
Certainly air will go the rest of that and we're looking for status, so say that everything is correct,

73
00:05:07,340 --> 00:05:13,280
we were successful and therefore we'll go with resident status, three hundred of that adjacent.

74
00:05:13,550 --> 00:05:19,240
And then I just want to pass in a task and say, yep, that's the task you're on for now.

75
00:05:19,250 --> 00:05:25,280
There also might be a case where there's something wrong with an ID where essentially, yes, we're

76
00:05:25,280 --> 00:05:30,110
getting the value from the firearms, but it doesn't match any of the tasks.

77
00:05:30,110 --> 00:05:33,390
And if you remember member of documentation, then we get no.

78
00:05:33,950 --> 00:05:35,200
So what is the case then?

79
00:05:35,390 --> 00:05:39,560
Well, then I want to check if the task actually is now.

80
00:05:39,860 --> 00:05:42,460
And then, of course, I want to send back different response.

81
00:05:42,860 --> 00:05:48,710
Now, make sure, make sure, make sure that you always, always, always set up your return.

82
00:05:49,250 --> 00:05:53,150
Otherwise, what's going to happen while JavaScript is going to be reading the code?

83
00:05:53,390 --> 00:05:59,630
And if you don't have the return, even though there might be no task more, you'll send one response

84
00:05:59,840 --> 00:06:02,060
and then you'll send the next one right after that.

85
00:06:02,330 --> 00:06:04,320
So always, always make sure you return.

86
00:06:04,550 --> 00:06:05,490
So now we're JavaScript.

87
00:06:05,510 --> 00:06:05,810
Now is.

88
00:06:05,880 --> 00:06:11,050
OK, so now I just need to return from the function and here we go with that status.

89
00:06:11,270 --> 00:06:16,580
Now, in this case, though, of course, the task that we're looking for doesn't exist and the status

90
00:06:16,580 --> 00:06:18,490
quo for that is for all four.

91
00:06:18,890 --> 00:06:26,510
And then again, we go on here and pass in the message in the object and the message will be following

92
00:06:26,750 --> 00:06:26,920
on.

93
00:06:26,940 --> 00:06:35,240
So no task with our ID and then Colon and then we'll just look for task and then ID.

94
00:06:36,020 --> 00:06:39,170
And eventually, of course, we also might have the error.

95
00:06:39,560 --> 00:06:46,160
And I'll talk about these two errors in the next video, because that's going to be a common theme that

96
00:06:46,160 --> 00:06:48,020
we'll set up for the upcoming round.

97
00:06:48,350 --> 00:06:51,190
And I kind of want to give it a separate video.

98
00:06:51,620 --> 00:06:52,580
So in here.

99
00:06:53,430 --> 00:07:00,080
Would just grow up and let's just look for that generic one of the that five hundred and then we'll

100
00:07:00,080 --> 00:07:07,190
just pass in the ER copy this one and then scroll down and below where we have the catch, of course,

101
00:07:08,120 --> 00:07:08,300
in.

102
00:07:08,630 --> 00:07:17,450
So if I go back right now to my postman and if I click on send I should get shake and bake because of

103
00:07:17,450 --> 00:07:19,120
course that is the idea.

104
00:07:19,440 --> 00:07:22,460
Now if you don't believe me, we can go back to all the tasks.

105
00:07:22,860 --> 00:07:24,320
Let's keep on scrolling.

106
00:07:24,320 --> 00:07:29,990
And I think I'm going to be looking for this testing schema because some of them are actually empty.

107
00:07:30,590 --> 00:07:33,400
When we were testing out, that's when we were setting them up.

108
00:07:33,620 --> 00:07:39,920
So now grab this idea instead, go back to a single task and then copy and paste.

109
00:07:40,280 --> 00:07:44,320
And of course, now the value is going to be testing schema.

110
00:07:44,600 --> 00:07:50,270
And like I mentioned previously, I'll talk about errors, why we have to have them, essentially why

111
00:07:50,270 --> 00:07:56,990
we have two responses for the errors in the next video, but that's how we can set up a route to get

112
00:07:56,990 --> 00:07:57,980
a single item.

113
00:07:58,430 --> 00:08:05,210
So we go again, we try catch we set up async and then we use the static function, find one.

114
00:08:05,630 --> 00:08:12,380
And then, of course, in this case we're looking for the ID that has the value, the same as in our

115
00:08:12,380 --> 00:08:12,890
programs.

116
00:08:13,310 --> 00:08:18,200
If we can find one awesome, we send back that specific task.

117
00:08:18,590 --> 00:08:25,250
If not, then we send back for a four and then all the way in a large block, we have our generic error.

