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)

View File

@ -310,9 +310,6 @@ export class UsersService {
}
async findOne(id: string) {
const coa = await this.coaService.findByUser(id, coaType.WALLET);
const coaProfit = await this.coaService.findByUser(id, coaType.PROFIT);
try {
const userData = await this.usersRepository
.createQueryBuilder('users')
@ -336,11 +333,17 @@ export class UsersService {
'userDetail.phone_number',
])
.getOne();
const coa = await this.coaService.findByUser(id, coaType.WALLET);
let coaProfit;
if(userData.roles.id != 'e4dfb6a3-2338-464a-8fb8-5cbc089d4209'){
coaProfit = await this.coaService.findByUser(id, coaType.PROFIT);
};
return {
...userData,
wallet: coa.amount,
profit: coaProfit.amount,
profit: coaProfit ? coaProfit.amount : coaProfit,
};
} catch (e) {
if (e instanceof EntityNotFoundError) {