1
00:00:00,140 --> 00:00:00,500
All right.

2
00:00:00,500 --> 00:00:09,020
And once we have the model in place, let's navigate to job controller and yes, one by one.

3
00:00:09,140 --> 00:00:16,219
Essentially, we will refactor these controllers and eventually we won't have this local data.

4
00:00:16,370 --> 00:00:22,340
Again, the main point with the local data was to show you the main idea.

5
00:00:22,790 --> 00:00:27,410
We can operate as far as the controllers and requests are concerned.

6
00:00:27,410 --> 00:00:33,380
And then now we want to, of course, connect everything to a database because we want to persist that

7
00:00:33,380 --> 00:00:33,950
value.

8
00:00:33,980 --> 00:00:37,940
We don't want to just start from scratch each and every time.

9
00:00:38,120 --> 00:00:39,680
So this is really up to you.

10
00:00:39,680 --> 00:00:43,580
But for now, I'll just leave these values here with no ID and all that.

11
00:00:43,580 --> 00:00:49,960
And then once we are done refactoring all of the controllers, I'm just going to remove it one by one.

12
00:00:49,970 --> 00:00:50,840
Let's set it up.

13
00:00:50,840 --> 00:00:54,620
We want to start first with importing job.

14
00:00:54,980 --> 00:00:59,330
Basically our job model from the models.

15
00:00:59,360 --> 00:01:01,590
Now in my case, I'm going to call this job.

16
00:01:01,590 --> 00:01:05,010
I'm just going to save a little bit on typing.

17
00:01:05,099 --> 00:01:10,590
And that's why it's important over here to export, since we will use it here in the controllers.

18
00:01:10,710 --> 00:01:13,530
Yep, it's located in the models job model.

19
00:01:13,560 --> 00:01:16,340
But what's missing over here is the JS.

20
00:01:16,350 --> 00:01:20,490
Like I said, as I'm recording, probably I'll forget few times.

21
00:01:20,490 --> 00:01:23,340
Then let's navigate to create job.

22
00:01:23,340 --> 00:01:25,170
Why do we want to work on this one first?

23
00:01:25,200 --> 00:01:29,550
Well, because I want to show you what happens when we create the instance.

24
00:01:30,190 --> 00:01:31,030
Otherwise.

25
00:01:31,030 --> 00:01:35,110
I mean, what jobs are we expecting since we haven't created any.

26
00:01:35,380 --> 00:01:37,480
I'm going to leave company in position because.

27
00:01:37,510 --> 00:01:38,350
Same deal.

28
00:01:38,470 --> 00:01:42,460
So we will send still the same values for now.

29
00:01:42,490 --> 00:01:44,530
So I'm going to go to job recording.

30
00:01:44,530 --> 00:01:50,350
And if you remember when we were creating the job, there was a company as well as the position.

31
00:01:50,350 --> 00:01:52,440
So those are the two things we're sending.

32
00:01:52,450 --> 00:01:53,980
So I'll leave this one.

33
00:01:54,370 --> 00:02:02,650
I will remove this check because eventually there will be a layer, the validation layer, and therefore

34
00:02:02,650 --> 00:02:04,710
I don't think there is any need.

35
00:02:04,720 --> 00:02:09,970
And as far as the status and all that, we can keep it as 201 and Json job.

36
00:02:09,970 --> 00:02:12,940
So eventually there's going to be a job to tell you.

37
00:02:12,940 --> 00:02:17,650
Honestly, as far as the front end, again, we're really not looking for the value that we get back

38
00:02:17,650 --> 00:02:20,470
because when it comes to adding a job, we add the job.

39
00:02:20,470 --> 00:02:22,150
There's going to be a success message.

40
00:02:22,150 --> 00:02:26,230
And essentially, if we want to see all of the jobs, we just navigate to all jobs.

41
00:02:26,230 --> 00:02:28,810
So this is really going to depend on your application.

42
00:02:28,810 --> 00:02:30,470
That's what I'm trying to say.

43
00:02:30,470 --> 00:02:34,070
If you want to send back the exact job, you can definitely do so.

44
00:02:34,190 --> 00:02:37,040
But in our case, technically it is optional.

45
00:02:37,040 --> 00:02:39,880
And up next, let's create our first job.

46
00:02:39,890 --> 00:02:42,590
So essentially we're looking for our model.

47
00:02:43,010 --> 00:02:48,200
In our case, it's a job and it has a method by the name of create.

48
00:02:48,230 --> 00:02:56,090
And in the create method, we pass in the object and we want to provide well which properties we're

49
00:02:56,090 --> 00:02:59,870
going to use in order to create that instance.

50
00:02:59,900 --> 00:03:01,880
Now, in our case, what do we have over here?

51
00:03:01,880 --> 00:03:03,860
We have company and position.

52
00:03:03,860 --> 00:03:10,700
And please keep in mind that when we were creating the job model, we already set some values as default.

53
00:03:10,730 --> 00:03:15,110
Now eventually those values will be provided, but for now.

54
00:03:15,650 --> 00:03:16,610
What's important.

55
00:03:16,610 --> 00:03:23,750
But for now, we can skip the status type and job location because again, there are already some default

56
00:03:23,750 --> 00:03:24,710
values in there.

57
00:03:24,710 --> 00:03:29,450
So in here I'm just going to provide the company value as well as the position.

58
00:03:29,600 --> 00:03:36,140
Now this is a synchronous, so we want to set up a wait in front of it and basically we want to get

59
00:03:36,140 --> 00:03:44,210
back the result and therefore I'm going to go with const job is equal to again await job create and

60
00:03:44,210 --> 00:03:46,100
we provide these two values.

61
00:03:46,640 --> 00:03:51,560
So now let's navigate to create job over here and let's send it.

62
00:03:51,560 --> 00:03:59,000
And if everything is correct, we should be able to see in our dashboard a new job instance and check

63
00:03:59,000 --> 00:03:59,590
it out.

64
00:03:59,600 --> 00:04:02,060
So this is what we're getting back.

65
00:04:02,240 --> 00:04:09,830
Notice So we have company position, then job status, default value pending type, same deal, default

66
00:04:09,830 --> 00:04:10,190
one.

67
00:04:10,190 --> 00:04:13,760
Then we have the ID, so this one gets created by MongoDB.

68
00:04:14,000 --> 00:04:17,570
And also remember I mentioned Createdat and Updatedat.

69
00:04:17,570 --> 00:04:23,720
So those two values are set because we have over here this timestamps.

70
00:04:23,720 --> 00:04:32,510
And if we navigate back to our dashboard and refresh, we should see something pretty, pretty cool.

71
00:04:32,510 --> 00:04:38,540
So notice, like I said, this is going to be our database and since in my case I provided value of

72
00:04:38,540 --> 00:04:41,810
Java file, of course that's the value I see over here.

73
00:04:41,810 --> 00:04:43,700
So this is my database.

74
00:04:43,700 --> 00:04:46,010
And then as far as the collections.

75
00:04:46,750 --> 00:04:48,420
Why it's called jobs.

76
00:04:48,430 --> 00:04:51,910
Well, because over here I went with Mongoose model.

77
00:04:51,910 --> 00:04:54,110
So this creates that collection.

78
00:04:54,130 --> 00:05:00,670
Then we need to come up with a name and essentially it just sets it up in the plural.

79
00:05:00,670 --> 00:05:05,590
So I went with Job and it created jobs and then we just provide schema.

80
00:05:05,590 --> 00:05:08,800
So again, this is going to be structure for our data.

81
00:05:08,800 --> 00:05:12,880
And whenever you see collections, just think table.

82
00:05:12,890 --> 00:05:19,870
So this is where I'll have all of the job values and same deal we can see over here the ID which gets

83
00:05:19,870 --> 00:05:20,260
created.

84
00:05:20,260 --> 00:05:26,230
So we don't need to use the nano ID and then one by one we have all of these properties.

85
00:05:26,260 --> 00:05:31,960
Now one last thing that I want to mention in this video, please keep in mind that when it comes to

86
00:05:31,990 --> 00:05:32,830
MongoDB.

87
00:05:33,960 --> 00:05:40,830
Essentially we can pass here the entire body because I know that it's going to be an object.

88
00:05:40,830 --> 00:05:43,150
And in there I'll have the properties.

89
00:05:43,170 --> 00:05:45,570
So basically I can do something like this.

90
00:05:45,660 --> 00:05:51,050
I can go with rec dot body and we can remove this line of code.

91
00:05:51,060 --> 00:05:56,520
And if you're wondering, well, what is going to happen, if I'll add some extra property that actually

92
00:05:56,520 --> 00:05:58,140
doesn't match my schema?

93
00:05:58,170 --> 00:06:03,260
Well, we'll see that it nicely gets ignored when we're creating the job.

94
00:06:03,270 --> 00:06:10,810
So let's say I'm going to go with some value and I'm going to set it equal to random value.

95
00:06:10,830 --> 00:06:14,670
So once I send again, I'll get back the job.

96
00:06:14,670 --> 00:06:20,390
But notice the property basically is not in my instance.

97
00:06:20,400 --> 00:06:27,050
So essentially we only add the values that are in our schema.

98
00:06:27,060 --> 00:06:33,880
So again, same company, same position, all that, but you don't see anywhere that some value and

99
00:06:33,880 --> 00:06:34,750
random value.

100
00:06:34,780 --> 00:06:41,500
Now, like I keep mentioning, yes, of course, eventually there's going to be a validation layer where

101
00:06:41,500 --> 00:06:45,830
we'll check for exact values and we will discuss this later.

102
00:06:45,850 --> 00:06:48,000
Therefore, we're skipping over it right now.

103
00:06:48,010 --> 00:06:53,590
Just wanted to mention that you can skip the destructuring part if you want to, since there's going

104
00:06:53,590 --> 00:06:59,350
to be a validation layer sitting on top of the controllers anyway.

