Let's begin the implementation.
So we're going to first go over inside of our tickets service to our ticket model file inside of here
we're going to add in the idea of a order I.D. being tied to a ticket.
So to get started I'm gonna go down to my schema.
I'm going to say that in addition to these three properties we're also going to have an order I.D. property
as well we're gonna say that this is gonna be a type string again with a capital S right there.
And we are not going to market as being required because when a ticket is first created there is not
going to be any order associated with it will then go back up to our ticket dock interface.
So we need to make sure that typescript understands that a ticket document or an instance of a ticket
has an order I.D. property as well.
It will add in order.
I.D. is going to be a type string.
You don't think we're going to do on this property inside the interface.
We're gonna make sure that we mark this as optional because again when we first create a ticket there
will not be an order I.D. associated with it.
So to make sure that it's clear that this is gonna be an optional property we're gonna put on a question
mark right there and that tells typescript that order I.D. is going to be either a string or possibly
undefined is that is it for our ticket model file.
They'll say this and then go back over to the listener
inside the listener.
Let's write a couple of comments just to guide ourselves on how we're going to put this together.
First we need to reach into our tickets collection and find the ticket that the order is reserving
if we do not find the ticket we should throw in there.
So if no ticket throw air because presumably maybe our events are out of order or something like that
maybe we erroneously said that a ticket was being reserved when the ticket didn't even exist.
Who knows after that we will then mark the ticket as being reserved by setting its order i.e. property
will save the ticket.
And then finally ask the message.
That's it that we know what we're gonna go through here.
Let's start the implementation first off in order to run a query and find some particular ticket inside
of our tickets collection.
Naturally we need our ticket model at the very top.
I will import our ticket model from up three directories or two directories.
My mistake it's inside of our test folder that we need to go up three directories.
There we go.
We'll get our ticket model so we'll go ahead and attempt to find the ticket that this order is mentioning
where the event is mentioning they'll say ticket is a weight ticket find by I.D. data that ticket dot
I.D. That is the ticket that we're trying to reserve.
Well then check to see if a ticket was actually found.
So if there is not a ticket let's just through a plain error and say ticket not found
after that will then set the order.
I.D. property on the ticket itself the ticket sets order I.D. to data dot I.D. That is the idea of the
order that was just created.
Well then say the ticket.
So it's simple a weight ticket that save.
And then finally act the message.
Remember second argument right there.
We will take a look at the message and call act on it.
And that's pretty much it It's I'd say this looks pretty reasonable as usual.
Let's take a pause right here and then write out a couple of tests just to make sure that this thing
is working as expected.