1
00:00:00,240 --> 00:00:00,730
Beautiful.

2
00:00:01,230 --> 00:00:07,510
We have set up our first scheme, as well as the model, and of course, we want to start using it.

3
00:00:07,890 --> 00:00:12,690
And yes, we will use it in a comptrollers, therefore, we'll navigate there.

4
00:00:12,960 --> 00:00:17,310
And I'm going to be looking for my model and I'll sign it to the task variable.

5
00:00:17,680 --> 00:00:24,570
I'll say I require I'm looking in the models folder and then more specifically, task online.

6
00:00:24,570 --> 00:00:31,120
Before we continue, let me just give you a brief overview of what we're about to do.

7
00:00:31,500 --> 00:00:38,100
So if we navigate back to Mongu stocks and more specifically, if you're looking for the models, we

8
00:00:38,100 --> 00:00:44,100
can find here more info and see that models are fancy constructor's compiled from Kievan Definition's,

9
00:00:44,460 --> 00:00:49,260
an instance of a model is called a document.

10
00:00:49,770 --> 00:00:51,510
And they give you this example.

11
00:00:51,870 --> 00:00:57,240
Pretty much everything that we did in the last video, apart from the fact that, of course, they have

12
00:00:57,240 --> 00:00:57,980
different values.

13
00:00:58,350 --> 00:01:02,940
And here we have nice explanation that the first argument is singular.

14
00:01:02,950 --> 00:01:06,000
Name of the collection your model is for.

15
00:01:06,330 --> 00:01:13,490
Since Mongo's automatically looks for the plural lowercase version of your model name.

16
00:01:13,980 --> 00:01:17,550
So effectively, eventually we'll have the tasks.

17
00:01:18,060 --> 00:01:24,570
When I mentioned one more time that the instance of the model is called document and are few ways how

18
00:01:24,570 --> 00:01:34,020
we can create one, we can go this route or we can use DOT create and here they showcase the callback

19
00:01:34,020 --> 00:01:34,740
function approach.

20
00:01:35,100 --> 00:01:42,360
But we can also use a wait and essentially what create is looking for while it's looking for the object

21
00:01:42,690 --> 00:01:44,050
with those properties.

22
00:01:44,280 --> 00:01:47,940
So now we have a name as well as the completed.

23
00:01:48,210 --> 00:01:48,650
Correct.

24
00:01:48,780 --> 00:01:51,480
And of course we can pass this manually.

25
00:01:51,900 --> 00:01:56,070
But wouldn't that make more sense if we just go to create TaskRabbit?

26
00:01:56,580 --> 00:02:03,240
And since we know that in there we can access the task data in request, not body, why don't we just

27
00:02:03,240 --> 00:02:09,780
pipe it through and pass it along to our model create method and it's going to work something like this

28
00:02:10,259 --> 00:02:16,710
where I'll grab the body because this is going to be coming from my postman here, shake and bake and

29
00:02:16,750 --> 00:02:17,700
valuable Lytro.

30
00:02:18,000 --> 00:02:24,600
And then instead of sending it back, we'll pass it into TASC Dot Create.

31
00:02:24,810 --> 00:02:31,590
Now since I'm going to be using a weight on a task that create course, I want to refactor this and

32
00:02:31,590 --> 00:02:36,630
I'll say that this function, the create task actually is going to be async.

33
00:02:36,900 --> 00:02:43,650
So my controller will be async and then instead of the function body, I'm going to go with task and

34
00:02:43,650 --> 00:02:45,090
I'll set it equal to await.

35
00:02:45,210 --> 00:02:48,210
Like I said, I'm not going to use the callback function approach.

36
00:02:48,210 --> 00:02:53,400
I'll use a wait instead and we'll wait for task dath create.

37
00:02:53,400 --> 00:03:00,990
And like I said, if you want you can hard code this year you can say name and then first task and of

38
00:03:00,990 --> 00:03:03,300
course we can do the same thing for completed.

39
00:03:03,810 --> 00:03:10,020
But I already covered why it's going to make way more sense if we just take this or that body.

40
00:03:10,110 --> 00:03:17,250
So whatever we're getting from the postman and then let's just pass that object into task that create

41
00:03:17,400 --> 00:03:18,510
and let's see what happens.

42
00:03:18,900 --> 00:03:25,560
So our moment here and I'll just say wreck that body over here.

43
00:03:25,830 --> 00:03:29,940
And as far as the response, well, now I'm just waiting for a task.

44
00:03:30,210 --> 00:03:34,650
So instead of that body in response, I'll place my task.

45
00:03:34,800 --> 00:03:36,690
And I also want to add status.

46
00:03:37,080 --> 00:03:41,790
And if you remember, the correct status was to hundred one effectively.

47
00:03:41,790 --> 00:03:49,980
That is, if you have a successful post request and then instead of JSON, being equal to that body

48
00:03:50,340 --> 00:03:54,750
will pass in the object and in here will pass in our task.

49
00:03:55,110 --> 00:04:00,090
And then once we save again, nothing happens because we haven't triggered the post request.

50
00:04:00,450 --> 00:04:09,960
But if we go back to the postman, if I click here, send what I should see is this.

51
00:04:10,290 --> 00:04:11,630
I should see the task.

52
00:04:11,640 --> 00:04:12,840
So that's my object.

53
00:04:12,990 --> 00:04:14,040
And now check it out.

54
00:04:14,370 --> 00:04:17,930
We have this underscore idy and what that means.

55
00:04:17,940 --> 00:04:22,620
Well, that means that we created a new document with the following properties.

56
00:04:22,980 --> 00:04:25,470
We have a name we have completed.

57
00:04:25,830 --> 00:04:31,940
We of course have the array, like I just mentioned, and we also have this underscore underscore the

58
00:04:32,220 --> 00:04:39,660
so of course these two are created by default every time we create the document and that of these ones

59
00:04:39,660 --> 00:04:40,450
we provide.

60
00:04:40,860 --> 00:04:49,020
So if you want to keep on testing, we're going to go with second task and we'll set maybe the completed

61
00:04:49,020 --> 00:04:49,580
to force.

62
00:04:49,740 --> 00:04:51,390
Again, this is all quick and dirty.

63
00:04:51,630 --> 00:04:55,830
Just because I want to have some data in my database.

64
00:04:56,070 --> 00:04:59,600
There will be still some modifications to the code, but.

65
00:04:59,870 --> 00:05:07,160
If we can see these successful responses where we have tasks with underscore what that also means,

66
00:05:07,160 --> 00:05:14,720
my friends, is that when we go to our database and if fire refresh, check it out.

67
00:05:14,990 --> 00:05:17,240
Now, of course, I have the task manager.

68
00:05:17,740 --> 00:05:19,700
I said that's my database.

69
00:05:20,060 --> 00:05:24,080
And what are you know, of course, I have the task collection now.

70
00:05:24,080 --> 00:05:24,740
What do I have?

71
00:05:24,740 --> 00:05:25,760
An enormous collection.

72
00:05:25,940 --> 00:05:27,020
I have documents.

73
00:05:27,290 --> 00:05:31,430
What documents shake and bake and second task.

74
00:05:31,730 --> 00:05:33,310
And you have the same result.

75
00:05:33,560 --> 00:05:34,220
Congrats.

76
00:05:34,370 --> 00:05:36,020
We're off to the great start.

