1
00:00:07,560 --> 00:00:08,700
Welcome back.

2
00:00:08,730 --> 00:00:13,230
In this video, let's focus on the account of a user.

3
00:00:13,260 --> 00:00:18,560
We are not done with the user code operation, for example, deleting, updating.

4
00:00:18,570 --> 00:00:22,600
But what we want is the authorization and then the authentication.

5
00:00:22,620 --> 00:00:24,420
The rest are easy.

6
00:00:24,420 --> 00:00:30,030
So let's switch from users and now let's get to how we're going to create an account and then how we

7
00:00:30,030 --> 00:00:36,120
are going to associate account creation with a user and a transaction with an account.

8
00:00:36,120 --> 00:00:37,770
So let's get started.

9
00:00:37,770 --> 00:00:45,630
So inside the controllers, let's collapse the users, and now let's focus on the account and we are

10
00:00:45,630 --> 00:00:49,140
going to start with the creation of an account.

11
00:00:49,140 --> 00:00:53,520
So let's get back to the models and we have the account model.

12
00:00:53,520 --> 00:01:03,450
So inside the account controller less require the one as account and to import is working fine.

13
00:01:03,630 --> 00:01:08,730
So next step is that we're going to pass in the payload that we want to create.

14
00:01:08,880 --> 00:01:15,640
But before creating, let's look at the steps because you want to assist with account creation with

15
00:01:15,640 --> 00:01:16,470
the user.

16
00:01:16,470 --> 00:01:20,700
So here we go inside the try.

17
00:01:20,730 --> 00:01:22,530
Let's have the roadmap.

18
00:01:22,650 --> 00:01:24,750
Step number one is.

19
00:01:45,400 --> 00:01:47,710
So let's start with the step number one.

20
00:01:48,100 --> 00:01:53,290
Remember, we are going to protect this route by using the log in middleware.

21
00:01:53,350 --> 00:01:58,780
So because of that, we're going to have the log in user as req dot user.

22
00:01:58,780 --> 00:02:00,280
So here we go.

23
00:02:00,310 --> 00:02:02,590
Let's bring in the user model.

24
00:02:03,700 --> 00:02:06,170
And for this, the auto import isn't working.

25
00:02:06,190 --> 00:02:10,000
So the trick is that, again, let's go to the file.

26
00:02:10,210 --> 00:02:11,080
We save it.

27
00:02:11,110 --> 00:02:14,260
Let's come back to the file where we want to require.

28
00:02:14,260 --> 00:02:15,980
And then user is turned around.

29
00:02:16,000 --> 00:02:17,260
It is working.

30
00:02:17,830 --> 00:02:19,900
So now here we go.

31
00:02:20,500 --> 00:02:27,450
So cost as user found is equal to a weight.

32
00:02:27,460 --> 00:02:36,550
And then you bring in the user dot fine by ID and then the ID is under rec dot user.

33
00:02:37,300 --> 00:02:41,380
So if a user is not found, we are going to throw an error.

34
00:02:41,860 --> 00:02:44,070
So we need our app error class.

35
00:02:44,080 --> 00:02:54,220
So again, we need to come here and then receive it and come back to the file and let's see a we have

36
00:02:54,220 --> 00:02:56,760
the class perfect.

37
00:02:56,770 --> 00:03:05,470
So here if user is not found, that is if there is no user found then they are going to return code

38
00:03:05,470 --> 00:03:06,250
next.

39
00:03:06,430 --> 00:03:16,840
Then you pass in our error class here and they pass in the message as user not found, they pass in

40
00:03:16,840 --> 00:03:19,850
the status code as four or for many not found.

41
00:03:19,870 --> 00:03:29,350
So at this point it means that a user is found so you can go ahead and create the account as const account

42
00:03:29,350 --> 00:03:34,030
is equal to a weight and then the account model dot great.

43
00:03:34,720 --> 00:03:40,720
And for this, we're going to pass in the name the initial balance, the account type and the node and

44
00:03:40,720 --> 00:03:42,160
then the created by.

45
00:03:42,190 --> 00:03:45,670
So looking at the model, we are going to pass in these properties.

46
00:03:45,670 --> 00:03:47,620
So here we go.

47
00:03:54,920 --> 00:04:01,250
So what we need here is going to be the name of the account, the initial balance,

48
00:04:04,100 --> 00:04:06,470
and then the account type.

49
00:04:10,150 --> 00:04:12,980
And then the nodes, that description.

50
00:04:13,000 --> 00:04:23,110
So here we can pass in the name the initial balance, the account type, and then the nodes and that

51
00:04:23,110 --> 00:04:23,680
is it.

52
00:04:24,040 --> 00:04:32,170
And lastly, we need to add the user who is creating this account that is created by and we need the

53
00:04:32,170 --> 00:04:33,640
ID of the user.

54
00:04:33,670 --> 00:04:37,720
And lucky for us, we have the user and the rec dot user.

55
00:04:37,720 --> 00:04:45,780
So here we go as created by and we are going to use rec dot user and that is it.

56
00:04:45,790 --> 00:04:50,290
So for pushing, we are going to use user found dot account.

57
00:04:50,290 --> 00:04:54,010
Remember we have account on the user.

58
00:04:54,040 --> 00:04:58,690
If you check it out, this is what we want to push the account into.

59
00:04:58,720 --> 00:05:00,670
So here we go.

60
00:05:00,970 --> 00:05:09,190
It's going to be push, then we push the account dot I'd it.

61
00:05:10,090 --> 00:05:19,750
So lastly we need to save the user as a weight user found dot save a everything is perfect.

62
00:05:20,020 --> 00:05:24,820
So lastly, we can say the created account.

63
00:05:25,060 --> 00:05:30,730
So here provide the status as six six.

64
00:05:31,390 --> 00:05:36,490
And next is the actual data, which is the account.

65
00:05:36,760 --> 00:05:44,180
And for error we can pass to next as the error we need that we need to pass in the next.

66
00:05:44,200 --> 00:05:45,830
So that is it, guys.

67
00:05:45,850 --> 00:05:48,730
So next step is that we need to protect this root.

68
00:05:48,730 --> 00:05:52,060
So inside the root of account.

69
00:05:52,090 --> 00:05:55,040
This is a root of account.

70
00:05:55,060 --> 00:05:58,210
Let's bring in the log in.

71
00:05:59,320 --> 00:06:02,620
Well, again, I need to save the file again.

72
00:06:02,620 --> 00:06:06,430
Inside the metaverse is log in, save it.

73
00:06:06,460 --> 00:06:12,550
Let's go to the account and let's import it as that's a here we go.

74
00:06:12,670 --> 00:06:15,250
So this is a root I want to protect.

75
00:06:15,250 --> 00:06:18,510
So I'll provide a second element to it.

76
00:06:18,520 --> 00:06:19,660
So let's save it.

77
00:06:19,660 --> 00:06:23,010
And now let's make a request to create an account.

78
00:06:23,020 --> 00:06:28,440
So back to the tender client, let's close users and account.

79
00:06:28,450 --> 00:06:29,880
Here we go.

80
00:06:29,890 --> 00:06:33,310
Let's provide the properties you want to create.

81
00:06:33,400 --> 00:06:37,990
So here are going to be as the name of my account.

82
00:06:37,990 --> 00:06:41,110
So I'll call this one as mom's building.

83
00:06:41,200 --> 00:06:47,080
Meaning I'm building a house for my mom and I want to keep track about the expenses and the income.

84
00:06:47,200 --> 00:06:51,580
And then it's a balance I want to provide as initial

85
00:06:54,490 --> 00:06:55,300
balance.

86
00:06:55,300 --> 00:07:05,230
I will say for this one, I provide $2,000 and after that the account type for this one, make sure

87
00:07:05,230 --> 00:07:08,220
that you provide the accepted value.

88
00:07:08,230 --> 00:07:11,380
So inside the model, let's look at the account type.

89
00:07:11,410 --> 00:07:15,700
We have savings, investment, credit card and we have projects.

90
00:07:15,700 --> 00:07:21,160
So I'm going to select project here and that project.

91
00:07:23,420 --> 00:07:24,060
Great.

92
00:07:24,080 --> 00:07:38,090
And next is notes in in description about this account, let's say building a house for my sweet mother

93
00:07:41,240 --> 00:07:43,550
and that is it for the created by.

94
00:07:43,550 --> 00:07:48,410
We have access inside the controller so there is no worry about that.

95
00:07:48,410 --> 00:07:51,020
So let's hit st and let's see the result.

96
00:07:51,050 --> 00:07:56,990
A You can see I guess some error here, meaning that kind of read properties of undefined meaning that

97
00:07:56,990 --> 00:07:59,690
we are not providing the token.

98
00:07:59,690 --> 00:08:07,250
So here provide authorization and now provide the bearer and let's add some random token here and let's

99
00:08:07,250 --> 00:08:12,260
st and you can see that we have the message as invalid login.

100
00:08:12,260 --> 00:08:16,190
So let's go ahead and then log in and then grab that token.

101
00:08:16,190 --> 00:08:21,620
So we and the users here log in and let's copy this token.

102
00:08:22,730 --> 00:08:28,760
And let's go to the crate here and let's provide us that and let's hit send.

103
00:08:29,590 --> 00:08:31,150
Well, I guess I'm error.

104
00:08:31,180 --> 00:08:33,250
Let's see where the arrow is coming from.

105
00:08:33,340 --> 00:08:34,659
Oh, I got this.

106
00:08:34,690 --> 00:08:36,340
Next is not defined.

107
00:08:36,370 --> 00:08:38,020
The spelling is wrong.

108
00:08:38,350 --> 00:08:40,270
So let's get to the.

109
00:08:41,240 --> 00:08:46,910
Controllers under account and let's see where the error is coming from.

110
00:08:47,360 --> 00:08:50,180
So under account creation.

111
00:08:50,510 --> 00:08:54,280
Oh, supposed to be t I believe you guys saw it.

112
00:08:54,690 --> 00:08:57,020
Supposed to be next and not t.

113
00:08:57,020 --> 00:08:58,880
Yeah, yeah, that is it.

114
00:08:58,880 --> 00:09:01,670
So let me try again and see.

115
00:09:02,990 --> 00:09:04,340
Oh, I got some error here.

116
00:09:04,340 --> 00:09:07,160
Meaning that account type is required.

117
00:09:07,160 --> 00:09:12,440
So let's see if in providing the account type.

118
00:09:12,800 --> 00:09:17,090
Well I think I'm not destruction it inside here.

119
00:09:17,090 --> 00:09:22,820
So let's see the body where we have the account type here.

120
00:09:23,600 --> 00:09:29,240
The account type is supposed to be here, but why is it that it is not receiving that?

121
00:09:29,240 --> 00:09:30,560
So let's check the spellings.

122
00:09:30,560 --> 00:09:31,130
Well.

123
00:09:32,230 --> 00:09:34,600
Is account type.

124
00:09:36,610 --> 00:09:40,590
So I think I made some type of mistake here.

125
00:09:40,610 --> 00:09:41,100
Yeah.

126
00:09:41,110 --> 00:09:42,700
So let's say again.

127
00:09:43,880 --> 00:09:52,220
A This time around, I go by my first account that I want to keep track about the expenses and income.

128
00:09:52,610 --> 00:09:58,610
You can see that for this account there is no transaction without expenses or income, and I have the

129
00:09:58,610 --> 00:10:00,200
details about that.

130
00:10:00,440 --> 00:10:05,200
So what has left is that I can go ahead and create more account.

131
00:10:05,210 --> 00:10:09,740
So for this I will say about my education.

132
00:10:10,460 --> 00:10:13,820
So I will say that expenses

133
00:10:16,220 --> 00:10:28,580
about my education and for the initial balance I'll provide RS 1000 and this I'm going to be the education.

134
00:10:28,580 --> 00:10:35,450
So let's hit send where I got an error meaning that education is not a valid admiration.

135
00:10:35,450 --> 00:10:40,250
So let's see the type of values the account type takes.

136
00:10:40,700 --> 00:10:44,360
We don't have education inside here.

137
00:10:45,260 --> 00:10:49,220
I think I can add it right because it's really important.

138
00:10:49,520 --> 00:10:49,870
Okay.

139
00:10:49,880 --> 00:10:54,110
So let me add that one to here quickly as education.

140
00:10:54,380 --> 00:10:58,010
So save it and now let's create that one.

141
00:10:58,010 --> 00:11:02,810
And let's see a I go back my second account.

142
00:11:02,900 --> 00:11:10,520
So if I check my profile, I want to see all the account that I have created.

143
00:11:10,520 --> 00:11:14,420
So let's go to file and let's hit send.

144
00:11:14,570 --> 00:11:23,390
And this time around you can see that I have all the account that I've created, but I see the IDs.

145
00:11:23,390 --> 00:11:29,540
So the next video, let's see how we are going to populate this ID with the real object.

