[server] validate bonus reversal

This commit is contained in:
Neeraj Gupta
2024-11-19 10:24:58 +05:30
parent bd33bec3e6
commit 641a73c101

View File

@@ -3,6 +3,8 @@ package storagebonus
import (
"context"
"fmt"
"github.com/ente-io/museum/ente"
"github.com/ente-io/museum/ente/storagebonus"
)
@@ -27,7 +29,15 @@ func (r *Repository) RemoveAddOnBonus(ctx context.Context, bonusType storagebonu
if err != nil {
return 0, err
}
return res.RowsAffected()
// verify if the bonus was removed
rowsAffected, err := res.RowsAffected()
if err != nil {
return 0, err
}
if rowsAffected == int64(0) {
return 0, ente.NewBadRequestWithMessage(fmt.Sprintf("bonus not found for user %d with bonusID %s", userID, bonusID))
}
return rowsAffected, nil
}
func (r *Repository) UpdateAddOnBonus(ctx context.Context, bonusType storagebonus.BonusType, userID int64, validTill int64, storage int64) error {