1
00:00:07,380 --> 00:00:08,520
In this video.

2
00:00:08,520 --> 00:00:13,500
Let's go ahead and create a transaction for a specific account.

3
00:00:13,620 --> 00:00:19,110
Let's say that we want to keep track about expenses for a particular account.

4
00:00:19,110 --> 00:00:23,500
Let's say building a house for my mom or mom's building.

5
00:00:23,520 --> 00:00:27,250
So let's see how we're going to create a transaction for that.

6
00:00:27,270 --> 00:00:35,040
So inside the controller is definitely we may need the controller for transaction and here we go and

7
00:00:35,040 --> 00:00:40,280
we may need the account, the user and then the transaction.

8
00:00:40,290 --> 00:00:42,890
You may need these three models.

9
00:00:42,900 --> 00:00:48,810
So let's go ahead and require those models and I'll explain to you when we need it.

10
00:00:48,840 --> 00:00:52,620
So the user model here again, let's go to the file.

11
00:00:52,650 --> 00:00:58,200
We save it and now less import it here as user.

12
00:01:00,980 --> 00:01:01,640
Great.

13
00:01:01,670 --> 00:01:05,019
Next one, I'm going to be the account again.

14
00:01:05,030 --> 00:01:06,620
Let's go to the model.

15
00:01:06,650 --> 00:01:11,110
Save it and now let's require it here as account.

16
00:01:11,120 --> 00:01:11,900
Perfect.

17
00:01:11,960 --> 00:01:21,470
And lastly, is the actual transaction, save it and let's require it as transaction A, we have all

18
00:01:21,470 --> 00:01:22,370
the models.

19
00:01:22,520 --> 00:01:23,630
So perfect.

20
00:01:23,630 --> 00:01:28,520
Let's collapse this one and let's collapse the user in the account.

21
00:01:28,520 --> 00:01:32,780
Let's take to the transaction and then the transaction controller.

22
00:01:33,020 --> 00:01:35,480
So let's lay out these steps here.

23
00:01:59,920 --> 00:02:00,550
Perfect.

24
00:02:00,820 --> 00:02:03,550
So let's start with a fine user.

25
00:02:03,640 --> 00:02:07,500
Remember, we can get an idea of the user and request that user.

26
00:02:07,510 --> 00:02:08,620
So here we go.

27
00:02:08,710 --> 00:02:20,560
Cost user found is equal to await the user model dot by ID they pass in the red dot user.

28
00:02:21,160 --> 00:02:25,190
Step number two is you want to find the account.

29
00:02:25,210 --> 00:02:27,730
How are you going to do that one?

30
00:02:27,910 --> 00:02:33,220
Well, we can get a count from the request object.

31
00:02:33,730 --> 00:02:38,460
The other option is that we can get a count from the user found.

32
00:02:38,470 --> 00:02:40,180
But here is a problem.

33
00:02:40,180 --> 00:02:44,740
Remember on the user found, we are saving a race of account.

34
00:02:44,740 --> 00:02:47,320
So what account are we going to retrieve?

35
00:02:47,620 --> 00:02:55,810
Well, so to make it pretty easy, I want to pass the ID of the account as params or as a request body.

36
00:02:55,810 --> 00:03:01,270
So I'll prefer to pass it from the request body than from the URL.

37
00:03:01,270 --> 00:03:02,980
So here we go.

38
00:03:03,100 --> 00:03:09,820
So let's structure the payload from the request object as that request, that body.

39
00:03:11,290 --> 00:03:19,390
And for this one we need the name of the transaction, the amount of the transaction, and then the

40
00:03:19,390 --> 00:03:26,380
type of transaction and then the nodes by the transaction and then the transaction type.

41
00:03:29,230 --> 00:03:29,910
Great.

42
00:03:29,920 --> 00:03:31,240
So here we go.

43
00:03:31,480 --> 00:03:37,090
Let's find the accounts as account found.

44
00:03:41,320 --> 00:03:51,210
Is equal to await a count dirt find by id a the account.

45
00:03:51,220 --> 00:03:54,730
I want to send the ID as an account.

46
00:03:54,730 --> 00:03:56,440
So that is it.

47
00:03:56,470 --> 00:04:01,050
Let's also structure that from the request body as account.

48
00:04:01,060 --> 00:04:09,010
So for this one, in case there is no user, we can go ahead and then through an error as that meaning

49
00:04:09,010 --> 00:04:10,990
that user not found.

50
00:04:10,990 --> 00:04:13,350
So we may need the app error.

51
00:04:13,360 --> 00:04:17,140
So let's go ahead and then receive it so that we can acquire it.

52
00:04:17,140 --> 00:04:23,860
So inside the transaction controller here, let's bring in the app error.

53
00:04:25,210 --> 00:04:25,930
Perfect.

54
00:04:26,440 --> 00:04:27,850
So here you go.

55
00:04:28,330 --> 00:04:34,990
If user is not found, we can return and then we are going to call next.

56
00:04:35,410 --> 00:04:39,040
So let's provide next as a third element.

57
00:04:41,110 --> 00:04:45,640
And for next we're going to create instance of our error plus.

58
00:04:48,040 --> 00:04:53,500
They pass in the message as user note found.

59
00:04:53,590 --> 00:04:56,680
They pass in the status code as 404.

60
00:04:57,760 --> 00:05:00,330
So the same thing for the account.

61
00:05:00,340 --> 00:05:03,160
We can also check so I can copy this one.

62
00:05:03,160 --> 00:05:11,500
And here let's check meaning that if account is not found, you will see that account not found.

63
00:05:11,590 --> 00:05:15,450
So below here, let's go ahead and create our transaction.

64
00:05:15,460 --> 00:05:26,530
So once the transaction is equal to wait, then the transaction don't create the pass in the payload

65
00:05:26,530 --> 00:05:31,240
as the amount of that, the type of transaction.

66
00:05:31,630 --> 00:05:41,710
After that, the node where the transaction and then the account and then the transaction type and then

67
00:05:41,710 --> 00:05:45,940
the category need to specify that one to and name.

68
00:05:46,150 --> 00:05:49,540
Let's provide the category as here.

69
00:05:50,800 --> 00:05:51,760
So.

70
00:05:54,210 --> 00:05:58,410
So you would be thinking the difference between the type and transaction type.

71
00:05:58,410 --> 00:06:00,330
So let's see more about that.

72
00:06:00,510 --> 00:06:03,540
We have the name transaction type.

73
00:06:04,680 --> 00:06:05,150
Yeah.

74
00:06:05,160 --> 00:06:06,410
So let's remove the type.

75
00:06:06,420 --> 00:06:07,440
There is no type.

76
00:06:07,470 --> 00:06:09,230
It is transaction type.

77
00:06:09,240 --> 00:06:12,330
So let's remove this one and remove this one.

78
00:06:12,960 --> 00:06:13,740
Yes.

79
00:06:13,980 --> 00:06:22,140
So this what we want to create next step is that let's push the transaction to the account found as

80
00:06:22,140 --> 00:06:24,990
transactions dot push.

81
00:06:27,200 --> 00:06:33,350
And I'm going to push the transaction, created dirt and score it.

82
00:06:33,620 --> 00:06:44,120
Lastly, let's receive the account found as dot C and let's go ahead and send the response to the user.

83
00:06:44,390 --> 00:06:51,800
So here is going to be status here and then you're going to be success.

84
00:06:51,800 --> 00:06:57,440
And we need this one in the front end and in data as transaction.

85
00:06:58,010 --> 00:06:59,480
Moment of truth.

86
00:06:59,660 --> 00:07:03,100
So let's get back to the root.

87
00:07:03,110 --> 00:07:07,970
So here and that transaction, which is this one.

88
00:07:08,730 --> 00:07:09,460
Great.

89
00:07:09,470 --> 00:07:11,600
So let's provide the payload.

90
00:07:12,430 --> 00:07:14,770
Definitely you may need the token.

91
00:07:14,770 --> 00:07:18,460
So let's go to look in and now let's copy the token.

92
00:07:20,050 --> 00:07:31,600
And inside the route of transaction crates and the headers here, let's add the authorization and then

93
00:07:32,740 --> 00:07:37,690
barer and paste it to Queen and let's provide the body.

94
00:07:38,020 --> 00:07:40,000
So here we go.

95
00:07:40,540 --> 00:07:47,530
The name of the transaction, I would say bind roofing sheet.

96
00:07:51,940 --> 00:07:55,030
And this way I'm going to be the transaction type.

97
00:07:58,030 --> 00:08:04,100
And for this, let's see, the types is going to be income or expenses.

98
00:08:04,120 --> 00:08:13,860
So for this one, I'm going to be expenses as that is x pane sis.

99
00:08:13,870 --> 00:08:19,900
So the next property is going to be the note, meaning the description about that.

100
00:08:25,730 --> 00:08:26,330
Great.

101
00:08:26,540 --> 00:08:31,760
In this way, I'm going to be the account that we want to create the transaction for.

102
00:08:31,910 --> 00:08:41,390
So if you go to the transaction, sorry, the account, which is this one, so here I think we can implement

103
00:08:41,390 --> 00:08:42,970
a route to fetch or account.

104
00:08:42,980 --> 00:08:46,310
So let's do the one quickly before we get back to that.

105
00:08:46,400 --> 00:08:52,100
So inside the account controller here is going to be pretty simple to fetch all.

106
00:08:52,130 --> 00:08:53,720
So here are going to be the get.

107
00:08:53,720 --> 00:08:54,590
All right.

108
00:08:54,590 --> 00:09:04,520
So you're going to make a request as cost and then account is account is equal to a weight and then

109
00:09:04,520 --> 00:09:08,270
the account dot find as that.

110
00:09:08,270 --> 00:09:12,110
And let's say the account I want to see.

111
00:09:13,070 --> 00:09:14,240
Okay, so save it.

112
00:09:14,240 --> 00:09:18,100
And now let's get back to the account.

113
00:09:18,110 --> 00:09:20,090
Let's fetch all the accounts.

114
00:09:20,090 --> 00:09:22,820
That is where is my account.

115
00:09:23,570 --> 00:09:24,770
Transaction account.

116
00:09:24,770 --> 00:09:25,850
So fetch all.

117
00:09:27,000 --> 00:09:35,280
So I copy this one for my mom's Jordan and then inside the crate I provide as an ID to the account.

118
00:09:36,060 --> 00:09:44,550
And next is going to be the category for that as category and for the category.

119
00:09:44,550 --> 00:09:46,470
Let's see what we have.

120
00:09:46,770 --> 00:09:50,710
We have food, utility, personal shopping.

121
00:09:50,760 --> 00:09:56,130
I think we can use project or building.

122
00:09:56,130 --> 00:09:58,650
Let's add billion also in the mix here.

123
00:09:59,850 --> 00:10:00,000
Great.

124
00:10:00,120 --> 00:10:10,200
So I can specify it here as a payload so category going to be built and I think your is the name transaction

125
00:10:10,200 --> 00:10:11,250
node account.

126
00:10:11,250 --> 00:10:12,870
And then yeah.

127
00:10:12,870 --> 00:10:17,340
So let's say and let's see what we like now we are going to see the error.

128
00:10:17,910 --> 00:10:25,500
So let's check it out and let's see where we can see that user not found, meaning that I'm not passing

129
00:10:25,500 --> 00:10:27,240
the slogan material.

130
00:10:27,270 --> 00:10:33,120
Let's go to the transaction route here and let's bring in the log image.

131
00:10:33,420 --> 00:10:43,440
So here is a mature save it and now let's get to the transaction roots and let's require it is logged

132
00:10:43,440 --> 00:10:43,950
in.

133
00:10:44,160 --> 00:10:48,840
So here we go then I'll put it here and has that.

134
00:10:48,840 --> 00:10:56,940
So let's send the request again and let's see this time around the token is not valid, so let's log

135
00:10:56,940 --> 00:10:58,020
in again.

136
00:10:58,740 --> 00:11:01,950
And the users, I think it has expired.

137
00:11:01,950 --> 00:11:11,670
So log in and now let's copy this one and let's go to the transaction, create and the headers.

138
00:11:11,670 --> 00:11:16,770
Let's copy this one and paste it here and let's send.

139
00:11:17,600 --> 00:11:25,580
And you can see when providing the amount sometimes is how I do it because I want to know a feel which

140
00:11:25,580 --> 00:11:29,090
I forgot to provide and when to be the amount.

141
00:11:29,450 --> 00:11:33,050
So here I provide ice $5,000.

142
00:11:33,320 --> 00:11:35,440
And I think that's all what we need.

143
00:11:35,450 --> 00:11:35,950
Yeah.

144
00:11:35,960 --> 00:11:44,510
So let's send a, we have our transaction being added to our account, but we are lacking something,

145
00:11:44,510 --> 00:11:47,860
meaning the user who created this transaction.

146
00:11:47,870 --> 00:11:53,390
So it means that on the field we are not making use of required.

147
00:11:53,390 --> 00:11:53,870
Yes.

148
00:11:53,870 --> 00:11:56,990
So let's make it a required field to true.

149
00:11:57,410 --> 00:12:04,850
So if I try to create again, I'm not providing the user, so I'll get an error and there you go.

150
00:12:04,850 --> 00:12:06,830
So let's go ahead and provide it.

151
00:12:06,830 --> 00:12:14,180
So inside the transaction controller, let's add the created by and we can get it for rec dot user.

152
00:12:14,360 --> 00:12:15,080
Perfect.

153
00:12:15,080 --> 00:12:21,260
So now we are able to create a transaction for a specific account.

154
00:12:21,530 --> 00:12:28,400
So let's go ahead and then fetch our account and let's see if we have a transaction for that which is

155
00:12:28,400 --> 00:12:28,940
this one.

156
00:12:28,940 --> 00:12:33,320
So let's get st and let's see and here we go.

157
00:12:33,320 --> 00:12:40,070
You can see that for this account called Month Building, I've added one transaction.

158
00:12:40,190 --> 00:12:45,980
So to be able to get the actual data we are going to use populate on that.

159
00:12:46,310 --> 00:12:56,840
So let's go to the account and getting all we are going to use the populates to provide the transactions,

160
00:12:57,980 --> 00:13:03,500
save it and now let's make a request again and let's see the magic.

161
00:13:03,590 --> 00:13:06,770
And there we go, guys.

162
00:13:07,280 --> 00:13:13,400
We can see we have a building account with this transaction.

163
00:13:13,700 --> 00:13:15,890
The transaction is expenses.

164
00:13:15,890 --> 00:13:20,510
So let's go ahead and also add one more transaction.

165
00:13:20,510 --> 00:13:25,760
So inside this one and a transaction, let's go ahead and add one more.

166
00:13:25,760 --> 00:13:33,320
This time around, you're going to be income and I would see funding.

167
00:13:35,050 --> 00:13:36,130
The project.

168
00:13:36,520 --> 00:13:37,300
So.

169
00:13:37,300 --> 00:13:40,840
And note I will say.

170
00:13:42,860 --> 00:13:49,010
Salary for funding this project.

171
00:13:49,910 --> 00:13:53,630
Eh, let's get sent and let's check it out.

172
00:13:53,720 --> 00:13:55,780
And here we go.

173
00:13:55,790 --> 00:13:58,010
We have back the transaction.

174
00:13:58,010 --> 00:14:01,100
So if you fetch all account, let's see.

175
00:14:01,190 --> 00:14:05,690
You can see that for this particular account, we have two transactions.

176
00:14:05,690 --> 00:14:12,770
One is this one and then the other one is this one, which is funding the project with amount and then

177
00:14:12,770 --> 00:14:15,320
transaction type going to be income.

178
00:14:15,530 --> 00:14:21,530
So now I can tell you that we are done with the entire project API creation.

179
00:14:21,770 --> 00:14:28,670
So what has let is about the crowd operation for example, deleting, updating and that one to isn't

180
00:14:28,670 --> 00:14:29,720
that difficult.

