mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 16:44:54 +00:00
fix: calculating child and parent balance
This commit is contained in:
@ -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),
|
||||
]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user