Merge branch 'development' into 'devops-staging'

Feat: add try catch at callback metro

See merge request empatnusabangsa/ppob/ppob-backend!195
This commit is contained in:
muhammad fadil 2022-08-09 13:39:29 +00:00
commit 4dfe7dd6de

View File

@ -1,7 +1,15 @@
import { Controller, Get, HttpStatus, Logger, Req } from '@nestjs/common'; import {
Controller,
Get,
HttpException,
HttpStatus,
Logger,
Req,
} from '@nestjs/common';
import { TransactionService } from './transaction.service'; import { TransactionService } from './transaction.service';
import { FastifyRequest } from 'fastify'; import { FastifyRequest } from 'fastify';
import { Public } from '../auth/public.decorator'; import { Public } from '../auth/public.decorator';
import { EntityNotFoundError } from 'typeorm';
@Controller({ @Controller({
path: 'ppob_callback', path: 'ppob_callback',
@ -24,7 +32,6 @@ export class PpobCallbackController {
response, response,
); );
} else { } else {
//TODO: UPDATE BERHASIL //TODO: UPDATE BERHASIL
await this.transactionService.checkCallbackOrderSuccess( await this.transactionService.checkCallbackOrderSuccess(
response['clientid'], response['clientid'],
@ -36,6 +43,7 @@ export class PpobCallbackController {
@Public() @Public()
@Get('/metro') @Get('/metro')
async getMetro(@Req() request: FastifyRequest) { async getMetro(@Req() request: FastifyRequest) {
try {
const response = request.query; const response = request.query;
if (response['message'].toLowerCase().includes('cek tagihan')) { if (response['message'].toLowerCase().includes('cek tagihan')) {
@ -56,6 +64,7 @@ export class PpobCallbackController {
} }
const splitMessage = response['message'].split('"'); const splitMessage = response['message'].split('"');
//TODO: UPDATE BERHASIL //TODO: UPDATE BERHASIL
await this.transactionService.updateBill( await this.transactionService.updateBill(
response['refid'], response['refid'],
@ -68,8 +77,10 @@ export class PpobCallbackController {
} else { } else {
console.log('statusapani', response['status']); console.log('statusapani', response['status']);
console.log('statusapani2', response.toString()); console.log('statusapani2', response.toString());
if (response['status'].toString() != '20') { if (response['status'].toString() != '20') {
console.log("masukkesiniga", "msk") console.log('masukkesiniga', 'msk');
//TODO: UPDATE GAGAL //TODO: UPDATE GAGAL
const updateTransaction = const updateTransaction =
await this.transactionService.callbackOrderFailed( await this.transactionService.callbackOrderFailed(
@ -82,7 +93,7 @@ export class PpobCallbackController {
statusCode: HttpStatus.BAD_REQUEST, statusCode: HttpStatus.BAD_REQUEST,
message: 'failed to proccess', message: 'failed to proccess',
}; };
} else { }
//TODO: UPDATE BERHASIL //TODO: UPDATE BERHASIL
const updateTransaction = const updateTransaction =
@ -97,7 +108,7 @@ export class PpobCallbackController {
message: 'success', message: 'success',
}; };
} }
}
this.logger.log({ this.logger.log({
requestQuery: request.query, requestQuery: request.query,
}); });
@ -106,5 +117,19 @@ export class PpobCallbackController {
statusCode: HttpStatus.OK, statusCode: HttpStatus.OK,
message: 'success', message: 'success',
}; };
} catch (e) {
if (e instanceof EntityNotFoundError) {
throw new HttpException(
{
statusCode: HttpStatus.NOT_FOUND,
error: 'Error callback',
message: e
},
HttpStatus.NOT_FOUND,
);
} else {
throw e;
}
}
} }
} }