mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 08:34:55 +00:00
fix: calculating child and parent balance
This commit is contained in:
@ -49,9 +49,11 @@ export class AccountService {
|
||||
|
||||
async decreaseAccountBalance(accountReference: string, amount: number) {
|
||||
const account = await this.getAccountByReferenceNumber(accountReference);
|
||||
|
||||
/**
|
||||
*
|
||||
* While there is no need to check for insufficient balance because this is a webhook handler,
|
||||
* I just added this check to ensure we don't have corruption in our data especially if this service is used elsewhere.
|
||||
* I just added this check to ensure we don't have corruption in our data.
|
||||
*/
|
||||
|
||||
if (account.balance < amount) {
|
||||
@ -61,6 +63,17 @@ export class AccountService {
|
||||
return this.accountRepository.decreaseAccountBalance(accountReference, amount);
|
||||
}
|
||||
|
||||
increaseReservedBalance(account: Account, amount: number) {
|
||||
if (account.balance < account.reservedBalance + amount) {
|
||||
throw new UnprocessableEntityException('ACCOUNT.INSUFFICIENT_BALANCE');
|
||||
}
|
||||
return this.accountRepository.increaseReservedBalance(account.id, amount);
|
||||
}
|
||||
|
||||
decrementReservedBalance(account: Account, amount: number) {
|
||||
return this.accountRepository.decreaseReservedBalance(account.id, amount);
|
||||
}
|
||||
|
||||
//THIS IS A MOCK FUNCTION FOR TESTING PURPOSES ONLY
|
||||
async fundIban(iban: string, amount: number) {
|
||||
const account = await this.getAccountByIban(iban);
|
||||
|
||||
Reference in New Issue
Block a user