Merge branch 'development' of https://gitlab.com/empatnusabangsa/ppob/ppob-backend into devops-staging

This commit is contained in:
Fadli 2022-06-29 23:53:43 +07:00
commit 949e368c2f
3 changed files with 186 additions and 111 deletions

View File

@ -19,31 +19,18 @@ export class PpobCallbackController {
if (response['statuscode'] == 2) {
//TODO: UPDATE GAGAL
const updateTransaction =
await this.transactionService.callbackOrderFailed(
await this.transactionService.checkCallbackOrderFailed(
response['clientid'],
response,
);
return {
updateTransaction,
statusCode: HttpStatus.BAD_REQUEST,
message: 'failed to proccess',
};
}
//TODO: UPDATE BERHASIL
const updateTransaction =
await this.transactionService.callbackOrderSuccess(
await this.transactionService.checkCallbackOrderSuccess(
response['clientid'],
response,
);
return {
updateTransaction,
statusCode: HttpStatus.OK,
message: 'success',
};
}
@Public()

View File

@ -132,9 +132,9 @@ export class TransactionController {
};
}
@Get('rollback-jurnal/:trxId')
async rollbackJurnal(@Request() req, @Param('trxId') trxId: string) {
const data = await this.transactionService.rollbackJurnal(trxId);
@Post('rollback-jurnal')
async rollbackJurnal(@Body() request, @Request() req) {
const data = await this.transactionService.rollbackJurnal(request.trxId);
return {
data,
statusCode: HttpStatus.OK,

View File

@ -3,19 +3,14 @@ import { DistributeTransactionDto } from './dto/distribute-transaction.dto';
import {OrderTransactionDto} from './dto/order-transaction.dto';
import {InjectRepository} from '@nestjs/typeorm';
import {Transactions} from './entities/transactions.entity';
import { Between, Connection, EntityNotFoundError, Repository } from 'typeorm';
import {Between, Connection, EntityNotFoundError, In, Repository} from 'typeorm';
import {COA} from './entities/coa.entity';
import {TransactionJournal} from './entities/transaction-journal.entity';
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';
@ -1059,6 +1054,109 @@ export class TransactionService {
return transactionData;
}
async checkCallbackOrderFailed(supplier_trx_id: string, callback: any) {
const transactionData = await this.findDataTransactionBySupplierTrxId(
supplier_trx_id
);
if (transactionData.status == statusTransaction.FAILED) {
throw new HttpException(
{
statusCode: HttpStatus.BAD_REQUEST,
error: 'failed to update, the transaction already failed',
},
HttpStatus.BAD_REQUEST,
);
} else if (transactionData.status == statusTransaction.SUCCESS) {
throw new HttpException(
{
statusCode: HttpStatus.BAD_REQUEST,
error: 'failed to update, the transaction already success',
},
HttpStatus.BAD_REQUEST,
);
} else {
const updateTransaction =
await this.callbackOrderFailed(
supplier_trx_id,
callback,
);
return {
updateTransaction,
statusCode: HttpStatus.BAD_REQUEST,
message: 'failed to proccess',
};
}
}
async checkCallbackOrderSuccess(supplier_trx_id: string, callback: any) {
const transactionData = await this.findDataTransactionBySupplierTrxId(
supplier_trx_id
);
if (transactionData.status == statusTransaction.FAILED) {
throw new HttpException(
{
statusCode: HttpStatus.BAD_REQUEST,
error: 'failed to update, the transaction already failed',
},
HttpStatus.BAD_REQUEST,
);
} else if (transactionData.status == statusTransaction.SUCCESS) {
throw new HttpException(
{
statusCode: HttpStatus.BAD_REQUEST,
error: 'failed to update, the transaction already success',
},
HttpStatus.BAD_REQUEST,
);
} else {
const updateTransaction =
await this.callbackOrderSuccess(
supplier_trx_id,
callback,
);
return {
updateTransaction,
statusCode: HttpStatus.OK,
message: 'success',
};
}
}
async findDataTransactionBySupplierTrxId(supplier_trx_id: string) {
try {
return await this.transactionRepository.findOneOrFail({
where: {
supplier_trx_id: supplier_trx_id,
},
relations: ['product_price'],
});
} catch (e) {
if (e instanceof EntityNotFoundError) {
throw new HttpException(
{
statusCode: HttpStatus.NOT_FOUND,
error: 'data not found',
},
HttpStatus.NOT_FOUND,
);
} else {
throw e;
}
}
}
async callbackOrderFailed(supplier_trx_id: string, callback: any) {
const dataTransaction = await this.transactionRepository.findOne({
where: {
@ -1317,35 +1415,25 @@ export class TransactionService {
return res;
}
async rollbackJurnal(trxId: string) {
const dataTransaction = await this.transactionRepository.findOne({
where: {
id: trxId,
},
relations: ['product_price'],
});
async rollbackJurnal(trxId: string[]) {
// const dataTransaction = await this.transactionRepository.findOne({
// where: {
// id: trxId,
// },
// relations: ['product_price'],
// });
let dataTransactionJurnal;
if (dataTransaction.type == typeTransaction.ORDER) {
dataTransactionJurnal = await this.transactionJournalRepository.find({
where: {
transaction_head: trxId,
},
relations: ['coa'],
skip: 4,
order: {
createdAt: 'ASC',
},
});
} else {
dataTransactionJurnal = await this.transactionJournalRepository.find({
where: {
transaction_head: trxId,
},
relations: ['coa'],
});
if (trxId.length % 2 != 0) {
throw Error("Not Balance")
}
const dataTransactionJurnal = await this.transactionJournalRepository.find({
where: {
id: In(trxId),
},
relations: ['coa'],
});
let dataRollbackJurnal = [];
dataTransactionJurnal.map((it) => {
@ -1362,7 +1450,8 @@ export class TransactionService {
dataRollbackJurnal.push(data);
});
if (dataRollbackJurnal.length > 0) {
const dataTransaction = new Transactions();
try {
await this.connection.transaction(async (manager) => {
await this.accountingTransaction({
@ -1377,7 +1466,6 @@ export class TransactionService {
throw e;
}
}
}
async withdrawBenefit(user) {
const userData = await this.userService.findExist(user);