1
00:00:00,140 --> 00:00:00,560
All right.

2
00:00:00,740 --> 00:00:03,490
Up next, let's start working on the user model.

3
00:00:03,500 --> 00:00:07,700
So at the moment, we have jobs, but in our application.

4
00:00:08,410 --> 00:00:15,280
The jobs are going to belong to a user so each user can create the job, delete the job and rest of

5
00:00:15,280 --> 00:00:15,880
the stuff.

6
00:00:16,030 --> 00:00:22,780
Now, before we start setting up the user model, a very important thing, let's clean out everything

7
00:00:22,780 --> 00:00:30,250
from database because eventually we will die both of these models together and you definitely will avoid

8
00:00:30,250 --> 00:00:34,030
some unnecessary bugs if you start from the scratch.

9
00:00:34,030 --> 00:00:39,310
So let's navigate to our cloud, the Atlas one, and simply click on jobs.

10
00:00:39,340 --> 00:00:43,240
Don't worry, we will set them back up just for now.

11
00:00:43,240 --> 00:00:50,140
We want to remove it since again, at the moment our jobs don't belong to a specific user, which eventually

12
00:00:50,140 --> 00:00:51,970
of course is going to be the case.

13
00:00:52,520 --> 00:00:55,540
Next, we want to create our user model.

14
00:00:55,540 --> 00:00:56,410
So same deal.

15
00:00:56,410 --> 00:01:00,010
We navigate to models, then we go with new file.

16
00:01:00,820 --> 00:01:03,070
I'm going to call this user model.

17
00:01:03,250 --> 00:01:05,300
So let's start with Mongoose from Mongoose.

18
00:01:05,370 --> 00:01:06,340
Okay, That's awesome.

19
00:01:07,150 --> 00:01:09,010
Then let's create the schema.

20
00:01:09,840 --> 00:01:14,920
I'm going to go with user schema that is equal to my new mongoose.

21
00:01:15,830 --> 00:01:18,500
Your mongoose dot and then schema.

22
00:01:18,710 --> 00:01:22,520
Let's set up our object and we'll have a few properties.

23
00:01:22,520 --> 00:01:29,180
We'll start here with string, then we'll have the email, also string then.

24
00:01:29,360 --> 00:01:34,580
And for some reason this wasn't correct, then we're going to go with password, which also will be

25
00:01:34,580 --> 00:01:35,360
a string.

26
00:01:37,310 --> 00:01:39,740
Then we have a last name.

27
00:01:40,980 --> 00:01:46,530
This is going to be technically an object because I'll set up some defaults, so I'm going to go here

28
00:01:46,530 --> 00:01:48,960
with type string and then default.

29
00:01:49,050 --> 00:01:51,180
It's going to be equal to lastname.

30
00:01:51,960 --> 00:01:52,860
Let's save this.

31
00:01:52,860 --> 00:01:54,960
Then we also have location.

32
00:01:56,200 --> 00:02:00,070
Also an object type equals to a string.

33
00:02:00,310 --> 00:02:01,630
Then default.

34
00:02:01,750 --> 00:02:03,490
I'll set it equal to my city.

35
00:02:03,520 --> 00:02:06,910
You can also go Earth or Florida.

36
00:02:07,240 --> 00:02:08,710
That's always a good option.

37
00:02:08,720 --> 00:02:11,320
And then lastly, we'll have a role.

38
00:02:11,350 --> 00:02:13,180
So in this application.

39
00:02:13,770 --> 00:02:16,800
Users are going to have roles now, totally.

40
00:02:16,800 --> 00:02:23,430
Honestly, only one user is going to be admin unless you choose to set it up differently.

41
00:02:23,430 --> 00:02:29,040
But as far as our code, there's only going to be one admin user.

42
00:02:29,040 --> 00:02:32,250
And of course admin users have more privileges.

43
00:02:32,250 --> 00:02:39,660
In our case, admin user is going to have access to the total amount of users and jobs in the application.

44
00:02:39,660 --> 00:02:41,700
But of course sky's the limit.

45
00:02:41,730 --> 00:02:48,120
Now as far as the role, yes, it's going to be a string, but we'll set it up here as enum.

46
00:02:48,780 --> 00:02:51,870
And as far as the options we're going to go with user.

47
00:02:52,820 --> 00:02:53,900
An admin.

48
00:02:54,080 --> 00:03:00,320
Then we're also going to set up default and we're going to go with user.

49
00:03:00,350 --> 00:03:03,440
Now one last thing we want to do in this video.

50
00:03:04,480 --> 00:03:06,880
Is to export default.

51
00:03:07,940 --> 00:03:11,270
And then remember, we're looking for Mongoose dot.

52
00:03:12,060 --> 00:03:13,140
Then model.

53
00:03:14,190 --> 00:03:15,300
Let's come up with a name.

54
00:03:15,300 --> 00:03:20,370
In my case, it's going to be user and we want to pass in the user schema.

55
00:03:20,370 --> 00:03:24,240
And with this in place, we are ready to move on to the next step.

