fix: transaction order product

This commit is contained in:
ilham
2021-12-31 00:59:49 +07:00
parent d66e6eed93
commit a30a81cbb6
2 changed files with 35 additions and 6 deletions

View File

@@ -10,7 +10,12 @@ import { CoaService } from './coa.service';
import * as uuid from 'uuid';
import { uniq } from 'lodash';
import { Decimal } from 'decimal.js';
import { balanceType, coaType, statusTransaction, typeTransaction } from '../helper/enum-list';
import {
balanceType,
coaType,
statusTransaction,
typeTransaction,
} from '../helper/enum-list';
import { ProductService } from '../product/product.service';
import { CreateJournalDto } from './dto/create-journal.dto';
import { UsersService } from 'src/users/users.service';
@@ -362,7 +367,10 @@ export class TransactionService {
]);
}
if (coaAccount.amount <= product.price) {
if (
coaAccount.amount <=
product_price.mark_up_price + product_price.price
) {
throw new HttpException(
{
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
@@ -446,6 +454,24 @@ export class TransactionService {
userData.partner?.id,
);
const coaAccount = await this.coaService.findByUser(
userData.id,
coaType.WALLET,
);
if (
coaAccount.amount <=
product_price.mark_up_price + product_price.price
) {
throw new HttpException(
{
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
error: `Transaction Failed because saldo not enough`,
},
HttpStatus.INTERNAL_SERVER_ERROR,
);
}
//TODO HIT API SUPPLIER
const trxId = Array(6)
.fill(null)