This commit is contained in:
2025-06-13 23:50:39 +02:00
parent 2a6f96d787
commit b6299ad527
2 changed files with 20 additions and 14 deletions

View File

@@ -41,6 +41,7 @@ func (s Dashboard) Summary(ctx context.Context, user *types.User, month time.Tim
WHERE user_id = $1
AND value > 0
AND account_id IS NOT NULL
AND treasure_chest_id IS NULL
AND error IS NULL
AND date_trunc('month', date) = date_trund('month', $2)`,
user.Id, month)
@@ -51,6 +52,7 @@ func (s Dashboard) Summary(ctx context.Context, user *types.User, month time.Tim
WHERE user_id = $1
AND value > 0
AND treasure_chest_id IS NOT NULL
AND account_id IS NULL
AND error IS NULL
AND date_trunc('month', date) = date_trund('month', $2)`,
user.Id, month)

View File

@@ -512,27 +512,31 @@ func (s TransactionImpl) validateAndEnrichTransaction(ctx context.Context, tx *s
return &transaction, nil
}
func (s TransactionImpl) updateErrors(transaction *types.Transaction) {
// There are the following constallations and their explanation:
//
// Account | TreasureChest | Value | Description
// Y | Y | + | Invalid
// Y | Y | - | Bought a good
// Y | N | + | Income
// Y | N | - | For moving money between accounts
// N | Y | + | Saving
// N | Y | - | For moving money between treasure chests
// N | N | + | Invalid
// N | N | - | Invalid
func (s TransactionImpl) updateErrors(t *types.Transaction) {
errorStr := ""
switch {
case transaction.Value < 0:
if transaction.TreasureChestId == nil {
errorStr = "no treasure chest specified"
}
case transaction.Value > 0:
if transaction.AccountId == nil && transaction.TreasureChestId == nil {
case (t.AccountId != nil && t.TreasureChestId != nil && t.Value > 0) ||
(t.AccountId == nil && t.TreasureChestId == nil):
errorStr = "either an account or a treasure chest needs to be specified"
} else if transaction.AccountId != nil && transaction.TreasureChestId != nil {
errorStr = "positive amounts can only be applied to either an account or a treasure chest"
}
default:
case t.Value == 0:
errorStr = "\"value\" needs to be specified"
}
if errorStr == "" {
transaction.Error = nil
t.Error = nil
} else {
transaction.Error = &errorStr
t.Error = &errorStr
}
}