1 00:00:01,940 --> 00:00:03,710 Let's begin the implementation. 2 00:00:03,710 --> 00:00:09,970 So we're going to first go over inside of our tickets service to our ticket model file inside of here 3 00:00:09,980 --> 00:00:14,290 we're going to add in the idea of a order I.D. being tied to a ticket. 4 00:00:14,620 --> 00:00:16,940 So to get started I'm gonna go down to my schema. 5 00:00:17,330 --> 00:00:22,160 I'm going to say that in addition to these three properties we're also going to have an order I.D. property 6 00:00:22,160 --> 00:00:28,100 as well we're gonna say that this is gonna be a type string again with a capital S right there. 7 00:00:28,340 --> 00:00:33,290 And we are not going to market as being required because when a ticket is first created there is not 8 00:00:33,290 --> 00:00:40,400 going to be any order associated with it will then go back up to our ticket dock interface. 9 00:00:40,440 --> 00:00:44,460 So we need to make sure that typescript understands that a ticket document or an instance of a ticket 10 00:00:44,670 --> 00:00:47,090 has an order I.D. property as well. 11 00:00:47,220 --> 00:00:48,510 It will add in order. 12 00:00:48,510 --> 00:00:52,120 I.D. is going to be a type string. 13 00:00:52,200 --> 00:00:54,220 You don't think we're going to do on this property inside the interface. 14 00:00:54,220 --> 00:00:58,590 We're gonna make sure that we mark this as optional because again when we first create a ticket there 15 00:00:58,590 --> 00:01:01,170 will not be an order I.D. associated with it. 16 00:01:01,740 --> 00:01:05,760 So to make sure that it's clear that this is gonna be an optional property we're gonna put on a question 17 00:01:05,760 --> 00:01:10,920 mark right there and that tells typescript that order I.D. is going to be either a string or possibly 18 00:01:10,980 --> 00:01:15,270 undefined is that is it for our ticket model file. 19 00:01:15,460 --> 00:01:17,530 They'll say this and then go back over to the listener 20 00:01:20,240 --> 00:01:21,540 inside the listener. 21 00:01:21,540 --> 00:01:25,660 Let's write a couple of comments just to guide ourselves on how we're going to put this together. 22 00:01:25,710 --> 00:01:33,780 First we need to reach into our tickets collection and find the ticket that the order is reserving 23 00:01:37,150 --> 00:01:38,940 if we do not find the ticket we should throw in there. 24 00:01:38,950 --> 00:01:45,280 So if no ticket throw air because presumably maybe our events are out of order or something like that 25 00:01:45,520 --> 00:01:49,620 maybe we erroneously said that a ticket was being reserved when the ticket didn't even exist. 26 00:01:49,690 --> 00:01:58,900 Who knows after that we will then mark the ticket as being reserved by setting its order i.e. property 27 00:02:00,590 --> 00:02:04,420 will save the ticket. 28 00:02:04,630 --> 00:02:07,390 And then finally ask the message. 29 00:02:07,390 --> 00:02:11,440 That's it that we know what we're gonna go through here. 30 00:02:11,440 --> 00:02:16,480 Let's start the implementation first off in order to run a query and find some particular ticket inside 31 00:02:16,480 --> 00:02:17,560 of our tickets collection. 32 00:02:17,590 --> 00:02:20,500 Naturally we need our ticket model at the very top. 33 00:02:20,500 --> 00:02:25,390 I will import our ticket model from up three directories or two directories. 34 00:02:25,390 --> 00:02:30,760 My mistake it's inside of our test folder that we need to go up three directories. 35 00:02:30,830 --> 00:02:31,200 There we go. 36 00:02:31,200 --> 00:02:38,020 We'll get our ticket model so we'll go ahead and attempt to find the ticket that this order is mentioning 37 00:02:38,020 --> 00:02:46,880 where the event is mentioning they'll say ticket is a weight ticket find by I.D. data that ticket dot 38 00:02:46,950 --> 00:02:48,910 I.D. That is the ticket that we're trying to reserve. 39 00:02:50,360 --> 00:02:52,290 Well then check to see if a ticket was actually found. 40 00:02:52,290 --> 00:03:00,230 So if there is not a ticket let's just through a plain error and say ticket not found 41 00:03:04,350 --> 00:03:05,970 after that will then set the order. 42 00:03:05,970 --> 00:03:15,410 I.D. property on the ticket itself the ticket sets order I.D. to data dot I.D. That is the idea of the 43 00:03:15,470 --> 00:03:18,510 order that was just created. 44 00:03:18,650 --> 00:03:19,640 Well then say the ticket. 45 00:03:19,640 --> 00:03:23,240 So it's simple a weight ticket that save. 46 00:03:23,320 --> 00:03:24,870 And then finally act the message. 47 00:03:24,970 --> 00:03:26,450 Remember second argument right there. 48 00:03:26,470 --> 00:03:29,970 We will take a look at the message and call act on it. 49 00:03:30,010 --> 00:03:35,570 And that's pretty much it It's I'd say this looks pretty reasonable as usual. 50 00:03:35,570 --> 00:03:39,470 Let's take a pause right here and then write out a couple of tests just to make sure that this thing 51 00:03:39,470 --> 00:03:40,820 is working as expected.