1
00:00:00,360 --> 00:00:00,760
Beautiful.

2
00:00:01,110 --> 00:00:08,610
We can save our years here and before we cover why it's such a bad practice to save our passport as

3
00:00:08,610 --> 00:00:09,120
a string.

4
00:00:10,180 --> 00:00:15,640
Now, let me remind you about the hour checking and more specifically, let me just jog your memory

5
00:00:15,820 --> 00:00:23,010
on the fact that we can check for the empty valorise right in the controller, because keep in mind

6
00:00:23,010 --> 00:00:26,440
that at the moment we are doing that using the mongoose.

7
00:00:26,680 --> 00:00:32,770
So first, let me show you how we can do that in the controller and then I'll talk about why we're checking

8
00:00:32,770 --> 00:00:36,360
in the mongoose, essentially what I'm trying to accomplish.

9
00:00:36,820 --> 00:00:43,360
And if you remember, we simply check it in a falling way where we go it name, email and password.

10
00:00:43,540 --> 00:00:47,500
Now, all of that is coming from Iraq, that body, of course.

11
00:00:47,740 --> 00:00:54,730
And then we want to go if and if one of the writers is missing, then we'll throw our own custom or

12
00:00:54,970 --> 00:00:57,500
more specifically, the bad request one.

13
00:00:57,790 --> 00:01:02,910
So let's say or your email and then we'll do the same thing for the password.

14
00:01:03,070 --> 00:01:07,970
So if one of them is missing and of course, we'll throw the error and of course, we need to import

15
00:01:07,970 --> 00:01:08,170
that.

16
00:01:08,350 --> 00:01:15,600
So say here and we're looking for bad request, quest and error.

17
00:01:15,910 --> 00:01:17,200
So that's the one we're looking for.

18
00:01:17,380 --> 00:01:22,330
Now, if you don't want to make the typo, then of course just navigate through the errors folder more

19
00:01:22,330 --> 00:01:25,390
specifically in the U.S. and then just grab this value.

20
00:01:26,050 --> 00:01:29,380
So that way you'll avoid some unnecessary typos.

21
00:01:29,620 --> 00:01:33,580
So let me just make sure that the name is correct, looks about right.

22
00:01:33,790 --> 00:01:35,200
And then we want to go with require.

23
00:01:35,200 --> 00:01:38,590
Of course, we're going to levels up and we're looking for two years.

24
00:01:38,770 --> 00:01:44,270
And since we're having the U.S. over there, of course, we don't need to be more specific by default.

25
00:01:44,470 --> 00:01:46,600
We'll get back the next year.

26
00:01:46,960 --> 00:01:52,270
And once I have the important in place now, of course, we just want to throw the error in the block

27
00:01:52,540 --> 00:01:54,700
where l say throw new.

28
00:01:55,030 --> 00:01:57,640
And of course, I'm looking for by request one.

29
00:01:58,360 --> 00:02:03,570
And then we just need to pass in the message because remember, the status code is already there.

30
00:02:03,880 --> 00:02:11,350
And let's just say, please, please provide name, email and password.

31
00:02:12,330 --> 00:02:21,180
And password, and once I save and once we navigate back to the postman, if I remove the password completely,

32
00:02:22,230 --> 00:02:26,280
if I'll just send notice now, of course I will get the message.

33
00:02:26,640 --> 00:02:33,000
Now, our functionality will still work because, of course, we're using the Mango's validators, even

34
00:02:33,000 --> 00:02:34,460
if I remove this code.

35
00:02:34,740 --> 00:02:43,170
So if I come on this one out and if we go back and if we send without a password or without any of these

36
00:02:43,170 --> 00:02:45,960
two values as well, of course we'll get back there.

37
00:02:46,320 --> 00:02:52,140
Now, the reason why I'm using the Mongo's validator, because during this project, I also want to

38
00:02:52,140 --> 00:02:58,110
show you how we can send back more meaningful response, because at the moment, of course, I'm sending

39
00:02:58,110 --> 00:03:05,280
500, which technically isn't a case, because, of course, now we have a bad request instead of internal

40
00:03:05,280 --> 00:03:12,150
server error and also known as these massive objects probably would be better if we would send just

41
00:03:12,150 --> 00:03:15,780
please provide the password or the e-mail or the name.

42
00:03:16,030 --> 00:03:22,500
And therefore, in this project, we will use Mongo's validators quite a bit just because, of course,

43
00:03:22,710 --> 00:03:26,640
I want to show you how we can send back more meaningful messages.

44
00:03:27,030 --> 00:03:30,950
But that doesn't mean that we're not going to check in the controller.

45
00:03:31,320 --> 00:03:37,290
So, of course, this one is optional, but there's going to be some cases where, yes, we all have

46
00:03:37,290 --> 00:03:40,630
to set up that check directly in the controller.

47
00:03:40,950 --> 00:03:45,690
So this one I'll remove because this pretty much is a repetition here.

48
00:03:45,690 --> 00:03:52,200
But when it comes to different results, yes, there might be some cases where we check directly in

49
00:03:52,200 --> 00:03:52,860
the controller.

50
00:03:53,220 --> 00:03:54,300
Hopefully that is clear.

51
00:03:54,480 --> 00:03:57,780
So now we can start tackling the password issue.

