diff --git a/internal/service/dashboard.go b/internal/service/dashboard.go index f5eb770..51e53d6 100644 --- a/internal/service/dashboard.go +++ b/internal/service/dashboard.go @@ -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) diff --git a/internal/service/transaction.go b/internal/service/transaction.go index d47d9da..22ce975 100644 --- a/internal/service/transaction.go +++ b/internal/service/transaction.go @@ -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 { - 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.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" + 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 } }