Merge branch 'development' into 'devops-staging'
Development See merge request empatnusabangsa/ppob/ppob-backend!77
This commit is contained in:
commit
a60747337f
|
@ -6,4 +6,6 @@ export class OrderTransactionDto {
|
|||
|
||||
@IsNotEmpty()
|
||||
destination: string;
|
||||
|
||||
trx_id: string;
|
||||
}
|
||||
|
|
|
@ -50,6 +50,11 @@ export class Transactions extends BaseModel {
|
|||
})
|
||||
partner_trx_id: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
})
|
||||
seri_number: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
})
|
||||
|
|
|
@ -197,6 +197,29 @@ export class TransactionController {
|
|||
};
|
||||
}
|
||||
|
||||
@Get('history-user/:id')
|
||||
async getHistoryTransactionUserByParam(
|
||||
@Query('page') page: number,
|
||||
@Query('pageSize') pageSize: number,
|
||||
@Query('start') startDate: string,
|
||||
@Query('end') endDate: string,
|
||||
@Param('id', ParseUUIDPipe) id: string,
|
||||
) {
|
||||
const data = await this.transactionService.transactionHistoryByUser(
|
||||
page,
|
||||
id,
|
||||
startDate == 'null' ? null : startDate,
|
||||
endDate == 'null' ? null : endDate,
|
||||
pageSize,
|
||||
);
|
||||
|
||||
return {
|
||||
...data,
|
||||
statusCode: HttpStatus.OK,
|
||||
message: 'success',
|
||||
};
|
||||
}
|
||||
|
||||
@Put('deposit-return/confirmation/:id/:status')
|
||||
async confirmDepositReturn(
|
||||
@Param('id', ParseUUIDPipe) id: string,
|
||||
|
|
|
@ -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';
|
||||
|
@ -292,6 +297,13 @@ export class TransactionService {
|
|||
orderTransactionDto: OrderTransactionDto,
|
||||
currentUser: any,
|
||||
) {
|
||||
const trxId = Array(6)
|
||||
.fill(null)
|
||||
.map(() => {
|
||||
return Math.round(Math.random() * 16).toString(16);
|
||||
})
|
||||
.join('');
|
||||
|
||||
//GET USER
|
||||
const userData = await this.userService.findByUsername(
|
||||
currentUser.username,
|
||||
|
@ -355,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,
|
||||
|
@ -377,6 +392,8 @@ export class TransactionService {
|
|||
transactionData.type = typeTransaction.ORDER;
|
||||
transactionData.product_price = product_price;
|
||||
transactionData.destination = orderTransactionDto.destination;
|
||||
transactionData.partner_trx_id = orderTransactionDto.trx_id;
|
||||
transactionData.supplier_trx_id = trxId;
|
||||
await manager.insert(Transactions, transactionData);
|
||||
|
||||
await this.accountingTransaction({
|
||||
|
@ -409,7 +426,13 @@ export class TransactionService {
|
|||
throw e;
|
||||
}
|
||||
|
||||
return true;
|
||||
return {
|
||||
trx_id: trxId,
|
||||
client_trx_id: orderTransactionDto.trx_id,
|
||||
product: orderTransactionDto.productCode,
|
||||
amount: product_price.mark_up_price + product_price.price,
|
||||
status: statusTransaction[statusTransaction.SUCCESS],
|
||||
};
|
||||
}
|
||||
|
||||
async orderTransactionProd(
|
||||
|
@ -431,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)
|
||||
|
@ -458,6 +499,7 @@ export class TransactionService {
|
|||
transactionData.type = typeTransaction.ORDER;
|
||||
transactionData.product_price = product_price;
|
||||
transactionData.destination = orderTransactionDto.destination;
|
||||
transactionData.partner_trx_id = orderTransactionDto.trx_id;
|
||||
transactionData.supplier_trx_id = trxId;
|
||||
|
||||
if (!hitSupplier.success) {
|
||||
|
@ -488,7 +530,13 @@ export class TransactionService {
|
|||
await this.productHistoryPriceService.create(newProductPrice);
|
||||
}
|
||||
|
||||
return hitSupplier;
|
||||
return {
|
||||
trx_id: trxId,
|
||||
client_trx_id: orderTransactionDto.trx_id,
|
||||
product: orderTransactionDto.productCode,
|
||||
amount: transactionData.amount,
|
||||
status: statusTransaction[transactionData.status],
|
||||
};
|
||||
}
|
||||
|
||||
async createDepositReturn(currentUser, depositReturnDto: DepositReturnDto) {
|
||||
|
@ -661,7 +709,8 @@ export class TransactionService {
|
|||
relations: ['product_price'],
|
||||
});
|
||||
|
||||
dataTransaction.status = statusTransaction.FAILED;
|
||||
dataTransaction.status = statusTransaction.SUCCESS;
|
||||
dataTransaction.seri_number = callback['sn'];
|
||||
dataTransaction.callback_json = callback;
|
||||
|
||||
const userData = await this.userService.findExist(dataTransaction.user);
|
||||
|
@ -851,12 +900,17 @@ export class TransactionService {
|
|||
.leftJoin('transaction.product_price', 'product_price')
|
||||
.leftJoin('product_price.product', 'product')
|
||||
.addSelect('transaction.amount', 'price')
|
||||
.addSelect('transaction.destination')
|
||||
.addSelect('transaction.seri_number','seri_number')
|
||||
.addSelect('transaction.supplier_trx_id', 'transaction_code')
|
||||
.addSelect('transaction.status', 'status')
|
||||
.addSelect('transaction.partner_trx_id', 'partner_transaction_code')
|
||||
.addSelect('userData.name', 'buyer')
|
||||
.addSelect('product.name', 'name')
|
||||
.addSelect('product.id', 'product_id');
|
||||
|
||||
if (startDate && endDate) {
|
||||
baseQuery.where('transaction.created_at between :startDate and :enDate', {
|
||||
baseQuery.andWhere('transaction.created_at between :startDate and :enDate', {
|
||||
startDate: new Date(startDate),
|
||||
enDate: new Date(endDate),
|
||||
});
|
||||
|
|
|
@ -151,9 +151,9 @@ export class UsersService {
|
|||
|
||||
if (type) {
|
||||
if (type == 'partner') {
|
||||
baseQuery.where('user.partner_id is not null')
|
||||
baseQuery.where('user.partner_id is not null');
|
||||
} else {
|
||||
baseQuery.where('user.partner_id is null')
|
||||
baseQuery.where('user.partner_id is null');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user