We've put together both of our publishers.
So now we're going to go back to our new root handler and the delete root handler in both those we had
left ourselves some little comments.
So here's the neuro handler and we left ourselves a comment at the very bottom where we said that we
should publish an event to say that an order was created.
So let's take care of that.
We're gonna start off first inside of our new TSA handler in order to publish an event.
We need both the publisher that we just created and we also need an active Nats client.
You might recall that to manage our Nats client we've got that Nats wrapper TSA file inside of our route
s our see directory so this Nats wrapper class right here we create a singleton out of it at the very
bottom called Nats wrapper.
And this Nats wrapper class is what is going to give us access to an active Nats client.
All right.
So inside of yes.
At the very top we will add in to import statements one for our order created publisher from up one
directory events publishers order created.
There we go.
Publisher and we'll also get our Nats rapper from up one directory.
Nats rapper so we can go ahead and publish that event down where we left that comet so here's a we'll
have to comment right after it.
Will you will create a new publisher.
And remember when we create the publisher we have to feed it.
The Nats client will do a new order created publisher pass in Nats wrapper client and then we will publish
and when we pass in that empty object for right now to publish we can hover over it and it will tell
us the exact properties that we have to provide.
So we have to throw in the I.D. status user I.D. and so on so let's fill it out.
So when we publish this event we're going to pass along some data of the idea and the idea is going
to come from the order that we have created just a moment ago.
That order I.D. then our status will be the orders status.
Next up is our user I.D. which will be the order user I.D. then expires at now.
Remember on this order object right here we are assigning a Date object and the date object is what
is going to eventually be more or less saved to the database.
The Date object doesn't actually technically it's saved into the database but more a mongoose is going
to automatically take that date object and convert it to a string just before it gets saved into Mongo
DB.
But at our code level at basically what we have access to inside of this file that expires that property
is a date object.
Now we are not going to provide a date object for the expires at property instead.
We had said that we were going to provide expires that as a string.
The reason for that is that whatever object we put inside of here is going to be eventually turned into
Jason.
When a Date object gets turned into Jason or essentially a string that Jason code is essentially going
to say hey Date object turn yourself into a string and the date object is going to assume that it should
turn itself into a string representing the current time zone that it is in.
So in other words if we just rely upon the normal behavior and we put in some kind of date object right
here we would end up with a date string or a timestamp that reflects whatever time zone you are living
in.
So for me I'm currently in Mountain Standard Time so it would be some Date Time right here.
Mountain Standard Time and that's not what we want whenever we share timestamps across different services.
We want to communicate them in some kind of a time zone agnostic sort of way.
So ideally we would be providing a UTC timestamp which is going to work regardless of what the time
zone of the service that is receiving this event is in so rather than relying upon this default to string
behavior of the Date object which would end up with some if not time zone that we want we are going
to instead control how this thing gets turned into a string.
So we are going to provide order expires at DOT to ISO string and that's how we do it.
That's how we get a UTC timestamp.
Notice how it's capital ISO in a capital S..
So that's going to return to us the string that's going to give us the date that is contained inside
these expires at object and it's gonna be in a UTC time format or time's up.
Enough that.
So next up we have to provide the status of the order.
So we'll put in status of order.
Oh sorry we already did the status on two lines right above.
We have to do the ticket so for the ticket we have to provide the idea the ticket level the ticket I.D.
and Andy Price as well which really ticket price.
And let's take a pause right here.
When we come back in the next video we're going to go through the same process over inside of our delete
root handler.