1
00:00:00,420 --> 00:00:07,920
All right, and we have successfully arrived at our last controller, the day task one, and if we are

2
00:00:07,920 --> 00:00:14,910
comfortable with getting the single task and setting up the daily task, we should be in good shape

3
00:00:15,240 --> 00:00:20,820
because, yes, there's going to be a bit more functionality, because in this case, not only are we

4
00:00:20,820 --> 00:00:27,480
looking for the I.D., but will also need the body since, of course, we'll be updating something.

5
00:00:27,630 --> 00:00:28,110
Correct.

6
00:00:28,470 --> 00:00:35,600
And then the second thing we have to pass in some options since by default we won't get right away the

7
00:00:35,610 --> 00:00:42,450
validators working and also we won't get the item that we just updated and the worry, of course, I'll

8
00:00:42,450 --> 00:00:44,480
talk about all of that in detail.

9
00:00:44,700 --> 00:00:46,340
So for now, just stay consistent.

10
00:00:46,620 --> 00:00:47,970
I'll move this sucker down.

11
00:00:48,090 --> 00:00:50,280
I'll move it below the delete desk.

12
00:00:50,760 --> 00:00:54,630
And let's just start simply by axing both of those things.

13
00:00:54,990 --> 00:00:58,260
Let's get the programs one and then the body one.

14
00:00:58,500 --> 00:01:03,630
So we just want to see that we are successful on acquiring both of those things.

15
00:01:03,960 --> 00:01:05,850
So I'll set this up as async.

16
00:01:06,740 --> 00:01:13,220
It's just a simple sense, and I'll just remove it and we're going to go try catch and for now, let's

17
00:01:13,220 --> 00:01:20,110
just go arrest that and that status will set it equal to two hundred and nine, the Jackson one.

18
00:01:20,440 --> 00:01:22,490
And here I want to grab two things.

19
00:01:22,730 --> 00:01:30,630
I want to grab my ID, just double check that I'm getting it properly from the Times and also the body.

20
00:01:31,040 --> 00:01:36,920
So for now, above the resident status, let's set up the idea one more time will say ID.

21
00:01:37,190 --> 00:01:45,890
So we're restructuring from the premise that primes and second one is going to be wrecked that body.

22
00:01:46,190 --> 00:01:49,010
And if you want, you can assign it to a data or whatever.

23
00:01:49,280 --> 00:01:54,790
But in my case, I'm just going to set up the property here and set it equal to directly.

24
00:01:55,070 --> 00:02:04,190
So let's just say I.D. is equal to a task ID and then data is going to be equal to wreck dogsbody body

25
00:02:04,460 --> 00:02:04,850
again.

26
00:02:05,090 --> 00:02:06,870
Why are we going to be passing data?

27
00:02:07,100 --> 00:02:10,970
Well, because if we're updating something, of course, you need that new info.

28
00:02:11,240 --> 00:02:11,640
Correct.

29
00:02:11,900 --> 00:02:18,230
So if I go back to my application and if I say that instead of walking the dog, I don't want to walk

30
00:02:18,230 --> 00:02:20,690
the cat, of course I need to supply this name.

31
00:02:20,870 --> 00:02:22,430
Otherwise it's not going to make any sense.

32
00:02:22,670 --> 00:02:24,140
The same goes for completed.

33
00:02:24,410 --> 00:02:30,170
I need to pass in that key with the new value and in this case, of course, is going to be false.

34
00:02:30,470 --> 00:02:33,080
So once I click edit, I'm successful.

35
00:02:33,080 --> 00:02:33,530
Awesome.

36
00:02:33,690 --> 00:02:40,850
So if I go back to all the tasks now, I have to walk the cat and in order to test this out again,

37
00:02:40,850 --> 00:02:44,690
we need to go back to the person that we're looking for, getting all the tasks.

38
00:02:44,690 --> 00:02:51,380
Since I want those correct IDs and you can pick any of them, doesn't really matter.

39
00:02:51,770 --> 00:02:57,110
I think I like the shake and bake the most, so I'll take this one then.

40
00:02:57,110 --> 00:03:05,550
We need to go to patch the update task one copy and paste and then in response we should see the area.

41
00:03:05,900 --> 00:03:06,350
Correct.

42
00:03:06,380 --> 00:03:12,620
We're not going to see the data since we haven't set up anything here in our body, at least not right

43
00:03:12,620 --> 00:03:12,920
now.

44
00:03:13,070 --> 00:03:14,210
But we'll do it in a second.

45
00:03:14,510 --> 00:03:17,420
But of course, now we're just getting update desk.

46
00:03:17,840 --> 00:03:18,670
So let's see.

47
00:03:18,680 --> 00:03:19,760
Let me go back here.

48
00:03:19,760 --> 00:03:20,510
Update task.

49
00:03:20,510 --> 00:03:21,890
Probably I didn't save the file.

50
00:03:22,400 --> 00:03:23,150
My apologies.

51
00:03:23,160 --> 00:03:29,120
Let me run one more time and now I should see the ID that matches, of course, my shake and bake.

52
00:03:29,360 --> 00:03:31,220
But as far as data, there's nothing there.

53
00:03:31,340 --> 00:03:31,950
Why one?

54
00:03:31,970 --> 00:03:35,630
Because I haven't sent anything from my front end.

55
00:03:35,630 --> 00:03:35,990
Right.

56
00:03:36,380 --> 00:03:40,760
So now let's go to the raw and then we'll set it equal to the JSON.

57
00:03:41,810 --> 00:03:49,700
And then we set up our object and remember, we're looking for the name and I'll just say testing added

58
00:03:49,700 --> 00:03:56,150
funk functionality, I guess, and then we're going to be looking for completed and we'll set it equal

59
00:03:56,150 --> 00:03:58,800
to let's just double check in here.

60
00:03:58,820 --> 00:03:59,320
It's true.

61
00:03:59,330 --> 00:04:00,560
So let's go with false.

62
00:04:01,460 --> 00:04:08,690
And Syria, of course, now not only I'm getting the idea just coming from the Proms, but I also have

63
00:04:08,690 --> 00:04:13,580
the data property and in there, of course, I can clearly see those values and the whole deal.

64
00:04:13,580 --> 00:04:18,040
Why I'm doing this is just so we don't have to console lock on a server.

65
00:04:18,470 --> 00:04:25,310
And once we have all of this in place, now let's roll up our sleeves and actually set up our functionality.

66
00:04:25,580 --> 00:04:26,860
So remove this one.

67
00:04:27,020 --> 00:04:28,670
We don't care about this one right now.

68
00:04:29,000 --> 00:04:35,900
And again, we want to go with the task, meaning I'll sign up a variable with the name of task and

69
00:04:35,900 --> 00:04:37,520
I'll set it equal to await.

70
00:04:38,090 --> 00:04:42,650
And of course, now we're looking for task, the model name and then find one.

71
00:04:43,100 --> 00:04:45,740
And if this one was find one undelete.

72
00:04:45,950 --> 00:04:48,140
What do you think is going to be this one?

73
00:04:48,500 --> 00:04:49,130
Well, it is.

74
00:04:49,130 --> 00:04:51,050
Find one and update.

75
00:04:51,470 --> 00:04:53,690
And in here, we need to pass a few things.

76
00:04:53,690 --> 00:04:59,410
First, we need to pass in the object where again, we set up our condition.

77
00:04:59,990 --> 00:05:06,820
So in this case, again, I'm going to go with ID my interest that one in the primes so underscore ID

78
00:05:07,160 --> 00:05:10,460
equal to task ID, that's step number one.

79
00:05:10,850 --> 00:05:15,650
Then of course we need to pass in that new data since we're updating something.

80
00:05:15,650 --> 00:05:16,000
Correct.

81
00:05:16,340 --> 00:05:19,750
So let's go here with comma and that's going to be the second value.

82
00:05:20,030 --> 00:05:24,350
So essentially you need to set up the object and set up which properties you're updating.

83
00:05:24,350 --> 00:05:30,890
But remember we already getting that as far as that body so wrecked, that body is right away, this

84
00:05:30,890 --> 00:05:31,250
object.

85
00:05:31,550 --> 00:05:39,590
So I can simply set up my next primary election where I go with RAGBRAI and then we have options object.

86
00:05:39,890 --> 00:05:46,520
But I first want to show you what happens if we don't use it and then we'll both of the values in there

87
00:05:46,550 --> 00:05:47,150
as well.

88
00:05:47,450 --> 00:05:54,110
So let's start here again by checking the task, because again, we might have a situation where there

89
00:05:54,110 --> 00:05:56,500
is no task with that specific idea.

90
00:05:56,930 --> 00:06:03,230
And again, just to speed this up, a copy and paste and that if we are successful, then of course,

91
00:06:03,230 --> 00:06:05,000
I want to send back the task.

92
00:06:05,300 --> 00:06:07,610
I'll say task is equal to task.

93
00:06:08,000 --> 00:06:10,460
And don't forget of the generic error.

94
00:06:10,820 --> 00:06:17,870
I would go with the result status and then you already know the rest copy and paste and you'll notice

95
00:06:17,870 --> 00:06:18,620
something interesting.

96
00:06:18,770 --> 00:06:22,940
Since we don't have the options, you'll notice the following thing where.

97
00:06:23,780 --> 00:06:27,840
I go with testing at a function, OK, that's awesome.

98
00:06:27,860 --> 00:06:34,090
I completed false, but essentially what we're going to get back is the original value.

99
00:06:34,460 --> 00:06:37,660
So remember the shake and bake effectively.

100
00:06:37,670 --> 00:06:38,730
This is what we'll get back.

101
00:06:38,750 --> 00:06:42,710
So once I send notice, yeah, I get two hundred.

102
00:06:43,190 --> 00:06:44,540
So I was successful.

103
00:06:45,330 --> 00:06:51,480
But notice the value here, the check and back and what's more interesting, that once I click on getting

104
00:06:51,480 --> 00:06:53,590
all the tasks, it's actually changed.

105
00:06:54,360 --> 00:06:55,690
So I was successful.

106
00:06:56,130 --> 00:06:57,160
So here's the gotcha.

107
00:06:57,450 --> 00:07:02,490
The reason why is that happening is because we're not passing the options.

108
00:07:02,620 --> 00:07:05,370
And as far as the options, we want to do two things.

109
00:07:05,550 --> 00:07:09,990
We want to get the new one back because by default, we're getting the old one.

110
00:07:10,180 --> 00:07:11,910
That's why we were successful.

111
00:07:12,330 --> 00:07:16,370
But in our update response, we got the old value.

112
00:07:16,680 --> 00:07:21,830
And the second thing, which you'll notice is the fact that we're not running the validators.

113
00:07:22,140 --> 00:07:25,050
So if you remember when we were setting up the model.

114
00:07:26,140 --> 00:07:30,530
One of the things that I set up for name was required equal to true.

115
00:07:31,030 --> 00:07:38,590
Now, if I try to update item with name equal to an empty string, I'm actually going to be successful.

116
00:07:38,890 --> 00:07:41,620
Now, again, we're getting back the old value.

117
00:07:41,890 --> 00:07:46,150
And in order to check the new one, we just need to get all tasks notice.

118
00:07:46,360 --> 00:07:49,220
And I promise you, I'll say this for the last time in this video.

119
00:07:49,420 --> 00:07:53,290
The reason for that is because we don't have the options object.

120
00:07:53,800 --> 00:07:57,930
And in order to set it up, we just need to go back to all the controllers.

121
00:07:57,940 --> 00:08:05,690
And like I said, third parameter is going to be our options and then we simply go with neutral.

122
00:08:05,950 --> 00:08:12,700
So this will always, always, always return that new item, the one that is already updated.

123
00:08:12,910 --> 00:08:19,460
And then the another property we can run is run validators and we'll set it equal to true.

124
00:08:19,810 --> 00:08:24,020
So once we do that, of course, we fixed both bugs.

125
00:08:24,370 --> 00:08:29,920
So if I for the final time, I guess in this video, go back to my post now.

126
00:08:30,350 --> 00:08:33,940
And here I'm going to go back to Sheik.

127
00:08:34,730 --> 00:08:43,789
And vague and set the value equal to true, we should see that right away so I can see shake and bake

128
00:08:43,789 --> 00:08:51,350
and if I tried to do that without passing anything in the name, then of course I'll get my big fat

129
00:08:51,350 --> 00:08:56,720
error, because when I was setting up the model, I said that name is actually required.

