1 00:00:01,660 --> 00:00:03,650 Our ticket created publisher is put together. 2 00:00:03,700 --> 00:00:10,750 So we're now going to go over to our roots directory find the new root handler inside of here. 3 00:00:10,930 --> 00:00:15,700 Like we just said right after creating a ticket and saving to the database we then want to publish an 4 00:00:15,700 --> 00:00:16,740 event. 5 00:00:16,740 --> 00:00:21,980 So let's import the publisher into this file and publish an event at the very top. 6 00:00:21,980 --> 00:00:30,840 We're going to import our ticket created publisher from up one directory events publishers ticket created 7 00:00:30,900 --> 00:00:34,760 publisher. 8 00:00:35,020 --> 00:00:43,240 Well then go down towards the bottom and then right after we do that ticket dot save call we will new 9 00:00:43,390 --> 00:00:49,050 ticket created publisher when we called us. 10 00:00:49,060 --> 00:00:51,130 We need to pass in the active Nats clients. 11 00:00:51,130 --> 00:00:53,040 We do not have that inside of our project yet. 12 00:00:53,050 --> 00:00:57,140 So we have not actually established a connection to Nats at any point time inside of here. 13 00:00:57,160 --> 00:00:58,660 But we will do that very shortly. 14 00:00:58,660 --> 00:01:02,770 So for right now I'm going gonna throw in clients and I'm going to assume that I will come back and 15 00:01:02,770 --> 00:01:05,070 fix that up in just a moment. 16 00:01:05,110 --> 00:01:12,620 Well then click Publish and pass in an object so if we take a look at this thing or the air on that 17 00:01:12,620 --> 00:01:15,970 object it will give us a reminder on all the properties we have to provide. 18 00:01:16,100 --> 00:01:19,880 So we need to throw in an idea title price and user I.D.. 19 00:01:20,060 --> 00:01:22,710 Now there's a little quick note on this I want to throw out there. 20 00:01:22,880 --> 00:01:27,090 The idea naturally has to be pulled directly off this ticket model. 21 00:01:27,200 --> 00:01:34,620 So we have to do something like ticket dot I.D. but for the other attributes such as title price and 22 00:01:34,620 --> 00:01:41,780 user I.D. you might be a little tempted to emit the title and price directly off the request body and 23 00:01:41,780 --> 00:01:48,110 a user I.D. directly off of wreck current user I.D. because hey it's all the same information right. 24 00:01:48,120 --> 00:01:52,380 In other words you might want to put inside of your just title so pulling the title from the request 25 00:01:52,380 --> 00:01:59,710 body as opposed to referencing the tickets title again you might think these are really the same exact 26 00:01:59,710 --> 00:02:00,940 titles in the title right. 27 00:02:00,940 --> 00:02:02,960 Here is the same as the title on the ticket. 28 00:02:02,980 --> 00:02:04,180 Well not necessarily. 29 00:02:04,180 --> 00:02:08,740 Remember that with Mongoose we can implement some pre and post save hooks. 30 00:02:08,740 --> 00:02:12,220 We can do some validation or sanitization on these values. 31 00:02:12,220 --> 00:02:18,040 So the value that came in off the requests body is not necessarily the same as what actually got saved 32 00:02:18,040 --> 00:02:19,700 to the database. 33 00:02:19,750 --> 00:02:25,090 So I really recommend holding the title or all these relevant attributes directly off of the ticket 34 00:02:25,090 --> 00:02:30,100 that we just saved the database as opposed to pulling the title and price off the request body because 35 00:02:30,100 --> 00:02:37,460 again they might actually be different values so we're gonna put in the title of the ticket or put in 36 00:02:37,460 --> 00:02:48,050 the price also off the ticket I'll put in the user I.D. also off the ticket. 37 00:02:48,070 --> 00:02:50,590 Now this is a a synchronous call right here. 38 00:02:50,590 --> 00:02:55,300 So we kind of have a big decision to make do we want to await this entire operation. 39 00:02:55,300 --> 00:03:00,280 Do you want to wait for the publisher to be completed before we send back a response to the user. 40 00:03:00,280 --> 00:03:03,280 Well that's kind of a interesting question and it's something that we're going to discuss in just a 41 00:03:03,280 --> 00:03:04,000 moment. 42 00:03:04,000 --> 00:03:05,460 But right now let's take a quick pause. 43 00:03:05,470 --> 00:03:09,250 When come back the next video we're gonna discuss how we're going to create this Nats client inside 44 00:03:09,250 --> 00:03:14,590 of our project because as usual it's going to end up being just a little bit more complicated than it 45 00:03:14,590 --> 00:03:16,300 might seem at first glance. 46 00:03:16,540 --> 00:03:17,920 So quick pause right here. 47 00:03:17,920 --> 00:03:18,790 Continue in just a minute.