feat(dashboard): #162 include total sum of accounts compared to total savings
This commit was merged in pull request #185.
This commit is contained in:
@@ -81,5 +81,31 @@ func (s Dashboard) Summary(ctx context.Context, user *types.User, month time.Tim
|
||||
summary.Total = summary.Income + summary.Expenses
|
||||
summary.Month = month
|
||||
|
||||
err = s.db.GetContext(ctx, &value, `
|
||||
SELECT SUM(current_balance)
|
||||
FROM treasure_chest
|
||||
WHERE user_id = $1`,
|
||||
user.Id)
|
||||
err = db.TransformAndLogDbError("dashboard", nil, err)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if value != nil {
|
||||
summary.SumOfSavings = *value
|
||||
}
|
||||
|
||||
err = s.db.GetContext(ctx, &value, `
|
||||
SELECT SUM(current_balance)
|
||||
FROM account
|
||||
WHERE user_id = $1`,
|
||||
user.Id)
|
||||
err = db.TransformAndLogDbError("dashboard", nil, err)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if value != nil {
|
||||
summary.SumOfAccounts = *value
|
||||
}
|
||||
|
||||
return &summary, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user