1
00:00:00,080 --> 00:00:05,090
And as far as the lead job is going to be very similar to added job.

2
00:00:05,120 --> 00:00:12,950
The only difference that now, of course, we want to remove that job from the array if the ID is correct.

3
00:00:12,980 --> 00:00:15,530
So let's go to our server.

4
00:00:15,890 --> 00:00:20,360
Now, we won't need the company in position when we're deleting the job.

5
00:00:20,540 --> 00:00:22,130
There's really no need.

6
00:00:22,310 --> 00:00:23,750
Copy and paste.

7
00:00:24,530 --> 00:00:25,940
Let's change the.

8
00:00:26,840 --> 00:00:27,830
Come in here.

9
00:00:28,160 --> 00:00:30,620
The method is not going to be patch.

10
00:00:30,740 --> 00:00:34,660
We'll go with delete your stays the same again.

11
00:00:34,670 --> 00:00:38,770
We'll use the ID over here as our route parameter.

12
00:00:38,780 --> 00:00:43,130
We're not looking for the company so we can remove this logic.

13
00:00:43,160 --> 00:00:49,640
We're still looking for that specific ID because we want to check whether the ID matches anything we

14
00:00:49,640 --> 00:00:51,140
have in the array.

15
00:00:51,680 --> 00:00:56,810
So we'll still have the req.params, we'll grab the ID, we'll look for specific job.

16
00:00:56,810 --> 00:01:01,880
If it doesn't exist, then we'll send back 404, however, if we're successful.

17
00:01:02,750 --> 00:01:08,560
Then we're going to go with new jobs and we'll filter the existing jobs.

18
00:01:08,570 --> 00:01:14,440
And that's why I purposely set up this one as Let because we'll overwrite the value.

19
00:01:14,450 --> 00:01:20,540
So we're going to go here with new jobs and that is equal to the existing jobs array.

20
00:01:20,570 --> 00:01:28,160
Then let's go with filter, then provide the job in our callback function and we'll say if the job ID

21
00:01:28,310 --> 00:01:31,880
does not match whatever we're passing in.

22
00:01:32,940 --> 00:01:34,650
As a route parameter.

23
00:01:34,680 --> 00:01:36,450
Then, of course, keep those jobs.

24
00:01:36,480 --> 00:01:38,040
That's how filter works.

25
00:01:38,160 --> 00:01:43,190
So if the job ID doesn't match, then this is going to be left in the new jobs.

26
00:01:43,200 --> 00:01:51,270
If it does match, then it's going to be removed and then we'll go here with jobs is equal to new jobs.

27
00:01:51,280 --> 00:01:56,040
And when it comes to response, technically you can send back the resource you just removed.

28
00:01:56,040 --> 00:01:58,400
But in this case, there's really no need.

29
00:01:58,410 --> 00:02:03,840
So we can simply provide a message and here we'll say job deleted.

30
00:02:04,650 --> 00:02:05,400
That's it.

31
00:02:05,430 --> 00:02:08,580
Let's navigate to our thunder client.

32
00:02:08,610 --> 00:02:09,740
Again, same deal.

33
00:02:09,750 --> 00:02:12,120
We want to duplicate this one.

34
00:02:12,920 --> 00:02:17,090
And again, the cool thing is that these requests will stay the same.

35
00:02:17,210 --> 00:02:23,990
So we won't have to create new ones for the jobs just because we switched to a database.

36
00:02:23,990 --> 00:02:28,220
So that's the reason why we're actually setting up everything in such a way.

37
00:02:28,350 --> 00:02:30,260
So first, let's start with rename.

38
00:02:30,410 --> 00:02:31,820
I'm going to go with.

39
00:02:32,450 --> 00:02:36,770
The lead job, then the method is not going to be patch.

40
00:02:37,250 --> 00:02:38,480
We'll go with delete.

41
00:02:38,750 --> 00:02:41,550
Again, we have the old technically ID.

42
00:02:41,810 --> 00:02:47,480
It's not going to be valid right now because again, we restarted the server and therefore let me send

43
00:02:47,480 --> 00:02:48,160
one more time.

44
00:02:48,170 --> 00:02:52,610
Get all jobs, grab one of these IDs.

45
00:02:52,620 --> 00:02:54,470
It doesn't really matter which one.

46
00:02:55,430 --> 00:02:57,170
And we want to provide it over here.

47
00:02:57,170 --> 00:03:01,550
So URL forward slash jobs and then the route parameter.

48
00:03:01,640 --> 00:03:04,130
Now, don't need these values over here.

49
00:03:05,420 --> 00:03:06,350
Let's just send it.

50
00:03:06,350 --> 00:03:08,840
And we have job deleted.

51
00:03:08,960 --> 00:03:12,890
Now where can we check that if we send again, get all jobs?

52
00:03:12,920 --> 00:03:13,970
Check it out now.

53
00:03:13,970 --> 00:03:15,710
We have only one.

54
00:03:15,740 --> 00:03:21,140
Now, if you want to check for wrong ID, totally a valid option.

55
00:03:21,140 --> 00:03:23,330
But in my case, I'm just going to skip that.

56
00:03:23,420 --> 00:03:30,680
And with this in place, we have successfully created a Crud functionality where we have some kind of

57
00:03:30,680 --> 00:03:32,390
resource in this case.

58
00:03:33,060 --> 00:03:43,230
Is just a simple array on a server and we have routes which allow us to work with that data so we can

59
00:03:43,230 --> 00:03:51,240
create new jobs, we can access all jobs, we can modify, we can get a single job, we can delete.

60
00:03:51,240 --> 00:03:58,710
And like I keep saying, this is going to be the building block pretty much for all your applications

61
00:03:58,710 --> 00:04:03,270
because everything else you build is effectively going to sit on top of this.

62
00:04:03,300 --> 00:04:09,000
If you're comfortable with this Crud idea where you have the resource on the server and you have the

63
00:04:09,000 --> 00:04:15,720
routes that allow you to work with that resource, you'll be in good shape.

