fix: calculating child and parent balance

This commit is contained in:
Abdalhameed Ahmad
2025-09-09 20:31:48 +03:00
parent e1f50decfa
commit 039c95aa56
12 changed files with 83 additions and 26 deletions

View File

@ -49,6 +49,7 @@ export class CardService {
parentCustomer.cards[0].account.id,
data,
cardColor,
true,
);
return this.getCardById(createdCard.id);
@ -87,6 +88,7 @@ export class CardService {
if (!card) {
throw new BadRequestException('CARD.NOT_FOUND');
}
return card;
}
@ -119,9 +121,8 @@ 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) {
if (amount > card.account.balance - card.account.reservedBalance) {
throw new BadRequestException('CARD.INSUFFICIENT_BALANCE');
}
@ -129,6 +130,7 @@ export class CardService {
await Promise.all([
this.neoleapService.updateCardControl(card.cardReference, finalAmount.toNumber()),
this.updateCardLimit(card.id, finalAmount.toNumber()),
this.accountService.increaseReservedBalance(card.account, amount),
this.transactionService.createInternalChildTransaction(card.id, amount),
]);