1 00:00:01,030 --> 00:00:03,050 We've put together both of our publishers. 2 00:00:03,050 --> 00:00:08,290 So now we're going to go back to our new root handler and the delete root handler in both those we had 3 00:00:08,290 --> 00:00:10,270 left ourselves some little comments. 4 00:00:10,270 --> 00:00:14,590 So here's the neuro handler and we left ourselves a comment at the very bottom where we said that we 5 00:00:14,590 --> 00:00:17,570 should publish an event to say that an order was created. 6 00:00:17,620 --> 00:00:19,380 So let's take care of that. 7 00:00:19,420 --> 00:00:23,950 We're gonna start off first inside of our new TSA handler in order to publish an event. 8 00:00:24,070 --> 00:00:29,190 We need both the publisher that we just created and we also need an active Nats client. 9 00:00:29,380 --> 00:00:34,810 You might recall that to manage our Nats client we've got that Nats wrapper TSA file inside of our route 10 00:00:34,830 --> 00:00:41,100 s our see directory so this Nats wrapper class right here we create a singleton out of it at the very 11 00:00:41,100 --> 00:00:42,750 bottom called Nats wrapper. 12 00:00:42,900 --> 00:00:48,680 And this Nats wrapper class is what is going to give us access to an active Nats client. 13 00:00:48,720 --> 00:00:49,230 All right. 14 00:00:49,290 --> 00:00:50,640 So inside of yes. 15 00:00:50,820 --> 00:01:00,660 At the very top we will add in to import statements one for our order created publisher from up one 16 00:01:00,660 --> 00:01:06,260 directory events publishers order created. 17 00:01:06,270 --> 00:01:06,630 There we go. 18 00:01:06,630 --> 00:01:14,130 Publisher and we'll also get our Nats rapper from up one directory. 19 00:01:14,140 --> 00:01:23,450 Nats rapper so we can go ahead and publish that event down where we left that comet so here's a we'll 20 00:01:23,450 --> 00:01:26,260 have to comment right after it. 21 00:01:26,270 --> 00:01:28,200 Will you will create a new publisher. 22 00:01:28,250 --> 00:01:30,530 And remember when we create the publisher we have to feed it. 23 00:01:30,540 --> 00:01:41,870 The Nats client will do a new order created publisher pass in Nats wrapper client and then we will publish 24 00:01:44,450 --> 00:01:48,410 and when we pass in that empty object for right now to publish we can hover over it and it will tell 25 00:01:48,410 --> 00:01:51,040 us the exact properties that we have to provide. 26 00:01:51,050 --> 00:01:55,990 So we have to throw in the I.D. status user I.D. and so on so let's fill it out. 27 00:01:56,990 --> 00:02:01,310 So when we publish this event we're going to pass along some data of the idea and the idea is going 28 00:02:01,310 --> 00:02:03,870 to come from the order that we have created just a moment ago. 29 00:02:03,960 --> 00:02:12,300 That order I.D. then our status will be the orders status. 30 00:02:12,300 --> 00:02:22,350 Next up is our user I.D. which will be the order user I.D. then expires at now. 31 00:02:22,380 --> 00:02:27,620 Remember on this order object right here we are assigning a Date object and the date object is what 32 00:02:27,650 --> 00:02:30,530 is going to eventually be more or less saved to the database. 33 00:02:30,530 --> 00:02:35,030 The Date object doesn't actually technically it's saved into the database but more a mongoose is going 34 00:02:35,030 --> 00:02:39,680 to automatically take that date object and convert it to a string just before it gets saved into Mongo 35 00:02:39,680 --> 00:02:40,220 DB. 36 00:02:40,830 --> 00:02:46,100 But at our code level at basically what we have access to inside of this file that expires that property 37 00:02:46,280 --> 00:02:48,250 is a date object. 38 00:02:48,260 --> 00:02:52,960 Now we are not going to provide a date object for the expires at property instead. 39 00:02:52,970 --> 00:02:56,330 We had said that we were going to provide expires that as a string. 40 00:02:56,330 --> 00:03:00,440 The reason for that is that whatever object we put inside of here is going to be eventually turned into 41 00:03:00,440 --> 00:03:01,350 Jason. 42 00:03:01,490 --> 00:03:07,580 When a Date object gets turned into Jason or essentially a string that Jason code is essentially going 43 00:03:07,580 --> 00:03:13,190 to say hey Date object turn yourself into a string and the date object is going to assume that it should 44 00:03:13,190 --> 00:03:17,730 turn itself into a string representing the current time zone that it is in. 45 00:03:17,750 --> 00:03:23,000 So in other words if we just rely upon the normal behavior and we put in some kind of date object right 46 00:03:23,000 --> 00:03:29,540 here we would end up with a date string or a timestamp that reflects whatever time zone you are living 47 00:03:29,540 --> 00:03:30,110 in. 48 00:03:30,110 --> 00:03:35,200 So for me I'm currently in Mountain Standard Time so it would be some Date Time right here. 49 00:03:35,210 --> 00:03:40,840 Mountain Standard Time and that's not what we want whenever we share timestamps across different services. 50 00:03:40,880 --> 00:03:44,810 We want to communicate them in some kind of a time zone agnostic sort of way. 51 00:03:45,230 --> 00:03:51,650 So ideally we would be providing a UTC timestamp which is going to work regardless of what the time 52 00:03:51,650 --> 00:03:58,260 zone of the service that is receiving this event is in so rather than relying upon this default to string 53 00:03:58,260 --> 00:04:03,420 behavior of the Date object which would end up with some if not time zone that we want we are going 54 00:04:03,420 --> 00:04:06,000 to instead control how this thing gets turned into a string. 55 00:04:06,030 --> 00:04:15,430 So we are going to provide order expires at DOT to ISO string and that's how we do it. 56 00:04:15,460 --> 00:04:18,050 That's how we get a UTC timestamp. 57 00:04:18,190 --> 00:04:21,250 Notice how it's capital ISO in a capital S.. 58 00:04:21,410 --> 00:04:25,690 So that's going to return to us the string that's going to give us the date that is contained inside 59 00:04:25,690 --> 00:04:33,940 these expires at object and it's gonna be in a UTC time format or time's up. 60 00:04:33,980 --> 00:04:35,390 Enough that. 61 00:04:35,430 --> 00:04:38,050 So next up we have to provide the status of the order. 62 00:04:38,160 --> 00:04:40,160 So we'll put in status of order. 63 00:04:40,170 --> 00:04:43,340 Oh sorry we already did the status on two lines right above. 64 00:04:43,530 --> 00:04:50,360 We have to do the ticket so for the ticket we have to provide the idea the ticket level the ticket I.D. 65 00:04:51,320 --> 00:04:54,790 and Andy Price as well which really ticket price. 66 00:04:54,890 --> 00:04:57,030 And let's take a pause right here. 67 00:04:57,050 --> 00:05:01,340 When we come back in the next video we're going to go through the same process over inside of our delete 68 00:05:01,340 --> 00:05:02,000 root handler.