In this video we're going to make sure that the common service watches for the event of comment moderated.
We're going to make sure that we take some information about the comment that was just moderated and
update our local definition of that comment.
So the status should go from pending to either approved or rejected.
Now once again I just want to remind you that understanding the different properties that are inside
of each of these events is super critical.
So I took a little bit of time just to kind of document out exactly what's going on right now with the
comment moderated event comment moderated has an I.D. content post I.D. and status and status is going
to be either approved or rejected it's going to be emitted from the moderation service and we're going
to receive it inside of comments.
So let's open up comments right now and make sure we receive this event and use that updated Status
field it's going to open up my comments directory I'll find indexed at J.S. inside of here I'll go down
to the post request HANDLER We had already put together to handle incoming events I'm going to pull
off the type and data properties once again from rect body will then say if Type is equal to comment
moderated then we want to handle this thing in some way
so the first thing you do inside of here is pull out the comment that we already have stored inside
of our data structure of comments by post I.D. So we need to find the appropriate comment that we've
already stored inside of here and update it status property
so let's get the post I.T. we'll just pull all the different properties out of data because you probably
have to use each of these very shortly it's all pull out the I.T. post I.D. and status the post I.D.
I.D. and status from data well then get all of our different comments that are associated with that
post I.D. We'll say comments is comments by post I.D. at post I.D. we then need to iterate through this
array of comments and find the appropriate comment inside there or the one that we actually want to
update we'll say can't comment is
comments that find we're going to try to find a comment with an I.D. equal to the I.D. from the event
so this right here is the comment that we need to update so we'll take that comment we're gonna update
its status to be the status that we just pulled out of the event as well and actually be it and we don't
have to actually insert this thing back into the comments or rain or anything like that because the
object is the same object in memory is the same object inside the array we essentially just don't have
to insert it back into the array or anything like that so we've now updated status.
Now the next thing we need to do is tell every other service inside our application that this update
just occurred that's going to be where we attempt to emit comment updated we're going to send out come
in updated that's gonna go over to our bus and once again we're going to make sure we receive that over
inside the query service let's also take a look at some documentation on come in updated just so we
really understand the different properties that need to be inside their so come and update it needs
to have the idea of the comment the content the post I.D. and status as well.
And at this point status should be either approved or rejected so let's put this event together and
send it over to our event plus so say a wait axial start post over to H TTP local host four thousand
five
the type of the event is going to be a comment updated and our data is going to be once again ideas
content post I.D. and the updated status so I.D. we can use the certain syntax here because we've already
got I.D..
Post I.D. status and you get the comment we'll be in there as well.
To be content
we'll take the I.D. the updated status the post I.D. that this comment is associated with and the content
as well.
Now I'm using the await syntax right here.
So I gonna make sure they marked the enclosing function as async and that should be at the last thing
we need to do is open up our query service and just make sure that we receive common updated.
So another quick possible take your that in just a moment.