All right my friends let's open up that ComEd module.
We're gonna make the two updates we just discussed.
Well first start off inside of our base listener.
So inside the base listener class are going to find the private client property and are going to change
it to protected.
I'm also going to go over to the publisher.
So here's based publisher.
This thing also gets a client inside there we had Martha client as private.
We don't have to.
We don't have to change this private thing over to protected but there might be a scenario at some point
in the future where maybe we want to get access to the client inside of a subclass of publisher.
So not not important not required right now but it's entirely possible that we might want to use this
at some point in the future.
So just thinking forward I'm also gonna change this thing to protected as well.
So that's those two changes.
So now we're going to go over to our ticket updated event and make sure that it says that there's going
to be an order I.D. attached to this thing as well.
So here's my ticket.
Updated event file.
I'm going to add in order I.D. I'm going to market as optional because it is possible that we are going
to update that ticket and then it will not have a defined order.
I.D. put in order I.D. And that's gonna be a string
now.
Quick question here.
Should we add in the order I.D. property to ticket created.
Well when we first create a ticket it is definitely not going to be initially assigned to an order whatsoever.
And that's just something that cannot happen and is very unlikely to happen inside of application.
So me personally I would not add in an order I.D. property to be ticket created event because the order
I.D. even if we provide it would always be set to null or undefined but that's just me you might say
hey I want make sure that all my events look really consistent as much as possible.
So if you wanted to.
Sure go ahead add in order I.D. to the ticket credit event.
But again for me not a requirement.
So we made our changes to the common module.
Now as usual we're going to limit those changes publish them and then update the version of the common
module used inside of our tickets service
back at my terminal.
I'll change into the common module and do that NPM run pub
and after a second or two we should be published.
I'll then go back over to my ticket service I'll do an NPM update for my coming module naturally the
name of your modules can me slightly different
looks good.
And then while we're doing updates I'm also gonna update the version used inside the order module as
well.
Now when we update this version it might result in us seeing an error or two when we go backwards the
order service.
But I think it's just easier for us to update all of our services simultaneously while we're doing this
update really quickly I'm also gonna go over to orders and do an update of that come module as well.
OK.
Very good.
Now back inside of my order created listener.
We finally get to enjoy the fruits of all the changes we just made.
So first off inside of here we do not need the import for wrapper at the top.
So I'll delete that
then down here when we create the publisher rather than reaching out to some other file or other class
we should be able to just access the client property on our listener itself.
So I should be able to write in this client and have everything work.
Now if you write in this client and you get an error chances are typescript is still taking a look at
the old version of your coming module.
So if you see an error right there the first thing to do is to either restart your editor or if you're
using Visual Studio code remember you can hit a manned shift P search for reload window run that that's
going to reboot the typescript type checker and now hopefully that error is going to go away.
If you still see an error then there's probably something else going on.
You want to take a look at the area and figure out what's happening okay.
That's it.
We've now got our publisher being initialized inside of here.
We're passing through the client that the listener is using.
Awesome.
Now above all this is actually a really good example of how we can have a listener that publishes its
own events.
It's pretty much the formula for it.
We're just going to import the publisher into the listener bring an instance of the publisher provide
the client and then publish an event.
Simple enough the last thing we're going to do.
We've created our publisher.
Now it's time to actually publish our event so we'll chain on a publish at the very end.
And then we'll publish information about the ticket that we had just saved.
So if we forget we can always mouse over and we will be told about all the different properties we have
to provide.
So I.T. version title blah blah blah.
All that stuff.
So we'll just throw it all in there just you know we could probably just solve this by throwing in the
entire ticket but I think there might be one or two properties that are not quite similarly named here
I think order I.D. has not quite lining up all I mean to say here is that we in many places throughout
this course we could have just thrown in an entire model to publish functions and whatnot.
But you'll notice that I have not really been doing that instead of been listing out all the different
properties one by one.
I personally like to list out all the properties just to make sure that I'm kind of using or picking
everything appropriately off of the model.
Just a quick side note OK.
So for the I.T. we'll get our ticket i.e. for price.
Ticket price or title ticket title.
What else is there.
We need our user I.D.
order I.D.
And I think that is about a version version.
There we go again.
So that looks good.
We're now publishing our event and one other thing I ought to mention here.
You'll recall that in the past we discussed that if we do not put the awake keyword right here we're
kind of assuming that the entire publish action is just going to go through successfully.
So we might want to make sure we put on the A WAIT RIGHT HERE BECAUSE THAT'S GONNA MAKE SURE THAT IF
ANYTHING GOES WRONG WITH THE publish then we're gonna throw an error on this line of code and never
go down to AK So that would probably be desirable in this case.
OK.
So let's say this.
That's pretty much it.
We'll take a quick pause right here and then hopefully do some kind of manual test or something similar
in the next video.