Merge branch 'development' into 'devops-staging'

add: add validation if saldo not enough

See merge request empatnusabangsa/ppob/ppob-backend!39
This commit is contained in:
ilham dwi pratama 2021-12-20 05:19:58 +00:00
commit a44166f1a2

View File

@ -144,6 +144,21 @@ export class TransactionService {
}
// GET COA
const coaBudget = await this.coaService.findByName(
`${coaType[coaType.BUDGET]}-${supplier.code}`,
);
if (coaBudget.amount < distributeTransactionDto.amount) {
throw new HttpException(
{
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
error: `Transaction Failed because saldo not enough`,
},
HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const coaContraBudget = await this.coaService.findByName(
`${coaType[coaType.CONTRA_BUDGET]}-${supplier.code}`,
);
const coaAR = await this.coaService.findByTwoUser(
distributeTransactionDto.destination,
currentUser.userId,
@ -153,13 +168,6 @@ export class TransactionService {
distributeTransactionDto.destination,
coaType.WALLET,
);
const coaBudget = await this.coaService.findByName(
`${coaType[coaType.BUDGET]}-${supplier.code}`,
);
const coaContraBudget = await this.coaService.findByName(
`${coaType[coaType.CONTRA_BUDGET]}-${supplier.code}`,
);
await this.connection.transaction(async (manager) => {
//INSERT TRANSACTION
@ -238,6 +246,16 @@ export class TransactionService {
coaType.ACCOUNT_RECEIVABLE,
);
if (coaSenderWallet.amount < distributeTransactionDto.amount) {
throw new HttpException(
{
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
error: `Transaction Failed because saldo not enough`,
},
HttpStatus.INTERNAL_SERVER_ERROR,
);
}
await this.connection.transaction(async (manager) => {
const transactionData = new Transactions();