1
00:00:00,330 --> 00:00:07,650
And once we're done discussing the validation as well as the need for try and catch, since we have

2
00:00:07,650 --> 00:00:11,640
a synchronous operation, why don't we continue with our controllers?

3
00:00:12,000 --> 00:00:19,440
And up next, I want to work on get all tasks so we know already how we can create a task.

4
00:00:19,830 --> 00:00:22,290
We know that we have a model in the model.

5
00:00:22,290 --> 00:00:23,520
We pass in the schema.

6
00:00:23,760 --> 00:00:27,780
And in order to get things done, we go with the name of the model.

7
00:00:28,050 --> 00:00:31,650
And of course, the method name is DOT Create.

8
00:00:32,040 --> 00:00:34,850
Now, what about the rest of the current operations?

9
00:00:35,280 --> 00:00:41,340
And again, we'll use our best helper, the Mangoush docs, if we navigate there.

10
00:00:41,340 --> 00:00:48,780
And then if we look for queries, then we can have this nice text where it says mouse models provide

11
00:00:48,960 --> 00:00:57,540
several static helper functions for and of this should be already familiar groud gorod operations on

12
00:00:57,540 --> 00:01:00,510
each of these functions or turns a Mangoush query object.

13
00:01:01,170 --> 00:01:06,600
Now we'll work with query object way more in the next project.

14
00:01:06,900 --> 00:01:13,770
But for the time being, we just need to understand that on every model we have these methods that are

15
00:01:13,770 --> 00:01:18,300
wikinews, starting with the lead many all the way to update one.

16
00:01:18,690 --> 00:01:22,680
And the one that we want to use right now is this one, the fine one.

17
00:01:23,010 --> 00:01:28,830
And I'll just open this up in a separate tab and then we can see that as far as the programmer, we

18
00:01:28,830 --> 00:01:31,290
want to pass in the filter object.

19
00:01:31,620 --> 00:01:32,610
Now, what does that mean?

20
00:01:32,640 --> 00:01:39,470
Well, it means that if I leave this filter object empty, this is just going to get me all the documents.

21
00:01:39,960 --> 00:01:43,260
So in our case, this is just going to get us all the tasks.

22
00:01:43,540 --> 00:01:49,320
Now, if we start supplying the values, for example, in our case, we could say completed equal to

23
00:01:49,320 --> 00:01:55,650
true, of course, that is going to get us what that is going to get us only the documents that are

24
00:01:55,650 --> 00:01:56,160
completed.

25
00:01:56,700 --> 00:02:02,430
Again, the way I've set up the project of the next project, the second project is the one where we'll

26
00:02:02,430 --> 00:02:06,870
take a deep dive into the filtering, sorting and all that.

27
00:02:07,110 --> 00:02:07,740
For the time being.

28
00:02:07,740 --> 00:02:12,720
We just need to understand if we want to get all the documents, which is going to be in our case,

29
00:02:13,020 --> 00:02:17,900
for we get all tasks controller, we simply need to use find.

30
00:02:18,330 --> 00:02:26,340
Now, it's also really interesting is the fact that if we go back and if we keep on scrolling, we can

31
00:02:26,340 --> 00:02:32,830
read that a query also has a dot of land function and thus can be used a promise.

32
00:02:33,270 --> 00:02:38,560
Now there is a caveat where technically it's not returning a promise.

33
00:02:38,580 --> 00:02:41,310
That's why I say here used as a promise.

34
00:02:41,550 --> 00:02:46,430
And essentially what that means for us is that, yes, we can use a wait.

35
00:02:46,740 --> 00:02:53,200
So for simplicity, we can stick a weight in front of it and we'll be in good shape.

36
00:02:53,220 --> 00:02:59,520
However, if you keep on scrolling, you'll read that queries are not promises and there are situations

37
00:02:59,640 --> 00:03:00,900
where it's really important.

38
00:03:00,900 --> 00:03:08,370
But if we keep on reading here, they have that then function for async a weight as a convenience.

39
00:03:08,580 --> 00:03:15,930
So long story short, similarly to how we create a task with a weight and we set up try and catch Bluck,

40
00:03:16,170 --> 00:03:17,780
we'll do it here as well.

41
00:03:18,390 --> 00:03:21,770
And the way we'll do that will go with try catch.

42
00:03:22,200 --> 00:03:27,390
So in here, of course, there's going to be an error, but if we're successful, then of course we'll

43
00:03:27,390 --> 00:03:29,580
just send back all the tasks.

44
00:03:29,820 --> 00:03:35,880
So let's start here with Consed and I'll set it equal to the tasks and the value will be equal to our

45
00:03:35,880 --> 00:03:36,240
weight.

46
00:03:36,660 --> 00:03:38,370
So we'll use a weight keyword.

47
00:03:38,550 --> 00:03:40,080
Therefore in front of the function.

48
00:03:40,290 --> 00:03:43,920
I want to set up my async and then I want to go with task.

49
00:03:43,920 --> 00:03:49,380
So that's going to be the name of the model and then the static function is fine.

50
00:03:49,560 --> 00:03:56,760
And since I want to get all the documents in the task collection, therefore I'll just stick here a

51
00:03:56,760 --> 00:03:57,810
empty object.

52
00:03:58,080 --> 00:04:04,020
And then as far as the error, well, in order to speed this up, I'll just copy the error from the

53
00:04:04,020 --> 00:04:07,490
create task and pass it here as well.

54
00:04:07,740 --> 00:04:11,000
And now the only thing is missing is our response.

55
00:04:11,010 --> 00:04:17,690
If we're successful, what do we want to do when we want to go with Red Dot and then we're looking for

56
00:04:17,690 --> 00:04:18,269
the status.

57
00:04:18,570 --> 00:04:22,950
In this case, the status is going to be two hundred and nine, Jason.

58
00:04:23,160 --> 00:04:25,080
And in here I'll just say tasks.

59
00:04:25,380 --> 00:04:29,100
So I'll be sending back the object and then serve an object.

60
00:04:29,100 --> 00:04:30,990
There's a property by the name of tasks.

61
00:04:31,350 --> 00:04:37,800
And as far as the value, it's going to be equal to whatever I'm getting back from the find and I'm

62
00:04:37,800 --> 00:04:44,730
just using the basic shorthand where if the property name is exactly the same as the variable for the

63
00:04:44,730 --> 00:04:52,800
value, while we can meet the second part and effectively it's the same as if I were to write like this.

64
00:04:53,130 --> 00:04:56,640
So we have tasks equal to tasks along with S6.

65
00:04:56,910 --> 00:04:59,480
We can just shorten this up and one.

66
00:04:59,640 --> 00:05:07,790
We save and if we go back to the postman and, you know, let me fix this one, I say here properly,

67
00:05:08,120 --> 00:05:09,560
I'll say testing.

68
00:05:10,540 --> 00:05:17,500
They're starting to ask because I want to save that, create one, so I'll save it here so it stays

69
00:05:17,500 --> 00:05:19,750
as our request and I'll close it.

70
00:05:19,900 --> 00:05:28,060
And then if we go to all the tasks and we simply hit send, now, what we should see is, of course,

71
00:05:28,060 --> 00:05:29,840
our object and check it out.

72
00:05:30,130 --> 00:05:33,670
Now we have all the tasks, so we have our way.

73
00:05:33,880 --> 00:05:37,270
And then inside of that array we have items.

74
00:05:37,510 --> 00:05:41,110
And of course, each item is represented as an object.

75
00:05:41,440 --> 00:05:46,810
So successfully we have set up the second route as well for all the tasks.

76
00:05:47,020 --> 00:05:54,160
And here we use the find static function and we pass in the empty object, which just gets us all the

77
00:05:54,160 --> 00:05:56,170
documents in the collection.

78
00:05:56,330 --> 00:06:02,710
And of course, of course, those are our tasks and not if we're successful, if there was no error,

79
00:06:02,890 --> 00:06:04,720
which is go with resident status.

80
00:06:04,730 --> 00:06:11,950
So we set up the status for our response and we send back a JSON and I just jam all my tasks inside

81
00:06:11,950 --> 00:06:15,370
of the object and set it equal to the tasks property.

