1
00:00:00,450 --> 00:00:01,920
At this point, we've got our schema.

2
00:00:02,160 --> 00:00:04,530
The only thing that is missing is the email validation.

3
00:00:05,100 --> 00:00:10,140
And just to show you alternative approaches, unlike jobs API, we won't use much option.

4
00:00:10,500 --> 00:00:14,150
Instead, we'll take a look at the mongooses docs more specific validation.

5
00:00:14,740 --> 00:00:19,860
And if we keep on scrolling, eventually we'll hit custom validators.

6
00:00:20,190 --> 00:00:25,230
So if the built in validators aren't enough, we can set up our own validators.

7
00:00:25,590 --> 00:00:31,380
And the way we do that, we set up a validate property that is going to be an object.

8
00:00:31,920 --> 00:00:33,710
And in there we have two more properties.

9
00:00:33,720 --> 00:00:37,650
One is validator, which is going to be equal to a function.

10
00:00:38,220 --> 00:00:40,020
So this is where we validate the input.

11
00:00:40,620 --> 00:00:44,580
And this is going to be the message that we show to the user.

12
00:00:45,000 --> 00:00:45,900
So let's try it out.

13
00:00:46,320 --> 00:00:47,040
Now we get back.

14
00:00:47,970 --> 00:00:49,680
We're looking forward to the email in this case.

15
00:00:50,300 --> 00:00:54,570
And I want to set up that Broward date, well, date object.

16
00:00:54,720 --> 00:00:57,240
And in that way, after your property's message.

17
00:00:57,360 --> 00:01:01,530
So it's going to be the message that we're sending back to the user and this guy said, we're going

18
00:01:01,530 --> 00:01:04,519
to go with the please provide valid email.

19
00:01:04,530 --> 00:01:08,880
So here we just say please provide email that means provide some kind of value.

20
00:01:09,330 --> 00:01:15,930
But once we set up to validate, then we'll say, please provide valid the email and then here we need

21
00:01:15,930 --> 00:01:19,290
to go with a validator which is going to be equal to a function.

22
00:01:19,800 --> 00:01:25,740
Now we can set up our own function and then we can set up a test where we validate that input.

23
00:01:26,220 --> 00:01:32,640
But another approach that we can take can use npm package by the name of validator, which is very,

24
00:01:32,640 --> 00:01:34,110
very popular package.

25
00:01:34,780 --> 00:01:40,050
And if you take a look at the ducks the way it works, we installed the package, which is already installed

26
00:01:40,050 --> 00:01:40,980
in the star.

27
00:01:41,340 --> 00:01:42,360
We are acquired.

28
00:01:42,870 --> 00:01:46,350
And then once we do that, we have access to a bunch of functions.

29
00:01:46,680 --> 00:01:52,170
For example, we have one is email service package will do all the work for us.

30
00:01:52,650 --> 00:01:57,090
We simply need to import the package when we need to get the function we're looking for.

31
00:01:57,120 --> 00:02:01,260
And as you can see, they have tons and tons of functions, basically validation options.

32
00:02:01,890 --> 00:02:07,410
And here I just said, is email and you can clearly see what they're checking for.

33
00:02:07,890 --> 00:02:16,200
So now if I navigate back and if I look for const and validate or I'm sorry validator, I guess validator

34
00:02:16,710 --> 00:02:18,030
is equal to require.

35
00:02:18,240 --> 00:02:19,260
And then the package.

36
00:02:19,510 --> 00:02:20,970
And if you want to take a look.

37
00:02:21,000 --> 00:02:23,670
Yep, there it is in the package.

38
00:02:23,670 --> 00:02:26,430
Jason, we have somewhere here.

39
00:02:26,700 --> 00:02:27,600
Yep, there it is.

40
00:02:28,150 --> 00:02:28,770
Validator.

41
00:02:29,250 --> 00:02:31,740
And therefore we can require right away.

42
00:02:31,950 --> 00:02:33,930
So let's say validator.

43
00:02:34,770 --> 00:02:42,540
And then once I say I want to go back here and I want to say validator and is email.

44
00:02:42,700 --> 00:02:44,340
So that's the function that I'm looking for.

45
00:02:44,940 --> 00:02:51,960
And once we have this in place, every time user is going to be trying to sign up for that account,

46
00:02:52,500 --> 00:02:54,900
we'll be able to test right away the email.

47
00:02:54,990 --> 00:02:58,710
So again, this is just alternative approach to what we have.

48
00:02:59,710 --> 00:03:02,350
In the jobs API or I remember here, yeah.

49
00:03:02,440 --> 00:03:07,060
Email and then we use Match in this case, back in the user.

50
00:03:07,240 --> 00:03:11,380
We use external package and we use validate object.

