Refactor balance check in increaseReservedBalance method to delegate validation to the caller, improving clarity and responsibility separation.

This commit is contained in:
Abdalhamid Alhamad
2025-11-02 12:41:16 +03:00
parent d6fb5f48d9
commit 2172051093

View File

@ -64,9 +64,8 @@ export class AccountService {
} }
increaseReservedBalance(account: Account, amount: number) { increaseReservedBalance(account: Account, amount: number) {
if (account.balance < account.reservedBalance + amount) { // Balance check is performed by the caller (e.g., transferToChild)
throw new UnprocessableEntityException('CARD.INSUFFICIENT_BALANCE'); // to ensure correct account (guardian vs child) is validated
}
return this.accountRepository.increaseReservedBalance(account.id, amount); return this.accountRepository.increaseReservedBalance(account.id, amount);
} }