1 00:00:00,930 --> 00:00:02,310 Just one last big step. 2 00:00:02,310 --> 00:00:06,390 We need to make sure that we open up our query service and watch for the common updated event. 3 00:00:06,540 --> 00:00:10,590 Whenever I receive that we're going to find the appropriate comment in memory and we're going to update 4 00:00:10,650 --> 00:00:14,040 its status to whatever the status is inside the event. 5 00:00:14,040 --> 00:00:14,760 So let's get to it. 6 00:00:14,760 --> 00:00:19,920 Let's open up our query service back inside my editor. 7 00:00:20,020 --> 00:00:22,730 I'm going to find my query service. 8 00:00:22,730 --> 00:00:27,780 Open up the index not just file inside their I will find where we handle all the different events that 9 00:00:27,780 --> 00:00:37,020 are coming in here going to add on a new if statement and watch for a type of comment. 10 00:00:37,050 --> 00:00:49,470 Updated I'll then pull out the updated I.T. content post I.D. and status from data and we'll once again 11 00:00:49,470 --> 00:00:52,060 attempt to find the appropriate comment. 12 00:00:52,230 --> 00:00:55,980 As a quick reminder we are storing all of our posts inside an object. 13 00:00:56,080 --> 00:00:57,270 So we're gonna look inside there. 14 00:00:57,270 --> 00:01:02,070 We're gonna find all the comments with the appropriate post and then we need to just as we did a moment 15 00:01:02,070 --> 00:01:05,630 ago look through that array of comments and find the comments we're trying to update. 16 00:01:05,640 --> 00:01:10,530 So very similar code to what we wrote in the back inside of our comment service just in the last video 17 00:01:11,190 --> 00:01:16,920 they'll say post is going to be post at post I.T. 18 00:01:21,520 --> 00:01:29,250 Well then find the appropriate comment which will be post dot comments dot find we're gonna iterate 19 00:01:29,250 --> 00:01:37,420 over every comment and then return comment idea equal to the idea the comment that we're trying to update 20 00:01:41,870 --> 00:01:47,720 will then update that comment so let's say that its status is going to be this new status. 21 00:01:48,170 --> 00:01:52,910 But remember I'm an update right here is kind of a very generic update or it's saying hey there's some 22 00:01:52,910 --> 00:01:55,020 new attributes associated with this comment. 23 00:01:55,220 --> 00:02:00,200 So chances are we would want to not only update the status here we might have also update the content 24 00:02:00,220 --> 00:02:01,710 of the come itself as well. 25 00:02:01,820 --> 00:02:06,020 So we should probably just take that property and use it to update this comment because again we don't 26 00:02:06,020 --> 00:02:09,400 really know what changed here might've been the status more than the content. 27 00:02:09,410 --> 00:02:10,080 Who knows. 28 00:02:10,100 --> 00:02:15,950 We'll just take all these update properties and assign them to this comment so I'll do comment dot Content 29 00:02:16,730 --> 00:02:17,300 is Content 30 00:02:20,630 --> 00:02:22,090 and that should pretty much be it. 31 00:02:22,160 --> 00:02:26,420 Once again we don't have to try to save this or stored this back inside the Cummins array because we 32 00:02:26,420 --> 00:02:31,100 are updating object that already exists inside their OK. 33 00:02:31,180 --> 00:02:37,510 So we've made many changes so far and I just want to say that chances are some point in time during 34 00:02:37,510 --> 00:02:38,340 this process. 35 00:02:38,350 --> 00:02:40,780 You have said wow this seems crazy. 36 00:02:40,780 --> 00:02:41,800 This seems insane. 37 00:02:41,800 --> 00:02:44,660 How do I know what changes are being made. 38 00:02:44,680 --> 00:02:46,390 Those are some really great questions. 39 00:02:46,420 --> 00:02:51,370 And honestly if you did not get confused during this process of updating these services I would be kind 40 00:02:51,370 --> 00:02:52,340 of surprised. 41 00:02:52,540 --> 00:02:58,150 This really was nasty and I'm going to be kind of surprised if you made all these changes not making 42 00:02:58,180 --> 00:03:00,370 any typos whatsoever. 43 00:03:00,370 --> 00:03:04,630 I just want you to keep that in mind because this entire process of having to go between these different 44 00:03:04,630 --> 00:03:07,550 services add in some events change events. 45 00:03:07,660 --> 00:03:09,710 That's some really nasty stuff. 46 00:03:09,710 --> 00:03:14,410 And without doubt if we're gonna start working on any larger application we need some better tools or 47 00:03:14,410 --> 00:03:19,840 some better methodology of managing the definition of all these events between these services. 48 00:03:19,840 --> 00:03:24,880 There's no doubt about it we need a better way of managing all this stuff because the last three videos 49 00:03:24,910 --> 00:03:27,650 really have not been fun. 50 00:03:27,880 --> 00:03:31,630 Having said that I think it's time to actually do a test of the application and see if this moderation 51 00:03:31,630 --> 00:03:33,080 stuff is actually working. 52 00:03:33,080 --> 00:03:38,030 Now remember we do not actually have anything on the react side this application yet to actually show 53 00:03:38,030 --> 00:03:42,430 something it says hey this comment is being approved or rejected or what have you. 54 00:03:42,430 --> 00:03:46,570 So right now we're going take a look at our network request log inside of chrome and make sure that 55 00:03:46,600 --> 00:03:51,230 all these different comments were creating have the appropriate status attached to them before we do 56 00:03:51,260 --> 00:03:54,920 any of that testing however I'm going to go over to my terminal and I'm going to make sure that none 57 00:03:54,920 --> 00:03:58,040 of these windows have any errors being displayed inside them. 58 00:03:58,040 --> 00:04:01,790 If you see any errors that means you likely have a typo somewhere inside your code. 59 00:04:01,790 --> 00:04:06,230 Now one last thing I want to mention very quickly if you go through this process of testing out this 60 00:04:06,230 --> 00:04:09,500 application and you don't get an error from something. 61 00:04:09,560 --> 00:04:15,830 Again I'm kind of going to be surprised because we've made a ton of changes so many places where you 62 00:04:15,830 --> 00:04:19,430 can make a typo very very easily. 63 00:04:19,480 --> 00:04:19,680 All right. 64 00:04:19,750 --> 00:04:24,240 Let's go over to our browser and at least try to do a test thing and refresh the page. 65 00:04:24,310 --> 00:04:26,290 I'm going to create a new post. 66 00:04:26,370 --> 00:04:35,650 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 67 00:04:35,740 --> 00:04:36,420 and see what I have. 68 00:04:37,210 --> 00:04:39,760 When I flip back over I don't see any errors anywhere. 69 00:04:39,790 --> 00:04:44,950 Again incredibly likely that you will have an air from somewhere inside of here if you have an error 70 00:04:45,010 --> 00:04:49,810 you can either try to hunted down yourself or just download the completed code that it is attached to 71 00:04:49,810 --> 00:04:56,330 this lecture and try running that instead it's going to go back over now I can refresh the page I see 72 00:04:56,330 --> 00:05:02,030 the comment right there if I click on my list of posts or see my yes my list of post inside the network 73 00:05:02,030 --> 00:05:06,950 request log I'll expand that one post I have take a look at the comments and you'll notice that this 74 00:05:06,950 --> 00:05:10,120 comment has been approved. 75 00:05:10,280 --> 00:05:11,270 Well that's good. 76 00:05:11,300 --> 00:05:14,120 Let's now try making a comment that should be rejected. 77 00:05:14,170 --> 00:05:18,570 I'm going to put in a comment here of orange. 78 00:05:18,570 --> 00:05:20,230 I will submit it. 79 00:05:20,300 --> 00:05:26,160 I'm going to refresh a click on the Post's request again. 80 00:05:26,270 --> 00:05:30,230 Now I should see a second comment inside of here and this time around it should have a status of rejected 81 00:05:30,500 --> 00:05:35,030 because it met our criteria for rejecting a comment had the word orange inside of it. 82 00:05:35,070 --> 00:05:40,380 So that means that hey this stuff is we're working out pretty well the last thing we really need to 83 00:05:40,380 --> 00:05:46,050 do is update the react application to the react application should show hey this comment has been rejected. 84 00:05:46,170 --> 00:05:50,520 If the comment has been rejected and it should show something like this comment is still being moderated 85 00:05:50,700 --> 00:05:53,180 if it is still in the pending state. 86 00:05:53,220 --> 00:05:56,600 So let's take a look at the react application in just a moment and fix it up.