In the last section we were able to test out the first step of our processing pipeline.
I clicked on one of the links inside the email.
We waited a little bit and now I see a console log of this object right here.
Notice how the object has a survey ID with the idea the survey that we have sent out and the choice
which indicates the button that the user clicked.
In this case yes.
So going back over to our code right now here is the value that we had Konst logged out.
We had counsel logged out peanut test pathname.
So this parse object right here will return an object that contains every sort of wild card that was
matched up from the given you are out or route.
I should say in this case pathname.
Now if the parse object right here is not able to extract both a survey ID and a choice then peacoat
test pathname will return NULL instead.
And so that's what's going to help us make sure that we somehow discard records that do not have a survey
ID and a choice let's adjust our code a little bit and figure out exactly how we'll do that.
So I'm going to delete the consulate log statement right now and now I'm going to rewrite that picquet
test pathname which is returning that object with the survey ID and the choice.
I'm now going to assign that object to a variable called Match like so.
So now at this point remember match will either be an object or it will be null.
If a test was not able to extract both the survey ID and the choice.
So now we can look at the match variable and say if a match was found just return that match object
like so.
Now before we just stop right here and say this is enough remember that we are currently processing
the list of all the different events and the three different pieces of data that we really care about.
Here are the survey I.D. the choice and the users e-mail and the users e-mail is contained inside of
that event object.
And so to make sure that we kind of return or walk away from this with all the exact pieces of data
that we care about I want to make sure that rather than just returning the survey ID and the choice
we instead return an object that has the survey ID the choice and the users email.
So we're going to modify this return statement a little bit to return an object that we're going to
create.
So we'll say returning an object that has the email from the event object or the event argument.
So the email is going to be taken from event dot email then we're going to make sure that we take the
survey I.D. and the choice from the match object.
So let's say survey I.D. will be matched on survey I.D. and we make sure that the choice is coming from
match dot choice like so.
Now I'm seeing a lot of opportunities here for a little bit of E-6 refactoring.
So let's give that a shot.
Let's do a little bit of refactoring to kind of tighten up all the code in here by using a little bit
of destructuring.
So I think that the first thing we can do is recognize that the event object we really only care about
the URL and the email properties.
So on the argument to the map function instead of the event we'll say parentheses curly braces and give
me just the email and the URL properties out of here.
Now when we pass off the event you are able to you all helper right here.
We can condense it to be just you l like so inside of the object that we're returning rather than saying
event or email we can condense it to be just email like so.
Now you'll notice that the email property and value right here are identical.
So we can condense it down to just e-mail.
And that's not all.
And we can go even further here.
Notice that out of the match object right here.
Oh I know it actually is.
Excuse me this is actually really important.
We actually can't do any destructuring of this thing right here because P-ROC test is either going to
return an object with Servi ID and choice but if it is not able to make the match it will return.
So we actually cannot do any destructuring off pee test right here.
We cannot do something like Oh give me only the survey ID and the choice because if P-ROC test returns
no then this structure in logic right here will throw an error because we're essentially trying to re
properties off of Knol and that throws an error.
So I think that the best we can do is essentially this right here OK.
So I'm thinking this is looking pretty good at this step.
I think that we can now after this entire map statement right here let's add in one last little console
log just to make sure that we are returning an object with only the properties that we really care about.
So a console log events like so.
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
generating from the map function.
So go back over to my test email right here.
I'm going to click on the Yes button.
It does its thing and they will flip over the terminal and just wait to get some response here.
Now of course again we have to wait for something actually come through.
So let's take a quick break.
We come back we'll hope that we see the console log of whatever we are returning in total from that
map statement.
So I'll see you in just a minute.