1
00:00:00,020 --> 00:00:00,410
All right.

2
00:00:00,410 --> 00:00:06,890
And up next, let's discuss how we can get all jobs from the database, as well as the getting a single

3
00:00:06,890 --> 00:00:08,890
job from database.

4
00:00:08,900 --> 00:00:13,790
And effectively we want to navigate to job controller first.

5
00:00:13,790 --> 00:00:16,550
Let's fix that, create job.

6
00:00:16,550 --> 00:00:19,880
So it's not going to be something actually we'll pass here.

7
00:00:20,590 --> 00:00:25,270
Wreck that body and then when it comes to getting all of the jobs.

8
00:00:25,570 --> 00:00:30,180
Of course, we're not going to use our local array anymore.

9
00:00:30,190 --> 00:00:33,760
So we want to go above our response.

10
00:00:33,760 --> 00:00:38,410
And I'm going to keep the same name since I don't want to change anything here in the response.

11
00:00:38,410 --> 00:00:39,850
So I'm going to go with jobs.

12
00:00:39,850 --> 00:00:41,680
And essentially we're looking for Await.

13
00:00:41,680 --> 00:00:43,680
Again, this is going to be asynchronous.

14
00:00:43,690 --> 00:00:51,430
Then job and notice we get a bunch of methods and the one that we're looking for is the find one.

15
00:00:51,430 --> 00:01:00,910
So this gets all of the instances and here we pass in the filter object and if it's empty, then we

16
00:01:00,910 --> 00:01:02,140
get all the instances.

17
00:01:02,140 --> 00:01:09,100
But if we pass in some values, then of course we will find the instance based on that parameter.

18
00:01:09,130 --> 00:01:15,520
Now, please keep in mind that of course whatever you pass in needs to match what we have in the schema

19
00:01:15,550 --> 00:01:19,420
and we'll cover the basic option in just one second.

20
00:01:19,420 --> 00:01:21,050
So first, let me save it.

21
00:01:21,860 --> 00:01:24,110
Then let me go back to create job.

22
00:01:24,230 --> 00:01:28,040
In between the videos, I created one job for the apple.

23
00:01:28,040 --> 00:01:29,180
So you know what?

24
00:01:29,450 --> 00:01:32,750
Let's do the same thing on Let's create Google.

25
00:01:33,300 --> 00:01:35,420
And in this case, it's going to be a back end.

26
00:01:35,450 --> 00:01:36,290
Let me send.

27
00:01:36,320 --> 00:01:43,610
Yep, we successfully created this job and now if I go to get all jobs, if everything is correct,

28
00:01:43,610 --> 00:01:48,290
I'm going to get back four jobs over here now again.

29
00:01:49,050 --> 00:01:53,710
Little bit later, of course, we'll talk about more complex options.

30
00:01:53,710 --> 00:02:02,140
But for now, if you want to get job based on specific company, for example, Apple or Google, just

31
00:02:02,140 --> 00:02:03,190
type here company.

32
00:02:03,190 --> 00:02:06,340
Just make sure that the property is actually in the schema.

33
00:02:06,700 --> 00:02:09,759
And of course, in my case, I'm going to go here with Apple.

34
00:02:09,759 --> 00:02:12,790
And if everything is correct, check it out.

35
00:02:12,820 --> 00:02:20,650
Now, we have only one instance because there's only one job that matches my search criteria.

36
00:02:20,680 --> 00:02:24,310
Now, this might be a little bit redundant, but I definitely want to showcase that.

37
00:02:24,310 --> 00:02:27,160
Of course, now we're persisting everything in the database.

38
00:02:27,160 --> 00:02:31,060
So what am I talking about over here if I stop the server?

39
00:02:32,340 --> 00:02:34,250
And restart it.

40
00:02:34,590 --> 00:02:37,750
You'll see that we still get back all of the jobs.

41
00:02:37,770 --> 00:02:41,140
So first, let me navigate over here to job controller.

42
00:02:41,160 --> 00:02:42,570
Let me remove.

43
00:02:42,990 --> 00:02:45,510
Let me just send the empty one.

44
00:02:45,690 --> 00:02:49,610
And you'll see that unlike the previous setup with our local data.

45
00:02:49,620 --> 00:02:53,250
Now, of course, since this is persisted in database.

46
00:02:53,990 --> 00:02:56,350
We're always going to have access to it.

47
00:02:56,360 --> 00:02:57,620
Hopefully that is clear.

48
00:02:57,620 --> 00:03:03,590
And now let's go to job controller and let's work on getting a single job.

49
00:03:03,740 --> 00:03:08,180
And totally honestly, most of this functionality is going to stay the same.

50
00:03:08,180 --> 00:03:10,820
So first, let me just remove stuff we're not going to use.

51
00:03:10,820 --> 00:03:13,820
So this was just for demonstration purposes.

52
00:03:13,820 --> 00:03:16,790
So we'll return to the errors in a second.

53
00:03:17,240 --> 00:03:24,860
And also, of course, we're not going to be looking for that single job in our local array, but we'll

54
00:03:24,860 --> 00:03:28,190
still use the ID so this stays the same.

55
00:03:29,360 --> 00:03:29,870
Every time.

56
00:03:29,870 --> 00:03:32,290
We'll want to get the single job.

57
00:03:32,300 --> 00:03:33,830
Yes, we'll have to pass in the ID.

58
00:03:34,070 --> 00:03:39,890
It doesn't matter that the first one was nano ID and the second one is going to be the Mongo one.

59
00:03:39,980 --> 00:03:40,610
No.

60
00:03:41,250 --> 00:03:42,780
That part is irrelevant.

61
00:03:42,810 --> 00:03:45,960
We still want to grab that ID from Req.params.

62
00:03:46,050 --> 00:03:50,820
The difference right now is that we'll create the instance and yes, I'll keep the same name because

63
00:03:50,820 --> 00:03:51,090
why?

64
00:03:51,090 --> 00:03:58,140
We need to retype stuff If we already have that name and we want to go wait again, it's asynchronous.

65
00:03:58,320 --> 00:04:05,850
Again, we go with our instance and the method name is find by ID and you can probably already imagine

66
00:04:05,850 --> 00:04:09,660
that in here we'll just pass in the ID extremely straightforward.

67
00:04:09,660 --> 00:04:14,250
So we take the ID from the parameters we use find by ID.

68
00:04:14,430 --> 00:04:20,910
Now, if we don't get back anything, we'll still get the null and therefore we'll still have this check.

69
00:04:20,910 --> 00:04:23,160
So this doesn't change.

70
00:04:23,280 --> 00:04:26,550
And if everything is correct, then we send back the job.

71
00:04:26,580 --> 00:04:28,340
So let's save it over here.

72
00:04:28,350 --> 00:04:31,710
Let's go to get single job.

73
00:04:32,370 --> 00:04:35,120
And I guess let's start by grabbing all of them.

74
00:04:35,130 --> 00:04:42,270
Now you can pick any job, but I'm just going to be sucker for Apple, I guess, during these videos.

75
00:04:42,360 --> 00:04:45,600
And let's go to getting a single job.

76
00:04:46,180 --> 00:04:47,140
Pass over here.

77
00:04:47,140 --> 00:04:52,880
And like I said, if everything is correct, we'll nicely get back the single job.

78
00:04:52,900 --> 00:04:57,460
Now, if the job doesn't exist, you know, let's log it.

79
00:04:57,490 --> 00:05:01,660
Just so you don't think that I'm messing with you, I'm going to go with log and job.

80
00:05:02,260 --> 00:05:06,430
Let's save it here and then change the last character.

81
00:05:06,430 --> 00:05:08,440
So don't remove any characters.

82
00:05:08,440 --> 00:05:12,400
Don't add any characters and we'll handle that.

83
00:05:12,430 --> 00:05:13,810
Gotcha a little bit later.

84
00:05:13,810 --> 00:05:15,910
So don't worry about it right now.

85
00:05:16,490 --> 00:05:23,210
Just change the last character and if we send notice, we nicely get back this 404.

86
00:05:23,240 --> 00:05:25,360
And like I said, the value is going to be null.

87
00:05:25,370 --> 00:05:31,040
So if the job based on that ID does not exist in the database.

88
00:05:31,340 --> 00:05:31,910
Yep.

89
00:05:31,940 --> 00:05:33,500
We'll get back the error.

90
00:05:33,500 --> 00:05:39,320
So let me go back to the previous one and we should see the job.

91
00:05:39,380 --> 00:05:47,390
And with this in place, we are done with getting all the jobs as well as getting a single job.

92
00:05:47,480 --> 00:05:51,230
And up next, we can work on update job and delete job.

