fixing: check bill

This commit is contained in:
ilham
2022-05-17 12:52:02 +07:00
parent 9ee5b65dfc
commit f449299bbf
2 changed files with 56 additions and 16 deletions

View File

@@ -1781,7 +1781,14 @@ export class TransactionService {
return transaction;
}
async updateBill(trxId: string, amount: number, admin: number) {
async updateBill(
trxId: string,
amount: number,
admin: number,
status: boolean,
) {
const billData = await this.findOneBillById(trxId);
await this.checkBillHistoryRepository.update(
{
trx_id: trxId,
@@ -1791,5 +1798,45 @@ export class TransactionService {
admin_price: admin,
},
);
const userData = await this.userService.findExist(billData.user);
if (userData.partner) {
const message = status
? `Bill dari ${billData.destination} adalah ${amount}.`
: '';
const statusResponse = status ? 'berhasil' : 'gagal';
this.callbackToPartner(
userData.id,
message,
billData.partner_trx_id,
amount,
billData.product_code,
billData.destination,
'-',
statusResponse,
);
}
}
async findOneBillById(trxId: string) {
try {
return await this.checkBillHistoryRepository.findOneOrFail({
where:{
trx_id: trxId,
},
});
} catch (e) {
if (e instanceof EntityNotFoundError) {
throw new HttpException(
{
statusCode: HttpStatus.NOT_FOUND,
error: 'Bill not found',
},
HttpStatus.NOT_FOUND,
);
} else {
throw e;
}
}
}
}