Just one last big step.
We need to make sure that we open up our query service and watch for the common updated event.
Whenever I receive that we're going to find the appropriate comment in memory and we're going to update
its status to whatever the status is inside the event.
So let's get to it.
Let's open up our query service back inside my editor.
I'm going to find my query service.
Open up the index not just file inside their I will find where we handle all the different events that
are coming in here going to add on a new if statement and watch for a type of comment.
Updated I'll then pull out the updated I.T. content post I.D. and status from data and we'll once again
attempt to find the appropriate comment.
As a quick reminder we are storing all of our posts inside an object.
So we're gonna look inside there.
We're gonna find all the comments with the appropriate post and then we need to just as we did a moment
ago look through that array of comments and find the comments we're trying to update.
So very similar code to what we wrote in the back inside of our comment service just in the last video
they'll say post is going to be post at post I.T.
Well then find the appropriate comment which will be post dot comments dot find we're gonna iterate
over every comment and then return comment idea equal to the idea the comment that we're trying to update
will then update that comment so let's say that its status is going to be this new status.
But remember I'm an update right here is kind of a very generic update or it's saying hey there's some
new attributes associated with this comment.
So chances are we would want to not only update the status here we might have also update the content
of the come itself as well.
So we should probably just take that property and use it to update this comment because again we don't
really know what changed here might've been the status more than the content.
Who knows.
We'll just take all these update properties and assign them to this comment so I'll do comment dot Content
is Content
and that should pretty much be it.
Once again we don't have to try to save this or stored this back inside the Cummins array because we
are updating object that already exists inside their OK.
So we've made many changes so far and I just want to say that chances are some point in time during
this process.
You have said wow this seems crazy.
This seems insane.
How do I know what changes are being made.
Those are some really great questions.
And honestly if you did not get confused during this process of updating these services I would be kind
of surprised.
This really was nasty and I'm going to be kind of surprised if you made all these changes not making
any typos whatsoever.
I just want you to keep that in mind because this entire process of having to go between these different
services add in some events change events.
That's some really nasty stuff.
And without doubt if we're gonna start working on any larger application we need some better tools or
some better methodology of managing the definition of all these events between these services.
There's no doubt about it we need a better way of managing all this stuff because the last three videos
really have not been fun.
Having said that I think it's time to actually do a test of the application and see if this moderation
stuff is actually working.
Now remember we do not actually have anything on the react side this application yet to actually show
something it says hey this comment is being approved or rejected or what have you.
So right now we're going take a look at our network request log inside of chrome and make sure that
all these different comments were creating have the appropriate status attached to them before we do
any of that testing however I'm going to go over to my terminal and I'm going to make sure that none
of these windows have any errors being displayed inside them.
If you see any errors that means you likely have a typo somewhere inside your code.
Now one last thing I want to mention very quickly if you go through this process of testing out this
application and you don't get an error from something.
Again I'm kind of going to be surprised because we've made a ton of changes so many places where you
can make a typo very very easily.
All right.
Let's go over to our browser and at least try to do a test thing and refresh the page.
I'm going to create a new post.
Say a post I'll refresh the page I'll add in a new comments submit and I'll go back over to my terminal
and see what I have.
When I flip back over I don't see any errors anywhere.
Again incredibly likely that you will have an air from somewhere inside of here if you have an error
you can either try to hunted down yourself or just download the completed code that it is attached to
this lecture and try running that instead it's going to go back over now I can refresh the page I see
the comment right there if I click on my list of posts or see my yes my list of post inside the network
request log I'll expand that one post I have take a look at the comments and you'll notice that this
comment has been approved.
Well that's good.
Let's now try making a comment that should be rejected.
I'm going to put in a comment here of orange.
I will submit it.
I'm going to refresh a click on the Post's request again.
Now I should see a second comment inside of here and this time around it should have a status of rejected
because it met our criteria for rejecting a comment had the word orange inside of it.
So that means that hey this stuff is we're working out pretty well the last thing we really need to
do is update the react application to the react application should show hey this comment has been rejected.
If the comment has been rejected and it should show something like this comment is still being moderated
if it is still in the pending state.
So let's take a look at the react application in just a moment and fix it up.