So let's use the validation package we just created and we're going to do that in Handler's Dash API,
in the function name to create customer and subscribe to plan.
And as you can see right here on line one, thirty five of my code, the data we're getting from the
front end is actually marshalled into straight payload.
So we decode it into straight payload.
And that type, as you can see over here, has a bunch of fields.
And we're going to pay attention to this one first name.
So the place to do the validation, of course, is right here.
And we want to stop if the data is not valid.
So let's just put a comment in here, validate data.
And to do that, we simply create a validator.
So I'll call that the and that's a sign the value of valid data for the new.
I don't think it did the import for me.
So let's go over here and import it.
I'll just duplicate this line and add this valid data and I should take care of that.
So we have a validated.
Now let's do a check.
And it's really simple.
So I want to check to make sure that there's at least two characters in the first name.
And that's totally arbitrary because I just want to show you how the validator works.
So from the variable V, we'll call the builtin method check and the first argument is a boolean.
And as you know, we can do something as simple as this.
Lenn data first name is greater than zero.
That will return true or greater than one, I guess, because you want to make it at least two characters
long that will return.
True if there's at least two characters in the first name and then return false otherwise.
So that's the first argument.
The key we want to check is called First Underscore Name, and that's what it's called in the JSON,
of course.
And we give it some error message must be Olinka Lowercase must be at least two characters
and get rid of the space.
And that's all I have to do.
So I'll close this one now to give us a little more room.
So that actually performs the check.
And now below it, you can put whatever checks you want in there.
Of course, now we just check to see if there's any errors.
So if not Vidor's valid, then I say app failed validation and give it an hour and vidaurre errors and
return.
So I don't want to go any further.
And literally that's all I have to do.
Now, obviously, you can make really simple checks here.
You could have one for last name if you wanted to.
So I just duplicate it like this and make it last name.
And of course, these values here have to correspond to whatever the entry is in the JSON because we
want to send that information back.
And all I can say is if last name data dot last name
equals an empty string and give that error and you can't get much simpler than that, it's pretty straightforward.
Now, I'm not going to do this second check.
I'm just going to do the first one.
So the next step is to go update our JavaScript on the front end.
And after we call fetch, we check to see if there's an error and do something with that information
and we'll take care of that in the next lecture.