1 00:00:01,450 --> 00:00:06,330 In this video we're going to make sure that the common service watches for the event of comment moderated. 2 00:00:06,400 --> 00:00:10,360 We're going to make sure that we take some information about the comment that was just moderated and 3 00:00:10,390 --> 00:00:12,900 update our local definition of that comment. 4 00:00:12,970 --> 00:00:17,010 So the status should go from pending to either approved or rejected. 5 00:00:18,020 --> 00:00:22,490 Now once again I just want to remind you that understanding the different properties that are inside 6 00:00:22,490 --> 00:00:24,890 of each of these events is super critical. 7 00:00:24,890 --> 00:00:28,730 So I took a little bit of time just to kind of document out exactly what's going on right now with the 8 00:00:28,730 --> 00:00:35,480 comment moderated event comment moderated has an I.D. content post I.D. and status and status is going 9 00:00:35,480 --> 00:00:41,990 to be either approved or rejected it's going to be emitted from the moderation service and we're going 10 00:00:41,990 --> 00:00:44,390 to receive it inside of comments. 11 00:00:44,390 --> 00:00:49,400 So let's open up comments right now and make sure we receive this event and use that updated Status 12 00:00:49,400 --> 00:00:57,870 field it's going to open up my comments directory I'll find indexed at J.S. inside of here I'll go down 13 00:00:57,870 --> 00:01:04,610 to the post request HANDLER We had already put together to handle incoming events I'm going to pull 14 00:01:04,610 --> 00:01:14,660 off the type and data properties once again from rect body will then say if Type is equal to comment 15 00:01:14,720 --> 00:01:18,020 moderated then we want to handle this thing in some way 16 00:01:20,970 --> 00:01:25,570 so the first thing you do inside of here is pull out the comment that we already have stored inside 17 00:01:25,570 --> 00:01:31,120 of our data structure of comments by post I.D. So we need to find the appropriate comment that we've 18 00:01:31,120 --> 00:01:33,940 already stored inside of here and update it status property 19 00:01:38,310 --> 00:01:44,170 so let's get the post I.T. we'll just pull all the different properties out of data because you probably 20 00:01:44,180 --> 00:01:49,790 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. 21 00:01:50,360 --> 00:02:00,170 I.D. and status from data well then get all of our different comments that are associated with that 22 00:02:00,170 --> 00:02:10,470 post I.D. We'll say comments is comments by post I.D. at post I.D. we then need to iterate through this 23 00:02:10,470 --> 00:02:14,640 array of comments and find the appropriate comment inside there or the one that we actually want to 24 00:02:14,640 --> 00:02:17,580 update we'll say can't comment is 25 00:02:20,380 --> 00:02:32,790 comments that find we're going to try to find a comment with an I.D. equal to the I.D. from the event 26 00:02:33,570 --> 00:02:39,990 so this right here is the comment that we need to update so we'll take that comment we're gonna update 27 00:02:39,990 --> 00:02:46,350 its status to be the status that we just pulled out of the event as well and actually be it and we don't 28 00:02:46,350 --> 00:02:50,070 have to actually insert this thing back into the comments or rain or anything like that because the 29 00:02:50,070 --> 00:02:55,200 object is the same object in memory is the same object inside the array we essentially just don't have 30 00:02:55,200 --> 00:03:01,000 to insert it back into the array or anything like that so we've now updated status. 31 00:03:01,010 --> 00:03:05,660 Now the next thing we need to do is tell every other service inside our application that this update 32 00:03:05,660 --> 00:03:13,440 just occurred that's going to be where we attempt to emit comment updated we're going to send out come 33 00:03:13,460 --> 00:03:19,790 in updated that's gonna go over to our bus and once again we're going to make sure we receive that over 34 00:03:19,790 --> 00:03:26,010 inside the query service let's also take a look at some documentation on come in updated just so we 35 00:03:26,010 --> 00:03:31,760 really understand the different properties that need to be inside their so come and update it needs 36 00:03:31,760 --> 00:03:37,610 to have the idea of the comment the content the post I.D. and status as well. 37 00:03:37,610 --> 00:03:44,120 And at this point status should be either approved or rejected so let's put this event together and 38 00:03:44,120 --> 00:03:55,920 send it over to our event plus so say a wait axial start post over to H TTP local host four thousand 39 00:03:55,930 --> 00:03:56,440 five 40 00:04:00,800 --> 00:04:09,590 the type of the event is going to be a comment updated and our data is going to be once again ideas 41 00:04:09,620 --> 00:04:17,240 content post I.D. and the updated status so I.D. we can use the certain syntax here because we've already 42 00:04:17,240 --> 00:04:17,920 got I.D.. 43 00:04:17,920 --> 00:04:22,250 Post I.D. status and you get the comment we'll be in there as well. 44 00:04:23,370 --> 00:04:24,050 To be content 45 00:04:26,960 --> 00:04:34,830 we'll take the I.D. the updated status the post I.D. that this comment is associated with and the content 46 00:04:34,890 --> 00:04:39,260 as well. 47 00:04:39,380 --> 00:04:41,110 Now I'm using the await syntax right here. 48 00:04:41,150 --> 00:04:47,880 So I gonna make sure they marked the enclosing function as async and that should be at the last thing 49 00:04:47,880 --> 00:04:55,510 we need to do is open up our query service and just make sure that we receive common updated. 50 00:04:55,590 --> 00:04:57,960 So another quick possible take your that in just a moment.