- add condition for userdata partner if not null in callback success

- comment check if the transaction is success
This commit is contained in:
Fadli 2022-09-06 21:36:05 +07:00
parent 6a7c66f461
commit 9d9772270d

View File

@ -1111,23 +1111,23 @@ export class TransactionService {
supplier_trx_id supplier_trx_id
); );
if (transactionData.status == statusTransaction.FAILED) { // if (transactionData.status == statusTransaction.FAILED) {
throw new HttpException( // throw new HttpException(
{ // {
statusCode: HttpStatus.BAD_REQUEST, // statusCode: HttpStatus.BAD_REQUEST,
error: 'failed to update, the transaction already failed', // error: 'failed to update, the transaction already failed',
}, // },
HttpStatus.BAD_REQUEST, // HttpStatus.BAD_REQUEST,
); // );
} else if (transactionData.status == statusTransaction.SUCCESS) { // } else if (transactionData.status == statusTransaction.SUCCESS) {
throw new HttpException( // throw new HttpException(
{ // {
statusCode: HttpStatus.BAD_REQUEST, // statusCode: HttpStatus.BAD_REQUEST,
error: 'failed to update, the transaction already success', // error: 'failed to update, the transaction already success',
}, // },
HttpStatus.BAD_REQUEST, // HttpStatus.BAD_REQUEST,
); // );
} else { // } else {
const updateTransaction = await this.callbackOrderFailed( const updateTransaction = await this.callbackOrderFailed(
supplier_trx_id, supplier_trx_id,
callback, callback,
@ -1142,7 +1142,7 @@ export class TransactionService {
HttpStatus.BAD_REQUEST, HttpStatus.BAD_REQUEST,
); );
} // }
} }
@ -1337,14 +1337,14 @@ export class TransactionService {
}); });
dataTransaction.status = statusTransaction.SUCCESS; dataTransaction.status = statusTransaction.SUCCESS;
if(callback['sn']){ if (callback['sn']) {
dataTransaction.seri_number = callback['sn']; dataTransaction.seri_number = callback['sn'];
console.log("msksn1", dataTransaction.seri_number) console.log("msksn1", dataTransaction.seri_number)
} else { } else {
const response = callback['message']; const response = callback['message'];
const responseBaru = response.split(' '); const responseBaru = response.split(' ');
dataTransaction.seri_number = dataTransaction.seri_number =
responseBaru[10].length > 1 ? responseBaru[10] : responseBaru[9]; responseBaru[10].length > 1 ? responseBaru[10] : responseBaru[9];
if (dataTransaction.seri_number == 'SN:') { if (dataTransaction.seri_number == 'SN:') {
dataTransaction.seri_number = responseBaru[11] dataTransaction.seri_number = responseBaru[11]
@ -1352,7 +1352,7 @@ export class TransactionService {
} }
dataTransaction.callback_json = callback; dataTransaction.callback_json = callback;
if(callback['message']) { if (callback['message']) {
if (callback['message'].includes('METRO')) { if (callback['message'].includes('METRO')) {
if (callback['price'] != dataTransaction.product_price.price) { if (callback['price'] != dataTransaction.product_price.price) {
dataProductHistoryPrice.price = parseInt(callback['price']) dataProductHistoryPrice.price = parseInt(callback['price'])
@ -1365,18 +1365,18 @@ export class TransactionService {
let supervisorData = []; let supervisorData = [];
const product_price = await this.productHistoryPriceService.findById( const product_price = await this.productHistoryPriceService.findById(
dataTransaction.product_price.id, dataTransaction.product_price.id,
); );
const product = await this.productService.findOneById( const product = await this.productService.findOneById(
product_price.product.id, product_price.product.id,
); );
let profit = product_price.mark_up_price; let profit = product_price.mark_up_price;
//GET COA //GET COA
const coaExpense = await this.coaService.findByName( const coaExpense = await this.coaService.findByName(
`${coaType[coaType.EXPENSE]}-SYSTEM`, `${coaType[coaType.EXPENSE]}-SYSTEM`,
); );
// dataTransaction.balance_remaining = coaAccount.amount - product_price.mark_up_price - costInventory; // dataTransaction.balance_remaining = coaAccount.amount - product_price.mark_up_price - costInventory;
@ -1384,17 +1384,17 @@ export class TransactionService {
if (userData.partner == null) { if (userData.partner == null) {
//GET SALES //GET SALES
supervisorData = await this.calculateCommission( supervisorData = await this.calculateCommission(
supervisorData, supervisorData,
profit, profit,
userData, userData,
); );
profit = supervisorData profit = supervisorData
.map((item) => { .map((item) => {
return item.credit; return item.credit;
}) })
.reduce((prev, curr) => { .reduce((prev, curr) => {
return prev + curr; return prev + curr;
}, 0); }, 0);
supervisorData = supervisorData.concat([ supervisorData = supervisorData.concat([
{ {
@ -1420,21 +1420,22 @@ export class TransactionService {
} catch (e) { } catch (e) {
throw e; throw e;
} }
if (userData.partner != null) {
if (userData.partner) { if (userData.partner) {
const message = `Transaksi ${product.code} dengan tujuan ${dataTransaction.destination} telah berhasil.`; const message = `Transaksi ${product.code} dengan tujuan ${dataTransaction.destination} telah berhasil.`;
this.callbackToPartner( this.callbackToPartner(
userData.partner.id, userData.partner.id,
message, message,
dataTransaction.partner_trx_id, dataTransaction.partner_trx_id,
dataTransaction.amount, dataTransaction.amount,
product.code, product.code,
dataTransaction.destination, dataTransaction.destination,
dataTransaction.seri_number, dataTransaction.seri_number,
'berhasil', 'berhasil',
); );
} }
} }
}
async resendOrderToPartner(supplier_trx_id: string, status: boolean){ async resendOrderToPartner(supplier_trx_id: string, status: boolean){
const dataTransaction = await this.transactionRepository.findOne({ const dataTransaction = await this.transactionRepository.findOne({