Our ticket created publisher is put together.
So we're now going to go over to our roots directory find the new root handler inside of here.
Like we just said right after creating a ticket and saving to the database we then want to publish an
event.
So let's import the publisher into this file and publish an event at the very top.
We're going to import our ticket created publisher from up one directory events publishers ticket created
publisher.
Well then go down towards the bottom and then right after we do that ticket dot save call we will new
ticket created publisher when we called us.
We need to pass in the active Nats clients.
We do not have that inside of our project yet.
So we have not actually established a connection to Nats at any point time inside of here.
But we will do that very shortly.
So for right now I'm going gonna throw in clients and I'm going to assume that I will come back and
fix that up in just a moment.
Well then click Publish and pass in an object so if we take a look at this thing or the air on that
object it will give us a reminder on all the properties we have to provide.
So we need to throw in an idea title price and user I.D..
Now there's a little quick note on this I want to throw out there.
The idea naturally has to be pulled directly off this ticket model.
So we have to do something like ticket dot I.D. but for the other attributes such as title price and
user I.D. you might be a little tempted to emit the title and price directly off the request body and
a user I.D. directly off of wreck current user I.D. because hey it's all the same information right.
In other words you might want to put inside of your just title so pulling the title from the request
body as opposed to referencing the tickets title again you might think these are really the same exact
titles in the title right.
Here is the same as the title on the ticket.
Well not necessarily.
Remember that with Mongoose we can implement some pre and post save hooks.
We can do some validation or sanitization on these values.
So the value that came in off the requests body is not necessarily the same as what actually got saved
to the database.
So I really recommend holding the title or all these relevant attributes directly off of the ticket
that we just saved the database as opposed to pulling the title and price off the request body because
again they might actually be different values so we're gonna put in the title of the ticket or put in
the price also off the ticket I'll put in the user I.D. also off the ticket.
Now this is a a synchronous call right here.
So we kind of have a big decision to make do we want to await this entire operation.
Do you want to wait for the publisher to be completed before we send back a response to the user.
Well that's kind of a interesting question and it's something that we're going to discuss in just a
moment.
But right now let's take a quick pause.
When come back the next video we're gonna discuss how we're going to create this Nats client inside
of our project because as usual it's going to end up being just a little bit more complicated than it
might seem at first glance.
So quick pause right here.
Continue in just a minute.