fix: validate card spending limit before transfering to child

This commit is contained in:
Abdalhameed Ahmad
2025-09-07 21:18:49 +03:00
parent d768da70f2
commit 15a48e4884
10 changed files with 75 additions and 2 deletions

View File

@ -119,6 +119,11 @@ export class CardService {
@Transactional()
async transferToChild(juniorId: string, amount: number) {
const card = await this.getCardByCustomerId(juniorId);
const availableSpendingLimit = await this.transactionService.calculateAvailableSpendingLimitForParent(card.account);
if (amount > availableSpendingLimit) {
throw new BadRequestException('CARD.INSUFFICIENT_BALANCE');
}
const finalAmount = Decimal(amount).plus(card.limit);
await Promise.all([
@ -129,4 +134,8 @@ export class CardService {
return finalAmount.toNumber();
}
fundIban(iban: string, amount: number) {
return this.accountService.fundIban(iban, amount);
}
}