Merge branch 'development' into 'devops-staging'

Development

See merge request empatnusabangsa/ppob/ppob-backend!77
This commit is contained in:
ilham dwi pratama 2021-12-30 18:17:46 +00:00
commit a60747337f
5 changed files with 101 additions and 14 deletions

View File

@ -6,4 +6,6 @@ export class OrderTransactionDto {
@IsNotEmpty() @IsNotEmpty()
destination: string; destination: string;
trx_id: string;
} }

View File

@ -50,6 +50,11 @@ export class Transactions extends BaseModel {
}) })
partner_trx_id: string; partner_trx_id: string;
@Column({
nullable: true,
})
seri_number: string;
@Column({ @Column({
nullable: true, nullable: true,
}) })

View File

@ -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') @Put('deposit-return/confirmation/:id/:status')
async confirmDepositReturn( async confirmDepositReturn(
@Param('id', ParseUUIDPipe) id: string, @Param('id', ParseUUIDPipe) id: string,

View File

@ -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';
@ -292,6 +297,13 @@ export class TransactionService {
orderTransactionDto: OrderTransactionDto, orderTransactionDto: OrderTransactionDto,
currentUser: any, currentUser: any,
) { ) {
const trxId = Array(6)
.fill(null)
.map(() => {
return Math.round(Math.random() * 16).toString(16);
})
.join('');
//GET USER //GET USER
const userData = await this.userService.findByUsername( const userData = await this.userService.findByUsername(
currentUser.username, 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( throw new HttpException(
{ {
statusCode: HttpStatus.INTERNAL_SERVER_ERROR, statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
@ -377,6 +392,8 @@ export class TransactionService {
transactionData.type = typeTransaction.ORDER; transactionData.type = typeTransaction.ORDER;
transactionData.product_price = product_price; transactionData.product_price = product_price;
transactionData.destination = orderTransactionDto.destination; transactionData.destination = orderTransactionDto.destination;
transactionData.partner_trx_id = orderTransactionDto.trx_id;
transactionData.supplier_trx_id = trxId;
await manager.insert(Transactions, transactionData); await manager.insert(Transactions, transactionData);
await this.accountingTransaction({ await this.accountingTransaction({
@ -409,7 +426,13 @@ export class TransactionService {
throw e; 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( async orderTransactionProd(
@ -431,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)
@ -458,6 +499,7 @@ export class TransactionService {
transactionData.type = typeTransaction.ORDER; transactionData.type = typeTransaction.ORDER;
transactionData.product_price = product_price; transactionData.product_price = product_price;
transactionData.destination = orderTransactionDto.destination; transactionData.destination = orderTransactionDto.destination;
transactionData.partner_trx_id = orderTransactionDto.trx_id;
transactionData.supplier_trx_id = trxId; transactionData.supplier_trx_id = trxId;
if (!hitSupplier.success) { if (!hitSupplier.success) {
@ -488,7 +530,13 @@ export class TransactionService {
await this.productHistoryPriceService.create(newProductPrice); 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) { async createDepositReturn(currentUser, depositReturnDto: DepositReturnDto) {
@ -661,7 +709,8 @@ export class TransactionService {
relations: ['product_price'], relations: ['product_price'],
}); });
dataTransaction.status = statusTransaction.FAILED; dataTransaction.status = statusTransaction.SUCCESS;
dataTransaction.seri_number = callback['sn'];
dataTransaction.callback_json = callback; dataTransaction.callback_json = callback;
const userData = await this.userService.findExist(dataTransaction.user); const userData = await this.userService.findExist(dataTransaction.user);
@ -851,12 +900,17 @@ export class TransactionService {
.leftJoin('transaction.product_price', 'product_price') .leftJoin('transaction.product_price', 'product_price')
.leftJoin('product_price.product', 'product') .leftJoin('product_price.product', 'product')
.addSelect('transaction.amount', 'price') .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('userData.name', 'buyer')
.addSelect('product.name', 'name') .addSelect('product.name', 'name')
.addSelect('product.id', 'product_id'); .addSelect('product.id', 'product_id');
if (startDate && endDate) { 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), startDate: new Date(startDate),
enDate: new Date(endDate), enDate: new Date(endDate),
}); });

View File

@ -151,9 +151,9 @@ export class UsersService {
if (type) { if (type) {
if (type == 'partner') { if (type == 'partner') {
baseQuery.where('user.partner_id is not null') baseQuery.where('user.partner_id is not null');
} else { } 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) { 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) {