mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 16:44:54 +00:00
fix: validate card spending limit before transfering to child
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user