1 00:00:00,800 --> 00:00:05,370 In the last section we were able to test out the first step of our processing pipeline. 2 00:00:05,370 --> 00:00:07,280 I clicked on one of the links inside the email. 3 00:00:07,320 --> 00:00:11,660 We waited a little bit and now I see a console log of this object right here. 4 00:00:11,670 --> 00:00:18,270 Notice how the object has a survey ID with the idea the survey that we have sent out and the choice 5 00:00:18,510 --> 00:00:20,940 which indicates the button that the user clicked. 6 00:00:20,970 --> 00:00:22,980 In this case yes. 7 00:00:23,430 --> 00:00:27,770 So going back over to our code right now here is the value that we had Konst logged out. 8 00:00:27,780 --> 00:00:30,900 We had counsel logged out peanut test pathname. 9 00:00:30,900 --> 00:00:37,710 So this parse object right here will return an object that contains every sort of wild card that was 10 00:00:37,710 --> 00:00:40,470 matched up from the given you are out or route. 11 00:00:40,470 --> 00:00:43,290 I should say in this case pathname. 12 00:00:43,410 --> 00:00:52,190 Now if the parse object right here is not able to extract both a survey ID and a choice then peacoat 13 00:00:52,290 --> 00:00:55,520 test pathname will return NULL instead. 14 00:00:55,560 --> 00:01:01,170 And so that's what's going to help us make sure that we somehow discard records that do not have a survey 15 00:01:01,170 --> 00:01:07,870 ID and a choice let's adjust our code a little bit and figure out exactly how we'll do that. 16 00:01:07,950 --> 00:01:14,610 So I'm going to delete the consulate log statement right now and now I'm going to rewrite that picquet 17 00:01:14,670 --> 00:01:22,720 test pathname which is returning that object with the survey ID and the choice. 18 00:01:22,740 --> 00:01:27,870 I'm now going to assign that object to a variable called Match like so. 19 00:01:28,120 --> 00:01:33,530 So now at this point remember match will either be an object or it will be null. 20 00:01:33,660 --> 00:01:38,800 If a test was not able to extract both the survey ID and the choice. 21 00:01:39,180 --> 00:01:46,620 So now we can look at the match variable and say if a match was found just return that match object 22 00:01:47,100 --> 00:01:48,470 like so. 23 00:01:49,050 --> 00:01:53,910 Now before we just stop right here and say this is enough remember that we are currently processing 24 00:01:53,910 --> 00:01:58,410 the list of all the different events and the three different pieces of data that we really care about. 25 00:01:58,410 --> 00:02:05,400 Here are the survey I.D. the choice and the users e-mail and the users e-mail is contained inside of 26 00:02:05,400 --> 00:02:06,990 that event object. 27 00:02:07,080 --> 00:02:12,240 And so to make sure that we kind of return or walk away from this with all the exact pieces of data 28 00:02:12,240 --> 00:02:17,130 that we care about I want to make sure that rather than just returning the survey ID and the choice 29 00:02:17,400 --> 00:02:22,740 we instead return an object that has the survey ID the choice and the users email. 30 00:02:22,950 --> 00:02:27,030 So we're going to modify this return statement a little bit to return an object that we're going to 31 00:02:27,030 --> 00:02:28,170 create. 32 00:02:28,230 --> 00:02:34,680 So we'll say returning an object that has the email from the event object or the event argument. 33 00:02:34,680 --> 00:02:41,100 So the email is going to be taken from event dot email then we're going to make sure that we take the 34 00:02:41,100 --> 00:02:44,580 survey I.D. and the choice from the match object. 35 00:02:44,610 --> 00:02:53,340 So let's say survey I.D. will be matched on survey I.D. and we make sure that the choice is coming from 36 00:02:53,490 --> 00:02:57,650 match dot choice like so. 37 00:02:58,060 --> 00:03:02,600 Now I'm seeing a lot of opportunities here for a little bit of E-6 refactoring. 38 00:03:02,650 --> 00:03:03,660 So let's give that a shot. 39 00:03:03,670 --> 00:03:07,960 Let's do a little bit of refactoring to kind of tighten up all the code in here by using a little bit 40 00:03:07,990 --> 00:03:09,640 of destructuring. 41 00:03:09,640 --> 00:03:15,190 So I think that the first thing we can do is recognize that the event object we really only care about 42 00:03:15,190 --> 00:03:18,130 the URL and the email properties. 43 00:03:18,400 --> 00:03:25,930 So on the argument to the map function instead of the event we'll say parentheses curly braces and give 44 00:03:25,930 --> 00:03:30,100 me just the email and the URL properties out of here. 45 00:03:30,100 --> 00:03:35,110 Now when we pass off the event you are able to you all helper right here. 46 00:03:35,290 --> 00:03:42,160 We can condense it to be just you l like so inside of the object that we're returning rather than saying 47 00:03:42,190 --> 00:03:46,730 event or email we can condense it to be just email like so. 48 00:03:47,050 --> 00:03:51,240 Now you'll notice that the email property and value right here are identical. 49 00:03:51,310 --> 00:03:53,690 So we can condense it down to just e-mail. 50 00:03:54,070 --> 00:03:54,980 And that's not all. 51 00:03:54,980 --> 00:03:56,860 And we can go even further here. 52 00:03:56,890 --> 00:04:00,590 Notice that out of the match object right here. 53 00:04:00,610 --> 00:04:01,990 Oh I know it actually is. 54 00:04:02,020 --> 00:04:03,340 Excuse me this is actually really important. 55 00:04:03,340 --> 00:04:08,650 We actually can't do any destructuring of this thing right here because P-ROC test is either going to 56 00:04:08,650 --> 00:04:15,620 return an object with Servi ID and choice but if it is not able to make the match it will return. 57 00:04:15,970 --> 00:04:19,450 So we actually cannot do any destructuring off pee test right here. 58 00:04:19,450 --> 00:04:25,330 We cannot do something like Oh give me only the survey ID and the choice because if P-ROC test returns 59 00:04:25,360 --> 00:04:30,400 no then this structure in logic right here will throw an error because we're essentially trying to re 60 00:04:30,400 --> 00:04:33,490 properties off of Knol and that throws an error. 61 00:04:33,490 --> 00:04:38,770 So I think that the best we can do is essentially this right here OK. 62 00:04:39,170 --> 00:04:41,500 So I'm thinking this is looking pretty good at this step. 63 00:04:41,990 --> 00:04:48,690 I think that we can now after this entire map statement right here let's add in one last little console 64 00:04:48,690 --> 00:04:54,250 log just to make sure that we are returning an object with only the properties that we really care about. 65 00:04:54,260 --> 00:04:58,430 So a console log events like so. 66 00:04:58,430 --> 00:05:03,380 And now let's click on a link inside of an email and get the thing to log out the list that we are now 67 00:05:03,410 --> 00:05:05,990 generating from the map function. 68 00:05:06,050 --> 00:05:09,290 So go back over to my test email right here. 69 00:05:09,290 --> 00:05:11,760 I'm going to click on the Yes button. 70 00:05:12,070 --> 00:05:17,650 It does its thing and they will flip over the terminal and just wait to get some response here. 71 00:05:17,690 --> 00:05:20,720 Now of course again we have to wait for something actually come through. 72 00:05:20,720 --> 00:05:22,080 So let's take a quick break. 73 00:05:22,100 --> 00:05:27,530 We come back we'll hope that we see the console log of whatever we are returning in total from that 74 00:05:27,530 --> 00:05:28,460 map statement. 75 00:05:28,460 --> 00:05:29,880 So I'll see you in just a minute.