1 00:00:01,820 --> 00:00:07,220 Let's put together an initial implementation of our update request handler inside the roots directory. 2 00:00:07,220 --> 00:00:12,540 I'll make a new file of update to yes that inside of here very top. 3 00:00:12,610 --> 00:00:23,390 Once again we'll get express request response from Express I will definitely be needing the body validator 4 00:00:24,320 --> 00:00:31,340 from Express validator I'm definitely going to need a couple of different Middleware is from our common 5 00:00:31,340 --> 00:00:37,330 library in total I'm going to kind of take a guess here I think we probably need to validate the incoming 6 00:00:37,330 --> 00:00:42,190 request I think we probably need to handle the case in which a ticket is not found sort out that not 7 00:00:42,190 --> 00:00:47,810 found error we probably want to have some kind of authentication restriction around this row handler 8 00:00:47,860 --> 00:00:52,880 so let's get require off we want to entered the case in which a user is trying to edit a ticket that 9 00:00:52,880 --> 00:01:02,110 they do not own So how about not authorized air and I think that's probably good for right now and then 10 00:01:02,110 --> 00:01:07,930 finally after that let's get our ticket model from one directory models ticket 11 00:01:11,760 --> 00:01:12,330 reader router 12 00:01:16,090 --> 00:01:26,530 on that router I'm going to associate a put method to API tickets Olan ideas I'm gonna have an async 13 00:01:26,590 --> 00:01:31,980 root handler I'm going to receive request 14 00:01:35,050 --> 00:01:40,000 and response I'm going to leave that thing empty for just a moment and I'll go down and immediately 15 00:01:40,000 --> 00:01:49,820 export this thing and then wired up to our app I will export router as all about update ticket router 16 00:01:51,450 --> 00:01:55,400 OK I'll save this thing let's go back over to our app dot test file 17 00:01:58,300 --> 00:02:05,210 inside of here towards the top right after all of our other routers I'll get update ticket router 18 00:02:10,070 --> 00:02:15,610 not index but update that's better and we can associate that with our app down here. 19 00:02:15,650 --> 00:02:20,350 So app use update ticket router. 20 00:02:20,410 --> 00:02:21,170 All right. 21 00:02:21,170 --> 00:02:23,530 Lot of wire up but we're done now. 22 00:02:23,570 --> 00:02:28,010 Let's start to put together some implementation on the thing to at least make those first two tests 23 00:02:28,010 --> 00:02:28,760 pass. 24 00:02:28,790 --> 00:02:34,560 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 25 00:02:34,560 --> 00:02:39,430 also want to make sure that if the user is not authenticated we send back a for one. 26 00:02:39,480 --> 00:02:45,240 Well the authentication step is definitely pretty straightforward so for that right before our root 27 00:02:45,240 --> 00:02:49,410 handler we can add in our require auth middleware. 28 00:02:49,470 --> 00:02:55,980 So I'll do require off like so now should definitely work. 29 00:02:56,020 --> 00:02:58,010 We could definitely save this and test right now. 30 00:02:58,030 --> 00:03:02,770 But let's try to implement or put in some implementation for that other one where we return for a four 31 00:03:02,770 --> 00:03:08,970 if he provided I.D. does not exist inside of our tickets collection so for that very select what we 32 00:03:08,970 --> 00:03:11,720 did on the get method just a little bit ago. 33 00:03:12,000 --> 00:03:17,010 Let's try to pull the ticket that the user is looking for out of our tickets collection using our ticket 34 00:03:17,010 --> 00:03:31,320 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 35 00:03:31,350 --> 00:03:40,710 if there is not a ticket let's throw a new not found error. 36 00:03:40,840 --> 00:03:45,500 And then finally just to make sure that all those other tests do not stall and have to wait time out. 37 00:03:45,500 --> 00:03:49,870 Remember that's a five second waiting period by default with just let's just send back some response 38 00:03:49,870 --> 00:03:50,520 right here. 39 00:03:50,530 --> 00:03:55,060 So even if we don't actually do the update at least all those tests will immediately resolve. 40 00:03:55,780 --> 00:03:58,020 So we'll do a rest not sent. 41 00:03:58,060 --> 00:04:02,330 We'll just send back the entire ticket for now and then going to save this file. 42 00:04:02,330 --> 00:04:05,860 Let's go back over to our terminal and see how we're doing. 43 00:04:05,940 --> 00:04:07,390 Looks like those tests are passing. 44 00:04:07,470 --> 00:04:08,090 Very good. 45 00:04:08,530 --> 00:04:14,380 So let's take a quick break here and we'll continue with the remaining tests in just a moment.