And as far as the lead job is going to be very similar to added job.
The only difference that now, of course, we want to remove that job from the array if the ID is correct.
So let's go to our server.
Now, we won't need the company in position when we're deleting the job.
There's really no need.
Copy and paste.
Let's change the.
Come in here.
The method is not going to be patch.
We'll go with delete your stays the same again.
We'll use the ID over here as our route parameter.
We're not looking for the company so we can remove this logic.
We're still looking for that specific ID because we want to check whether the ID matches anything we
have in the array.
So we'll still have the req.params, we'll grab the ID, we'll look for specific job.
If it doesn't exist, then we'll send back 404, however, if we're successful.
Then we're going to go with new jobs and we'll filter the existing jobs.
And that's why I purposely set up this one as Let because we'll overwrite the value.
So we're going to go here with new jobs and that is equal to the existing jobs array.
Then let's go with filter, then provide the job in our callback function and we'll say if the job ID
does not match whatever we're passing in.
As a route parameter.
Then, of course, keep those jobs.
That's how filter works.
So if the job ID doesn't match, then this is going to be left in the new jobs.
If it does match, then it's going to be removed and then we'll go here with jobs is equal to new jobs.
And when it comes to response, technically you can send back the resource you just removed.
But in this case, there's really no need.
So we can simply provide a message and here we'll say job deleted.
That's it.
Let's navigate to our thunder client.
Again, same deal.
We want to duplicate this one.
And again, the cool thing is that these requests will stay the same.
So we won't have to create new ones for the jobs just because we switched to a database.
So that's the reason why we're actually setting up everything in such a way.
So first, let's start with rename.
I'm going to go with.
The lead job, then the method is not going to be patch.
We'll go with delete.
Again, we have the old technically ID.
It's not going to be valid right now because again, we restarted the server and therefore let me send
one more time.
Get all jobs, grab one of these IDs.
It doesn't really matter which one.
And we want to provide it over here.
So URL forward slash jobs and then the route parameter.
Now, don't need these values over here.
Let's just send it.
And we have job deleted.
Now where can we check that if we send again, get all jobs?
Check it out now.
We have only one.
Now, if you want to check for wrong ID, totally a valid option.
But in my case, I'm just going to skip that.
And with this in place, we have successfully created a Crud functionality where we have some kind of
resource in this case.
Is just a simple array on a server and we have routes which allow us to work with that data so we can
create new jobs, we can access all jobs, we can modify, we can get a single job, we can delete.
And like I keep saying, this is going to be the building block pretty much for all your applications
because everything else you build is effectively going to sit on top of this.
If you're comfortable with this Crud idea where you have the resource on the server and you have the
routes that allow you to work with that resource, you'll be in good shape.