feat(transaction-recurring): #135 prohibit deletion of treasure chests if referenced
All checks were successful
Build Docker Image / Build-Docker-Image (push) Successful in 5m5s
Build and Push Docker Image / Build-And-Push-Docker-Image (push) Successful in 5m13s

This commit was merged in pull request #139.
This commit is contained in:
2025-05-29 14:37:49 +02:00
parent 6219741634
commit c2b96145f3
10 changed files with 644 additions and 551 deletions

View File

@@ -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 {

View File

@@ -1,10 +0,0 @@
package service_test
// import (
// "spned-sparrow"
// )
//
// func TestTreasureChestProhibitDeleteIfTransactionRecurringExists(t *testing.T) {
// service := main.Setup
//
// }