wip
This commit is contained in:
@@ -41,6 +41,7 @@ func (s Dashboard) Summary(ctx context.Context, user *types.User, month time.Tim
|
|||||||
WHERE user_id = $1
|
WHERE user_id = $1
|
||||||
AND value > 0
|
AND value > 0
|
||||||
AND account_id IS NOT NULL
|
AND account_id IS NOT NULL
|
||||||
|
AND treasure_chest_id IS NULL
|
||||||
AND error IS NULL
|
AND error IS NULL
|
||||||
AND date_trunc('month', date) = date_trund('month', $2)`,
|
AND date_trunc('month', date) = date_trund('month', $2)`,
|
||||||
user.Id, month)
|
user.Id, month)
|
||||||
@@ -51,6 +52,7 @@ func (s Dashboard) Summary(ctx context.Context, user *types.User, month time.Tim
|
|||||||
WHERE user_id = $1
|
WHERE user_id = $1
|
||||||
AND value > 0
|
AND value > 0
|
||||||
AND treasure_chest_id IS NOT NULL
|
AND treasure_chest_id IS NOT NULL
|
||||||
|
AND account_id IS NULL
|
||||||
AND error IS NULL
|
AND error IS NULL
|
||||||
AND date_trunc('month', date) = date_trund('month', $2)`,
|
AND date_trunc('month', date) = date_trund('month', $2)`,
|
||||||
user.Id, month)
|
user.Id, month)
|
||||||
|
|||||||
@@ -512,27 +512,31 @@ func (s TransactionImpl) validateAndEnrichTransaction(ctx context.Context, tx *s
|
|||||||
return &transaction, nil
|
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 := ""
|
errorStr := ""
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case transaction.Value < 0:
|
case (t.AccountId != nil && t.TreasureChestId != nil && t.Value > 0) ||
|
||||||
if transaction.TreasureChestId == nil {
|
(t.AccountId == nil && t.TreasureChestId == nil):
|
||||||
errorStr = "no treasure chest specified"
|
errorStr = "either an account or a treasure chest needs to be specified"
|
||||||
}
|
case t.Value == 0:
|
||||||
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:
|
|
||||||
errorStr = "\"value\" needs to be specified"
|
errorStr = "\"value\" needs to be specified"
|
||||||
}
|
}
|
||||||
|
|
||||||
if errorStr == "" {
|
if errorStr == "" {
|
||||||
transaction.Error = nil
|
t.Error = nil
|
||||||
} else {
|
} else {
|
||||||
transaction.Error = &errorStr
|
t.Error = &errorStr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user