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:38:37 +00:00
commit 0241656b42

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 { FastifyRequest } from 'fastify';
import { Public } from '../auth/public.decorator';
import { EntityNotFoundError } from 'typeorm';
@Controller({
path: 'ppob_callback',
@ -20,15 +28,14 @@ export class PpobCallbackController {
if (response['statuscode'] == 2) {
//TODO: UPDATE GAGAL
await this.transactionService.checkCallbackOrderFailed(
response['clientid'],
response,
);
response['clientid'],
response,
);
} else {
//TODO: UPDATE BERHASIL
await this.transactionService.checkCallbackOrderSuccess(
response['clientid'],
response,
response['clientid'],
response,
);
}
}
@ -36,60 +43,64 @@ export class PpobCallbackController {
@Public()
@Get('/metro')
async getMetro(@Req() request: FastifyRequest) {
const response = request.query;
try {
const response = request.query;
if (response['message'].toLowerCase().includes('cek tagihan')) {
if (response['status'] != 20) {
//TODO: UPDATE GAGAL
await this.transactionService.updateBill(
if (response['message'].toLowerCase().includes('cek tagihan')) {
if (response['status'] != 20) {
//TODO: UPDATE GAGAL
await this.transactionService.updateBill(
response['refid'],
null,
null,
false,
response['message'],
);
);
return {
statusCode: HttpStatus.OK,
message: 'success',
};
}
return {
statusCode: HttpStatus.OK,
message: 'success',
};
}
const splitMessage = response['message'].split('"');
//TODO: UPDATE BERHASIL
await this.transactionService.updateBill(
const splitMessage = response['message'].split('"');
//TODO: UPDATE BERHASIL
await this.transactionService.updateBill(
response['refid'],
Number(splitMessage[21].replace(/^\D+/g, '')),
Number(splitMessage[17].replace(/^\D+/g, '')),
true,
response['message'],
);
//
} else {
console.log('statusapani', response['status']);
console.log('statusapani2', response.toString());
if (response['status'].toString() != '20') {
console.log("masukkesiniga", "msk")
//TODO: UPDATE GAGAL
const updateTransaction =
);
//
} else {
console.log('statusapani', response['status']);
console.log('statusapani2', response.toString());
if (response['status'].toString() != '20') {
console.log('masukkesiniga', 'msk');
//TODO: UPDATE GAGAL
const updateTransaction =
await this.transactionService.callbackOrderFailed(
response['refid'],
response,
response['refid'],
response,
);
return {
updateTransaction,
statusCode: HttpStatus.BAD_REQUEST,
message: 'failed to proccess',
};
} else {
return {
updateTransaction,
statusCode: HttpStatus.BAD_REQUEST,
message: 'failed to proccess',
};
}
//TODO: UPDATE BERHASIL
const updateTransaction =
await this.transactionService.callbackOrderSuccess(
response['refid'],
response,
);
await this.transactionService.callbackOrderSuccess(
response['refid'],
response,
);
return {
updateTransaction,
@ -97,14 +108,28 @@ export class PpobCallbackController {
message: 'success',
};
}
}
this.logger.log({
requestQuery: request.query,
});
return {
statusCode: HttpStatus.OK,
message: 'success',
};
this.logger.log({
requestQuery: request.query,
});
return {
statusCode: HttpStatus.OK,
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;
}
}
}
}