We are all done with our expiration service and it is now emitting the expiration complete event so
we're not going to travel back in time.
Go back to the oil service and make sure that we build a listener to listen for this event as soon as
the order service sees expiration completes.
We're going to find the relevant order inside the orders collection and market as canceled.
We might have to do one or two other things related to canceling an order but we'll discuss that in
due time when we cancel the order.
We are probably also going to want to emit an order canceled event from the order service as well but
right now let's just focus on the order service and the listener for expiration comp. Now to build out
this listener we first need to update our common module inside of the order service.
Remember we update our come module just a moment ago and added in the expiration complete event but
we never update the version of that module inside of our order service back at my terminal I'm gonna
change into orders and then update my comfort module
all right.
Very good.
Now go backwards my editor I'm going to find my orders directory I'll find listeners inside there and
we'll add in a brand new listener with the name of you guessed it expiration complete listener got to
yes now we put together several listeners over time but I don't know about you.
I just have a hard time of remembering how to put these things together.
Just remember you can always rely on typescript.
The one thing at a minimum we have to remember we have to import listener from our common module we
can then make our a class of expiration complete listener
that will extend listener and then typescript is gonna take it from there.
We've been over this many times so let's just be through the rest of this implementation.
We need to import our event to provide to the generic type we need to import our Q Group Name subjects.
We've got to get our message type.
We've got to get.
I think that's it.
Actually from listener let's get the subject Seena and the exploration complete event.
We'll get our message type from node Nats streaming
and then what else.
I think that's is that it.
I think I feel like I mentioned one other but whatever will.
The Q Group Name naturally Arrigo from same directory cougar name.
There we go.
OK.
Now on our listener we'll stick in that type expiration complete event throw in the Q Group Name
throw in a subject of subject start expiration complete subject start expiration complete and then finally
on message mark that as a sync receive some data which will be of type expiration complete event at
data and then get our message which is up type message we go there's our listener again it's all the
same stuff between all these different listeners I tried to factor all this code down to be the absolute
minimum and this is pretty much what I came up with we could probably figure out a way to more easily
generalised Q Group name but in general this is pretty darn compact.
Anyways back on topic so we've got this incoming data that describes some order or the attempt to save
it in order should be cancelled the first thing you do is take a look inside of our orders collection
and find the relevant order at the very top let's import our order from up to directories models order
then inside of.
On message we can find our order so we'll do it and await Order Act find by I.D. And remember this event
right here has one single property it has the order ideas property if we ever forget that naturally
we can do a command click on expiration complete even at the top and will tell us OK here's the data
property it has an order I.D. so that is the idea the order that we want to find the inside of find
by I.D. we will reference data what order I.D. then as usual typescript is not sure if this thing is
actually defined or not so we just have to do a quick check make sure that order is defined that there's
not an order let's throw a new error and say order not found
then after that we need to update this thing status well do update the status we're going to need that
order status enum remember we had previously defined that inside of our common module and I was going
to describe all the puzzle statuses is that an order can have.
So we will import order status from our common module
then right after the if statement we'll do an order dot set up not that order dot set there we go.
And I want to change the status to order status that cancelled
now there might be one other thing we should do here as well.
Remember the order is going to contain a reference directly to the ticket that it is reserving.
And so we need to kind of make a decision here and decide whether or not we want to clear out that reference.
So in other words whether we want to say ticket is something like.
No.
Does that make sense or does it not.
Should we keep a reference to the order.
That's something we should probably discuss a little bit.
So let's take a quick pause right here and save this file that's why you're seeing my code jump all
over the place.
We can save this file.
We'll take a quick pause and we're going to decide whether or not it makes sense to reset the ticket
property on this newly cancelled order the quick pause here and we'll continue in just a moment.