All right my friends let's build a listener that's going to listen for the order created event.
Whenever we see this all we have to do is build up a new order and save it.
So will be pretty straightforward.
Let's go and get to it right away instead of my payment service off on the SRT directory.
Inside there I'll make a new folder called events and then inside there I'll make another new folder
called listeners.
Now you might recall every time we made a listener we need a cue group name.
And we've been defining that Q Group Name inside of a separate file inside the listeners directory.
Let's do that right now since we know that we're going to need it very shortly anyways.
The first filing in a crate inside the listeners is Q Group name dot t T.S. the inside of here we will
export a concept of Q Group name and we'll sign that B string of payments service
then inside of listeners will make a new file of order created listener not t s inside of here we're
gonna make yet another listener we've been this process so many times let's just go through it really
quickly at the top we will get our listener base class the order created events and these subjects in
them from our common module I will also get Q Group name from the file we just created of Q Group Name
will then make a class of order created listener that's going to extend our listener base class and
we'll feed in the order created even we can then define our subject as subjects start order created
and that should be a colon right there and then the actual value for this will be subjects that order
created our Q Group Name is Q Group name and then finally on message
Let's mark this thing as async it's going to receive that data argument that is of type order a created
event specifically the data property and then our message which is a type message and I neglected to
import message at the top of the file so we'll do that right away we'll get message from node that's
streaming
all right it's now inside of here.
Well as you mentioned all you want to do is extract some information of this data object use it to build
a new order and let's say that order then finally act the message that is it nothing else in order to
actually build the order.
Well we have to import the order model file.
We just put together.
So I will import that right away from up to directories models order and then inside of on message I'll
create an order with order dot builds we'll make sure we pass through all those different properties
that we've just said that we would so in total we need the idea the order version user I.D. price and
status so ideal the data dot I.D. price will be at data.
And remember this is nested on the ticket property.
So the data that ticket price status will be data dot status user I.D. you'll be at data dot user I.D.
and our version as well data dot version it we built our order.
Now we have to save it.
So in a weight order dot save
and then assuming that went as expected we can ask our message.
So a message dot EQ and that should be at
debt.
So I'd say this looks pretty good.
Now I would as usual really like to test this out very quickly.
We're gonna make this next video we're going to write out a test for this optional so if you're really
tied with testing no problem you can skip over if you want to.
Otherwise stick around and we'll go through some testing in the next video.
Very quickly.