1
00:00:07,370 --> 00:00:08,510
Welcome back.

2
00:00:08,540 --> 00:00:13,760
In this video, let's go ahead to model our data for our application.

3
00:00:14,060 --> 00:00:18,510
For this particular application, I'm going to have three entities.

4
00:00:18,530 --> 00:00:31,010
The first one is going to be the users, and then the next entity is going to be the account and account.

5
00:00:31,700 --> 00:00:36,230
And then lastly, it's going to be the transaction.

6
00:00:36,500 --> 00:00:40,910
So how are you going to relate these modules together?

7
00:00:41,360 --> 00:00:49,160
A user can create many accounts and one account can have many transactions.

8
00:00:49,520 --> 00:00:49,850
All right.

9
00:00:49,850 --> 00:00:52,100
So let's see how we're going to model this.

10
00:00:52,280 --> 00:00:55,730
So back to the file that is inside the model.

11
00:00:55,760 --> 00:00:58,850
Let's go ahead and create three files for that.

12
00:00:58,880 --> 00:01:08,990
The first one is going to be the user DOT JS, and then the next one is going to be the transaction.

13
00:01:09,350 --> 00:01:17,900
As that, you can see how I'm naming the model because model are like a class of which we can create

14
00:01:17,900 --> 00:01:20,570
instance of object out of this.

15
00:01:20,570 --> 00:01:23,960
So by convention you use uppercase for model.

16
00:01:23,990 --> 00:01:26,660
Then this one going to be the account.

17
00:01:26,750 --> 00:01:29,020
So third JS.

18
00:01:29,030 --> 00:01:31,610
So let's start with the user.

19
00:01:31,760 --> 00:01:32,210
Great.

20
00:01:32,210 --> 00:01:35,390
So let's bring in the mongoose package.

21
00:01:46,500 --> 00:01:53,160
And next is let's create the schema for that going to be as user schema.

22
00:02:27,050 --> 00:02:36,290
So then this property is going to be as has created account and for this it's going to be a boolean

23
00:02:36,290 --> 00:02:40,220
type of boolean.

24
00:02:40,580 --> 00:02:47,060
We are going to use this field to check if a user has created an account or a project or for you or

25
00:02:47,060 --> 00:02:51,010
she want to keep track about the expenses and income.

26
00:02:51,020 --> 00:02:56,600
So as soon as a user creates an account or a project, we are going to change this one to.

27
00:02:56,630 --> 00:02:57,230
True.

28
00:02:57,260 --> 00:03:00,390
So by default we say is.

29
00:03:02,210 --> 00:03:02,910
Force.

30
00:03:03,380 --> 00:03:03,960
Great.

31
00:03:03,980 --> 00:03:08,150
So next step is that a user can have many accounts.

32
00:03:08,150 --> 00:03:15,020
You're going to have an account filled on this user, and for this you're going to use referencing.

33
00:03:15,020 --> 00:03:24,050
So here as an array with objects and the type here, you're going to be a special type as mongoose dot

34
00:03:24,050 --> 00:03:28,400
schema dot types, dirt object ID.

35
00:03:28,700 --> 00:03:34,160
This field is not a required field, but instead, as soon as a user creates an account, you're are

36
00:03:34,160 --> 00:03:39,080
going to push the account created into the field or this account.

37
00:03:39,080 --> 00:03:46,350
So here we need to reference the model and for this you're going to reference the account model.

38
00:03:46,790 --> 00:03:50,330
We will create it very soon and that is it for that.

39
00:03:50,330 --> 00:03:54,920
So let's pass in some additional configuration for this.

40
00:03:54,920 --> 00:04:01,370
Let's provide timestamp and this one to true for this one, as soon as a user is registered, you're

41
00:04:01,370 --> 00:04:04,790
going to have the date that a user registered.

42
00:04:04,790 --> 00:04:09,080
So here you also have additional properties like to Jason.

43
00:04:09,080 --> 00:04:15,140
And for this one, if you want to convert virtual properties on the object, we will use this one.

44
00:04:15,140 --> 00:04:18,440
So here virtuous to true.

45
00:04:19,250 --> 00:04:23,990
The next step is that let's compile this schema to form a model.

46
00:04:24,110 --> 00:04:25,550
So here we go.

47
00:04:25,580 --> 00:04:39,620
Const uppercase user is equal to mongoose dot model and here we pass in the value here user and then

48
00:04:39,620 --> 00:04:42,230
the schema as user schema.

49
00:04:42,380 --> 00:04:48,950
This name is going to be the collection name inside our database and we're going to utilize it by adding

50
00:04:48,950 --> 00:04:51,830
X and then change everything to lowercase.

51
00:04:51,830 --> 00:04:58,670
So by convention, this is how we passed in last step is that let's go ahead and then export this one

52
00:04:58,670 --> 00:05:01,790
as module dot export.

53
00:05:04,110 --> 00:05:07,380
And it's equal to the user model.

54
00:05:07,410 --> 00:05:09,720
So we are done with the user model.

55
00:05:09,750 --> 00:05:13,370
The next step is going to be the account creation.

56
00:05:13,410 --> 00:05:14,790
It's going to be the same step.

57
00:05:14,810 --> 00:05:22,850
So let's copy this one here and paste it here and let's change this one to account schema.

58
00:05:22,860 --> 00:05:28,170
So select that and Press Command D for multiple selection.

59
00:05:28,170 --> 00:05:32,640
So here are going to be as account schema.

60
00:05:35,250 --> 00:05:35,840
Great.

61
00:05:35,850 --> 00:05:41,220
And for the accounts, Kima, let's look at the properties that we need for the account.

62
00:05:41,400 --> 00:05:47,340
When creating an account, we need to provide the name of the account and it's a required field.

63
00:05:47,340 --> 00:05:51,390
And then this property is going to be the account type for this one.

64
00:05:51,390 --> 00:05:58,590
You need to specify the type of an account, whether is a savings account or investment or billing or

65
00:05:58,710 --> 00:06:02,100
school or project or utilities or travel.

66
00:06:02,130 --> 00:06:05,460
So let's see how we're going to do the one for this.

67
00:06:05,460 --> 00:06:09,990
We are going to use a special property here called enumeration.

68
00:06:09,990 --> 00:06:16,620
The type is string, but here I'm going to pass in the accepted value call.

69
00:06:16,620 --> 00:06:24,390
Now we're going to be as that and going to be an array of the type of account we want to create.

70
00:06:24,390 --> 00:06:27,720
So here, let's finish up by using account type.

71
00:06:27,870 --> 00:06:35,400
So here I'm going to paste the account type here and better to provide the final source code for you.

72
00:06:35,850 --> 00:06:37,620
So this is account type.

73
00:06:37,620 --> 00:06:48,660
I want a user to create perfect and this one must be required field to true that is it.

74
00:06:48,660 --> 00:06:53,280
So let's collapse this one to have some enough room to do the rest.

75
00:06:53,940 --> 00:06:57,450
Then this property is going to be as initial balance.

76
00:06:57,450 --> 00:07:03,660
So it means that when creating an account, you can specify how much money you want to start with.

77
00:07:03,660 --> 00:07:06,060
So here you're going to be an optional.

78
00:07:06,060 --> 00:07:09,300
So here are going to be as balance and a type.

79
00:07:09,300 --> 00:07:19,530
Here is a number and by default let's give it zero default value here zero.

80
00:07:19,530 --> 00:07:22,560
And this one is not a required field.

81
00:07:23,520 --> 00:07:26,610
Then this one is going to be the transaction.

82
00:07:26,730 --> 00:07:32,490
Remember, an account can have many transactions, whether it's income or expenses.

83
00:07:32,490 --> 00:07:34,920
So let's go ahead and create that one.

84
00:07:34,980 --> 00:07:37,050
So let's remove this one.

85
00:07:37,050 --> 00:07:40,740
And now this is going to be the transaction.

86
00:07:41,130 --> 00:07:47,580
And for the transactions, we're going to keep the IDs of the transaction, but not the entire object.

87
00:07:47,580 --> 00:07:54,780
So here we're going to have the same type by the reference, we're going to reference the transaction

88
00:07:54,780 --> 00:07:55,530
model.

89
00:07:55,560 --> 00:07:59,400
And for this one too, we are going to create it very soon.

90
00:07:59,760 --> 00:08:04,620
The next step is that we want to know who created this particular account.

91
00:08:04,620 --> 00:08:14,370
So here, let's collapse this one and we can add a user or create it by this one has more meaning.

92
00:08:14,640 --> 00:08:23,010
So here we are going to use the same type as you use for the transaction and account and that is mongoose

93
00:08:23,010 --> 00:08:34,049
dot schema, dot types, dot object ID and you won't reference the user.

94
00:08:35,169 --> 00:08:38,260
And you won't reference the user model.

95
00:08:39,370 --> 00:08:40,000
Great.

96
00:08:40,240 --> 00:08:47,560
After that, you want to add some notes about the transaction that is description about the transaction

97
00:08:47,560 --> 00:08:55,870
and the type here is going to be of string and then is a required field to true.

98
00:08:56,410 --> 00:08:56,860
All right.

99
00:08:56,860 --> 00:09:00,280
So for this one, too, I think we can maintain this one.

100
00:09:00,400 --> 00:09:03,880
And lastly, let's change this one to account.

101
00:09:03,880 --> 00:09:09,550
So multiple selection and change this one to account, and that is it.

102
00:09:09,580 --> 00:09:18,640
The last step is going to be the transaction so we can copy the account and then paste it here for the

103
00:09:18,640 --> 00:09:19,720
transaction.

104
00:09:19,960 --> 00:09:24,460
So for the transaction, let's see the model for that tool.

105
00:09:24,880 --> 00:09:31,480
So let's change this one to transaction schema and it goes like this transaction.

106
00:09:33,540 --> 00:09:34,830
Come on.

107
00:09:35,700 --> 00:09:36,360
Perfect.

108
00:09:36,390 --> 00:09:38,250
So let's look at the properties here.

109
00:09:38,280 --> 00:09:42,240
We need a name and then the transaction type.

110
00:09:42,330 --> 00:09:45,390
So here are going to be as transaction

111
00:09:48,690 --> 00:09:49,350
type.

112
00:09:49,620 --> 00:09:55,110
And when I be a string, the same thing is going to be an enumeration of values.

113
00:09:55,110 --> 00:10:05,820
So here for the transaction type, you want to keep track of the income and then expenses.

114
00:10:06,510 --> 00:10:07,200
Perfect.

115
00:10:07,230 --> 00:10:14,850
Then this one going to be the amount for the transaction and a type is a number and going to be a required

116
00:10:14,850 --> 00:10:15,450
field.

117
00:10:19,200 --> 00:10:19,920
Great.

118
00:10:19,950 --> 00:10:24,230
Then this, I'm going to be the category of the transaction.

119
00:10:24,240 --> 00:10:27,120
So here we are going to copy this one.

120
00:10:27,120 --> 00:10:33,270
And now down here is going to be the category of the transaction.

121
00:10:34,170 --> 00:10:38,250
And for this one, so we are going to use the enum and for the values.

122
00:10:38,250 --> 00:10:43,320
I'm going to copy and paste the values for the category of the transaction.

123
00:10:43,410 --> 00:10:46,110
And here we go.

124
00:10:46,290 --> 00:10:46,890
Boom.

125
00:10:47,940 --> 00:10:50,490
And this one too is a required field.

126
00:10:50,520 --> 00:10:57,570
The next type is going to be a color because we need that one to add some beauty to the transaction.

127
00:10:57,660 --> 00:11:03,660
Let's say that if we want to use green for income or red for expenses, the choice is yours.

128
00:11:03,660 --> 00:11:07,380
That is why I want to add a field called color.

129
00:11:07,560 --> 00:11:15,450
So here is going to be the color field here and then the type is going to be of string.

130
00:11:15,450 --> 00:11:18,210
And for this one we're going to be optional.

131
00:11:20,280 --> 00:11:26,760
Then this property is going to be the created PI because you want to know who created this transaction.

132
00:11:26,760 --> 00:11:28,710
So let's paste that one here.

133
00:11:29,160 --> 00:11:31,470
Let's remove the transaction here.

134
00:11:31,980 --> 00:11:36,300
The next I'm going to be the date recorded or date for short.

135
00:11:36,720 --> 00:11:37,830
Let's make it date.

136
00:11:37,830 --> 00:11:38,370
Yeah.

137
00:11:38,730 --> 00:11:43,380
So here is going to be a type of date.

138
00:11:45,880 --> 00:11:47,950
And it's going to be optional.

139
00:11:47,980 --> 00:11:49,030
It's optional.

140
00:11:49,180 --> 00:11:57,700
Are we going to have a default value as debt default now as it does now?

141
00:11:59,750 --> 00:12:00,410
Great.

142
00:12:00,410 --> 00:12:04,610
So that is it for that and for this one too.

143
00:12:04,610 --> 00:12:07,730
We need the nodes and we need the timestamp.

144
00:12:07,730 --> 00:12:14,390
And then, Jason, the last step is let's go ahead and then compile to for model.

145
00:12:14,600 --> 00:12:19,100
So a multiple selection here is going to be transaction.

146
00:12:19,340 --> 00:12:25,520
So in case we have left some properties behind, we can come back and then fix it.

