Let's put together an initial implementation of our update request handler inside the roots directory.
I'll make a new file of update to yes that inside of here very top.
Once again we'll get express request response from Express I will definitely be needing the body validator
from Express validator I'm definitely going to need a couple of different Middleware is from our common
library in total I'm going to kind of take a guess here I think we probably need to validate the incoming
request I think we probably need to handle the case in which a ticket is not found sort out that not
found error we probably want to have some kind of authentication restriction around this row handler
so let's get require off we want to entered the case in which a user is trying to edit a ticket that
they do not own So how about not authorized air and I think that's probably good for right now and then
finally after that let's get our ticket model from one directory models ticket
reader router
on that router I'm going to associate a put method to API tickets Olan ideas I'm gonna have an async
root handler I'm going to receive request
and response I'm going to leave that thing empty for just a moment and I'll go down and immediately
export this thing and then wired up to our app I will export router as all about update ticket router
OK I'll save this thing let's go back over to our app dot test file
inside of here towards the top right after all of our other routers I'll get update ticket router
not index but update that's better and we can associate that with our app down here.
So app use update ticket router.
All right.
Lot of wire up but we're done now.
Let's start to put together some implementation on the thing to at least make those first two tests
pass.
So we want to make sure that if we ask for an idea that doesn't exist let's send back a form for we
also want to make sure that if the user is not authenticated we send back a for one.
Well the authentication step is definitely pretty straightforward so for that right before our root
handler we can add in our require auth middleware.
So I'll do require off like so now should definitely work.
We could definitely save this and test right now.
But let's try to implement or put in some implementation for that other one where we return for a four
if he provided I.D. does not exist inside of our tickets collection so for that very select what we
did on the get method just a little bit ago.
Let's try to pull the ticket that the user is looking for out of our tickets collection using our ticket
model so we can do a ticket is a wait ticket dot find by I.D. We'll pass in rec parameters I.D. then
if there is not a ticket let's throw a new not found error.
And then finally just to make sure that all those other tests do not stall and have to wait time out.
Remember that's a five second waiting period by default with just let's just send back some response
right here.
So even if we don't actually do the update at least all those tests will immediately resolve.
So we'll do a rest not sent.
We'll just send back the entire ticket for now and then going to save this file.
Let's go back over to our terminal and see how we're doing.
Looks like those tests are passing.
Very good.
So let's take a quick break here and we'll continue with the remaining tests in just a moment.