fix: transaction order product
This commit is contained in:
parent
d66e6eed93
commit
a30a81cbb6
|
@ -10,7 +10,12 @@ import { CoaService } from './coa.service';
|
||||||
import * as uuid from 'uuid';
|
import * as uuid from 'uuid';
|
||||||
import { uniq } from 'lodash';
|
import { uniq } from 'lodash';
|
||||||
import { Decimal } from 'decimal.js';
|
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 { ProductService } from '../product/product.service';
|
||||||
import { CreateJournalDto } from './dto/create-journal.dto';
|
import { CreateJournalDto } from './dto/create-journal.dto';
|
||||||
import { UsersService } from 'src/users/users.service';
|
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(
|
throw new HttpException(
|
||||||
{
|
{
|
||||||
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
|
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
@ -446,6 +454,24 @@ export class TransactionService {
|
||||||
userData.partner?.id,
|
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
|
//TODO HIT API SUPPLIER
|
||||||
const trxId = Array(6)
|
const trxId = Array(6)
|
||||||
.fill(null)
|
.fill(null)
|
||||||
|
|
|
@ -310,9 +310,6 @@ export class UsersService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async findOne(id: string) {
|
async findOne(id: string) {
|
||||||
const coa = await this.coaService.findByUser(id, coaType.WALLET);
|
|
||||||
const coaProfit = await this.coaService.findByUser(id, coaType.PROFIT);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const userData = await this.usersRepository
|
const userData = await this.usersRepository
|
||||||
.createQueryBuilder('users')
|
.createQueryBuilder('users')
|
||||||
|
@ -336,11 +333,17 @@ export class UsersService {
|
||||||
'userDetail.phone_number',
|
'userDetail.phone_number',
|
||||||
])
|
])
|
||||||
.getOne();
|
.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 {
|
return {
|
||||||
...userData,
|
...userData,
|
||||||
wallet: coa.amount,
|
wallet: coa.amount,
|
||||||
profit: coaProfit.amount,
|
profit: coaProfit ? coaProfit.amount : coaProfit,
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof EntityNotFoundError) {
|
if (e instanceof EntityNotFoundError) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user