feat(transaction-recurring): #135 prohibit deletion of treasure chests if referenced
This commit was merged in pull request #139.
This commit is contained in:
@@ -268,6 +268,18 @@ func (s TreasureChestImpl) Delete(user *types.User, idStr string) error {
|
||||
return fmt.Errorf("treasure chest has transactions: %w", ErrBadRequest)
|
||||
}
|
||||
|
||||
recurringCount := 0
|
||||
err = tx.Get(&recurringCount, `
|
||||
SELECT COUNT(*) FROM transaction_recurring WHERE user_id = ? AND treasure_chest_id = ?`,
|
||||
user.Id, id)
|
||||
err = db.TransformAndLogDbError("treasureChest Delete", nil, err)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if recurringCount > 0 {
|
||||
return fmt.Errorf("cannot delete treasure chest with existing recurring transactions: %w", ErrBadRequest)
|
||||
}
|
||||
|
||||
r, err := tx.Exec(`DELETE FROM treasure_chest WHERE id = ? AND user_id = ?`, id, user.Id)
|
||||
err = db.TransformAndLogDbError("treasureChest Delete", r, err)
|
||||
if err != nil {
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package service_test
|
||||
|
||||
// import (
|
||||
// "spned-sparrow"
|
||||
// )
|
||||
//
|
||||
// func TestTreasureChestProhibitDeleteIfTransactionRecurringExists(t *testing.T) {
|
||||
// service := main.Setup
|
||||
//
|
||||
// }
|
||||
Reference in New Issue
Block a user