diff --git a/src/card/services/card.service.ts b/src/card/services/card.service.ts index 5c2dc4e..4cb0a51 100644 --- a/src/card/services/card.service.ts +++ b/src/card/services/card.service.ts @@ -148,11 +148,18 @@ export class CardService { async transferToChild(juniorId: string, amount: number) { const card = await this.getCardByCustomerId(juniorId); + this.logger.debug(`Transfer to child - juniorId: ${juniorId}, parentId: ${card.parentId}, cardId: ${card.id}`); + this.logger.debug(`Card account - balance: ${card.account.balance}, reserved: ${card.account.reservedBalance}`); + const fundingAccount = card.parentId ? await this.accountService.getAccountByCustomerId(card.parentId) : card.account; + this.logger.debug(`Funding account - balance: ${fundingAccount.balance}, reserved: ${fundingAccount.reservedBalance}, available: ${fundingAccount.balance - fundingAccount.reservedBalance}`); + this.logger.debug(`Amount requested: ${amount}`); + if (amount > fundingAccount.balance - fundingAccount.reservedBalance) { + this.logger.error(`Insufficient balance - requested: ${amount}, available: ${fundingAccount.balance - fundingAccount.reservedBalance}`); throw new BadRequestException('CARD.INSUFFICIENT_BALANCE'); }