mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 00:24:54 +00:00
Merge pull request #57 from HamzaSha1/money-request-to-use-the-parint-account
Money request to use the parint account
This commit is contained in:
@ -148,7 +148,11 @@ export class CardService {
|
||||
async transferToChild(juniorId: string, amount: number) {
|
||||
const card = await this.getCardByCustomerId(juniorId);
|
||||
|
||||
if (amount > card.account.balance - card.account.reservedBalance) {
|
||||
const fundingAccount = card.parentId
|
||||
? await this.accountService.getAccountByCustomerId(card.parentId)
|
||||
: card.account;
|
||||
|
||||
if (amount > fundingAccount.balance - fundingAccount.reservedBalance) {
|
||||
throw new BadRequestException('CARD.INSUFFICIENT_BALANCE');
|
||||
}
|
||||
|
||||
@ -156,7 +160,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.accountService.increaseReservedBalance(fundingAccount, amount),
|
||||
this.transactionService.createInternalChildTransaction(card.id, amount),
|
||||
]);
|
||||
|
||||
|
||||
@ -42,10 +42,18 @@ export class TransactionService {
|
||||
const total = new Decimal(body.transactionAmount).plus(body.billingAmount).plus(body.fees).plus(body.vatOnFees);
|
||||
|
||||
if (card.customerType === CustomerType.CHILD) {
|
||||
if (card.parentId) {
|
||||
const parentAccount = await this.accountService.getAccountByCustomerId(card.parentId);
|
||||
await Promise.all([
|
||||
this.accountService.decreaseAccountBalance(parentAccount.accountReference, total.toNumber()),
|
||||
this.accountService.decrementReservedBalance(parentAccount, total.toNumber()),
|
||||
]);
|
||||
} else {
|
||||
await Promise.all([
|
||||
this.accountService.decreaseAccountBalance(card.account.accountReference, total.toNumber()),
|
||||
this.accountService.decrementReservedBalance(card.account, total.toNumber()),
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
await this.accountService.decreaseAccountBalance(card.account.accountReference, total.toNumber());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user