Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions __tests__/expenses.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,9 @@ describe('PUT /api/expenses/:id', () => {
expect(response3.statusCode).toBe(200);

expect(response2.body).toHaveProperty('availableBalance', 0);
expect(response2.body).toHaveProperty('totalBalance', 0);
expect(response2.body).toHaveProperty('investedAmount', 0);
expect(response3.body).toHaveProperty('availableBalance', -testExpenseData.amount);
expect(response3.body).toHaveProperty('totalBalance', -testExpenseData.amount);
expect(response3.body).toHaveProperty('investedAmount', 0);

});

Expand Down
4 changes: 2 additions & 2 deletions __tests__/incomes.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ describe('PUT /api/incomes/:id', () => {
expect(response3.statusCode).toBe(200);

expect(response2.body).toHaveProperty('availableBalance', 0);
expect(response2.body).toHaveProperty('totalBalance', 0);
expect(response2.body).toHaveProperty('investedAmount', 0);
expect(response3.body).toHaveProperty('availableBalance', testIncomeData.amount);
expect(response3.body).toHaveProperty('totalBalance', testIncomeData.amount);
expect(response3.body).toHaveProperty('investedAmount', 0);

});

Expand Down
10 changes: 6 additions & 4 deletions src/controllers/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const findAllAccountsByUserID = async (req, res) => {
const userId = req.params.uid;
const archived = !!req.query.archived;

const user = await User.findById(userId, 'accounts._id accounts.name accounts.totalBalance accounts.availableBalance accounts.startOfMonth accounts.archived');
const user = await User.findById(userId, 'accounts._id accounts.name accounts.investedAmount accounts.availableBalance accounts.startOfMonth accounts.archived');

if (!user) {
return res.status(404).json({
Expand Down Expand Up @@ -67,7 +67,6 @@ const createAccount = async (req, res) => {

let newAccount = {
name: req.body.name || "New Account",
totalBalance: 0,
availableBalance: 0,
budgets: [],
goals: [],
Expand All @@ -80,7 +79,7 @@ const createAccount = async (req, res) => {
// Finds user and appends newAccount to the accounts array, then returns the new account
const user = await User.findByIdAndUpdate(req.params.uid, {$push: {accounts: newAccount}}, {
new: true,
select: 'accounts._id accounts.name accounts.totalBalance accounts.availableBalance accounts.startOfMonth'
select: 'accounts._id accounts.name accounts.investedAmount accounts.availableBalance accounts.startOfMonth'
});

if (!user) {
Expand Down Expand Up @@ -126,6 +125,9 @@ const deleteAccountByID = async (req, res) => {
// Delete account's expenses from db
await deleteUserEntries.deleteExpenses("accountID", req.params.id);

// Delete account's investments from db
await deleteUserEntries.deleteInvestments("accountID", req.params.id);

res.status(200).json(user);

} catch (error) {
Expand All @@ -149,7 +151,7 @@ const updateAccountByID = async (req, res) => {

try {
// Find the user with the requested account
const user = await User.findOne({'accounts._id': req.params.id}, 'accounts._id accounts.name accounts.startOfMonth accounts.totalBalance accounts.availableBalance');
const user = await User.findOne({'accounts._id': req.params.id}, 'accounts._id accounts.name accounts.startOfMonth accounts.investedAmount accounts.availableBalance');

if (!user) {
return res.status(404).json({
Expand Down
Loading
Loading