In this video we're going to move over to our delete root handler.
Remember that is going to be in charge of cancelling a new order.
We're going to go through the same process over there.
But rather than publishing an order created event we're going to publish an order cancel the events.
So over inside of delete.
Yes.
At the very top we will import our order canceled publisher from up one directory events publishers
order canceled the publisher will then also get our Nats wrapper from up one directory Nats wrapper
do table check your spelling on order canceled right there.
Easy place to make a typo.
Once we got those imports together we'll go down to the comment we had left inside of here we'll create
a new instance of the order canceled.
Publisher and will pass into Nats client which is available through Nats rapper DCS client will then
call publish on the publisher.
And now on this object right here we have provide some information for the event's data.
So we need to give the orders I.T. and the tickets I.D. as well.
Well the orders idea is easy enough.
So the I.T. order dot I.T. will then give the ticket property and there must be an I.D. inside there.
Now this is going to be just a little bit tricky.
If we look at the rest of this route handler you'll notice that we don't actually have a reference to
the ticket that is associated with this order.
And we do not even load it up when we fetch this order from the database.
So we don't really know the idea that ticket to put inside of you right now.
So to fix that up we're going to find where we make a query on the database to get some information
about this order and we're going to make sure that we populate that ticket property so that when we
fetch the order we will also get the associated ticket along with it.
So now if we wanted to we could access order a ticket that would give us the ticket that we are looking
for.
And so in theory we could get the I.D. of that ticket by doing ticket dot I.D.
gate so down inside this object right here.
We'll put in order that ticket that I.D. case that should be it.
Let's say this and now that we've got all this stuff put together we need to take a look at how we're
going to get our tests running around these.
So we should probably have some tests to make sure that we are publishing this event correctly and to
make sure that we're publishing the order created event as well.
Whenever we either create a new order or cancel in order let's start to fix up some tests in the next
video.