1
00:00:00,180 --> 00:00:04,950
All right, and once the database connection is in place, the first thing we want to do is to create

2
00:00:04,950 --> 00:00:11,100
a user model and in the process we'll learn a few more, built a Mongo's validators.

3
00:00:11,460 --> 00:00:18,630
And as know, if you need to reference the steps we're about to take, just navigate to the read me

4
00:00:18,990 --> 00:00:20,160
in the road.

5
00:00:20,370 --> 00:00:25,530
So in the start, look for me and here you'll find all the steps.

6
00:00:25,920 --> 00:00:31,590
And since I want to show you more Vallieres, let me open up the Mangoush docs sern here.

7
00:00:31,600 --> 00:00:38,820
We're looking for validation and more specifically, just look for string one because in the user,

8
00:00:38,820 --> 00:00:40,770
pretty much all of them are going to be strange.

9
00:00:40,770 --> 00:00:45,300
So just click on any of these ones and here and there.

10
00:00:45,300 --> 00:00:49,590
I'll just use this as a reference just to showcase what's happening.

11
00:00:49,950 --> 00:00:53,460
And essentially we want to navigate of course, to the user model.

12
00:00:53,760 --> 00:00:59,520
So the file is over here and remember we're looking for it among which of course, so const Mongo's

13
00:00:59,520 --> 00:01:00,990
is equal to require.

14
00:01:01,110 --> 00:01:02,970
And of course, I'm looking for the Mongo's.

15
00:01:03,270 --> 00:01:09,960
And after that we will add two more packages, the JWT one Deidre's, and we're talking one as well

16
00:01:09,960 --> 00:01:10,740
as be.

17
00:01:11,100 --> 00:01:13,560
Yes, but of course that is still coming up.

18
00:01:13,860 --> 00:01:16,200
And I want to start by creating a schema.

19
00:01:16,470 --> 00:01:17,490
So let's go here.

20
00:01:17,490 --> 00:01:23,010
Let's call this user schema that is equal to new Mongo's.

21
00:01:23,550 --> 00:01:26,970
And of course, we're looking for a schema here in this case.

22
00:01:27,390 --> 00:01:30,870
And I want to go with parentheses, passing the object.

23
00:01:31,140 --> 00:01:37,550
And as far as the properties will have three, we'll have name email as well as the password.

24
00:01:37,800 --> 00:01:42,120
So let's go here with a name that's going to be the first one thing I can close the sidebar just so

25
00:01:42,120 --> 00:01:49,140
I have one more real estate and start with type type will be equal to string that will right away set

26
00:01:49,140 --> 00:01:53,020
it equal to your required and then we'll set it equal to.

27
00:01:53,130 --> 00:01:56,940
I remember first value is whether it is true or false.

28
00:01:57,330 --> 00:02:03,180
Of course in my case I'm going with true and I don't say please provide a name.

29
00:02:03,420 --> 00:02:05,880
So of course that is our required there.

30
00:02:06,090 --> 00:02:11,490
And after that I just want to showcase that in the Montrouge docs we can see that we have Midlake and

31
00:02:11,520 --> 00:02:12,090
max length.

32
00:02:12,570 --> 00:02:16,430
Now, of course, as far as the values, that's really up to you, Marcus.

33
00:02:16,470 --> 00:02:20,700
I'm going to go with mental length and I'll set it equal to three.

34
00:02:21,300 --> 00:02:24,660
And of course, I'm going to also set up a max length.

35
00:02:25,060 --> 00:02:31,110
I'm just going to say 50, then I want to go with email and not speed this up.

36
00:02:31,350 --> 00:02:32,850
We will copy and paste.

37
00:02:33,210 --> 00:02:35,190
And of course, I'll change the name here.

38
00:02:35,520 --> 00:02:39,690
This is going to be an email that are still say as required.

39
00:02:39,990 --> 00:02:41,640
So that's going to stay the same.

40
00:02:42,060 --> 00:02:43,230
Let's start over here.

41
00:02:43,620 --> 00:02:51,810
And then we also have a match, one which pretty much creates a validator that checks if the value matches

42
00:02:51,810 --> 00:02:53,580
the given regular expression.

43
00:02:53,940 --> 00:02:55,440
Now, why we want to use that?

44
00:02:55,440 --> 00:03:00,300
Because I want to use the regular expression to check for a valid email.

45
00:03:00,630 --> 00:03:02,730
There's plenty of suggestions out there.

46
00:03:02,970 --> 00:03:08,010
Most likely the first answers that are going to pop up are going to be from stack overflow.

47
00:03:08,310 --> 00:03:12,660
Just pick the one that makes the most sense to you and you'll be good to go.

48
00:03:12,780 --> 00:03:14,970
Now, as part of this project, you have two options.

49
00:03:15,270 --> 00:03:20,300
You can either get the code in or in me or just look in the final one.

50
00:03:20,460 --> 00:03:26,670
So in the final, of course, I have the models and all that and then look for user one and you can

51
00:03:26,670 --> 00:03:28,470
take the entire property.

52
00:03:28,710 --> 00:03:29,750
That's really up to you.

53
00:03:30,090 --> 00:03:32,970
So in my case, I'm just going to navigate through the read me.

54
00:03:33,450 --> 00:03:39,690
I'll take this code and then I want to go back to the user and more specifically, the email.

55
00:03:39,930 --> 00:03:46,290
I want to remove both of these limited length and max length and then we want to go with match and we

56
00:03:46,290 --> 00:03:47,160
pass in the array.

57
00:03:47,400 --> 00:03:55,560
So essentially of the syntax and then we want to pass in the regular expression VLAN comma and then

58
00:03:55,560 --> 00:03:57,990
whatever error message we want to provide.

59
00:03:58,200 --> 00:04:00,270
And in this case, it's pretty much going to be the same.

60
00:04:00,720 --> 00:04:03,990
I'm just going to say please provide valid email.

61
00:04:04,410 --> 00:04:11,850
And once I have the match in place, the last thing I want to set up for the email is unique and true.

62
00:04:12,450 --> 00:04:15,780
And essentially what unique does it create?

63
00:04:15,780 --> 00:04:17,430
A unique index.

64
00:04:17,820 --> 00:04:24,030
And this is something you need to be aware of, where technically it's not a valid error and that becomes

65
00:04:24,030 --> 00:04:28,290
important when we run validate method manually, which we haven't done.

66
00:04:28,290 --> 00:04:30,270
So don't lose your sleep over that.

67
00:04:30,540 --> 00:04:36,960
And when you're writing automated tests and of course you can read more about it in dogs, but the way

68
00:04:36,960 --> 00:04:39,450
it works, it just creates that unique index.

69
00:04:39,600 --> 00:04:47,640
So if I'm trying to save a user but there is already a email and use, then I'll get the duplicate error

70
00:04:47,640 --> 00:04:48,090
message.

71
00:04:48,390 --> 00:04:50,220
And lastly, I want to go password.

72
00:04:50,550 --> 00:04:57,810
And in here I think I'm going to take the name because pretty much is going to be exactly the same where

73
00:04:57,810 --> 00:04:59,070
I'm going to go with password.

74
00:04:59,990 --> 00:05:02,520
Password and then required will be true.

75
00:05:02,930 --> 00:05:08,270
Now, of course, the error message is going to be a little bit different, say your password and then

76
00:05:08,300 --> 00:05:14,300
as far as the length and max length, I think I'm going to go at six and no longer than 12.

77
00:05:15,180 --> 00:05:21,480
So let's set it up this way, we have the user in place, the only thing left to do is, of course,

78
00:05:21,480 --> 00:05:22,060
export it.

79
00:05:22,320 --> 00:05:30,120
So let's go with module exports and set it equal to our Mongo's model.

80
00:05:30,870 --> 00:05:34,020
And of course, we want to pass in our name.

81
00:05:34,200 --> 00:05:38,640
And I I'm going to go with user as well as the user schema.

82
00:05:38,890 --> 00:05:40,930
So user and schema.

83
00:05:41,250 --> 00:05:46,650
And once we say, of course, we can start setting up our register controller.

