mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-05 17:26:28 +00:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2863392518 | |||
| 82bd1c5276 | |||
| 058cd6edfc | |||
| f8aacae0ea | |||
| 5a4870408c | |||
| e3ef16753e | |||
| 90aaf3f6f6 | |||
| 0437eaab25 | |||
| 4a98a1c5cd | |||
| 3c927b6385 | |||
| 41bdf42bac |
@@ -3,6 +3,14 @@ require("winston-daily-rotate-file");
|
||||
const expressWinston = require("express-winston");
|
||||
const fs = require("fs");
|
||||
const moment = require("moment");
|
||||
const winstonLoki = require("../helpers/loki");
|
||||
const knex = require("../../infrastructure/database/knex");
|
||||
const {
|
||||
topuponline_metrics,
|
||||
topuponline_metrics_response_time,
|
||||
topuponline_metrics_load_balance,
|
||||
} = require("../helpers/prometheusmetrics");
|
||||
const helper = require("../helpers/helper");
|
||||
|
||||
const filename = () => {
|
||||
if (!fs.existsSync(`./expresswinstonlog`)) {
|
||||
@@ -28,6 +36,20 @@ const filename = () => {
|
||||
|
||||
filename();
|
||||
|
||||
const routes = [
|
||||
"/api/reservation",
|
||||
"/api/reservation/v2",
|
||||
"/api/loadbalance/request",
|
||||
"/api/topup1",
|
||||
"/api/topup2",
|
||||
"/api/topup3",
|
||||
"/api/topup4",
|
||||
"/api/topup5",
|
||||
"/api/topup6",
|
||||
"/api/topup7",
|
||||
"/api/topup8",
|
||||
];
|
||||
|
||||
const logger = {
|
||||
response: expressWinston.logger({
|
||||
transports: [
|
||||
@@ -35,13 +57,12 @@ const logger = {
|
||||
filename: "./expresswinstonlog/%DATE%.log",
|
||||
frequency: "24h",
|
||||
datePattern: "YYYY/MM/DD",
|
||||
zippedArchive: true,
|
||||
maxFiles: "1d",
|
||||
}),
|
||||
],
|
||||
format: winston.format.combine(
|
||||
winston.format.timestamp(),
|
||||
winston.format.printf((info) => {
|
||||
winston.format.printf(async (info) => {
|
||||
let body = {};
|
||||
body.id = info.meta.req.id;
|
||||
body.tag = "RES";
|
||||
@@ -51,16 +72,197 @@ const logger = {
|
||||
body.time = moment().format();
|
||||
body.responseTime = `${info.meta.responseTime} ms`;
|
||||
|
||||
var header_auth = info.meta.req.headers["authorization"];
|
||||
var issuer_name = "Web"
|
||||
if (!issuer_name)
|
||||
return `[${moment().format()}] | ${JSON.stringify(body)}`;
|
||||
let issuerName;
|
||||
|
||||
let partnerId = info.meta.req.partner_id_token;
|
||||
|
||||
if (!partnerId) {
|
||||
issuerName = "UNDEFINED";
|
||||
} else {
|
||||
let getIssuerName = await getPartner(info.meta.req.partner_id_token);
|
||||
if (!getIssuerName.c_name) {
|
||||
issuerName = "UNDEFINED";
|
||||
} else {
|
||||
issuerName = getIssuerName.c_name;
|
||||
}
|
||||
}
|
||||
|
||||
let statusCode = info.meta.res.body.code;
|
||||
let message = info.meta.res.body.message;
|
||||
let url = info.meta.req.originalUrl;
|
||||
|
||||
let date = moment().format("D");
|
||||
let month = moment().format("M");
|
||||
let year = moment().format("Y");
|
||||
|
||||
// Topup Metrics
|
||||
if (
|
||||
url == "/api/topup1" ||
|
||||
url == "/api/topup2" ||
|
||||
url == "/api/topup3" ||
|
||||
url == "/api/topup4" ||
|
||||
url == "/api/topup5" ||
|
||||
url == "/api/topup6" ||
|
||||
url == "/api/topup7" ||
|
||||
url == "/api/topup8"
|
||||
) {
|
||||
let trxId = info.meta.res.body.data.trxID;
|
||||
if (!trxId) {
|
||||
trxId = "UNDEFINED";
|
||||
}
|
||||
|
||||
topuponline_metrics_load_balance
|
||||
.labels({
|
||||
trxId: trxId,
|
||||
route: url,
|
||||
issuer_name: issuerName,
|
||||
date: date,
|
||||
month: month,
|
||||
year: year,
|
||||
})
|
||||
.observe(info.meta.responseTime);
|
||||
}
|
||||
|
||||
// Reservation Loki Logs
|
||||
if (url == "/api/reservation" || url == "/api/reservation/v2") {
|
||||
if (
|
||||
statusCode != "00" &&
|
||||
statusCode != "01" &&
|
||||
statusCode != "02" &&
|
||||
statusCode != "03" &&
|
||||
statusCode != "04"
|
||||
) {
|
||||
let rsvData = info.meta.req.body.reservation_data;
|
||||
let encryptRsvData = helper.decryptText(rsvData);
|
||||
let encryptRes = JSON.parse(encryptRsvData);
|
||||
let { card_number } = encryptRes;
|
||||
|
||||
winstonLoki.log.error({
|
||||
message: message,
|
||||
labels: {
|
||||
route: url,
|
||||
status_code: statusCode,
|
||||
issuer_name: issuerName,
|
||||
card_number: card_number,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
let reservation_number = info.meta.res.body.data.reservation_number;
|
||||
let card_number = info.meta.res.body.data.card_number;
|
||||
winstonLoki.log.info({
|
||||
message: message,
|
||||
labels: {
|
||||
route: url,
|
||||
status_code: statusCode,
|
||||
issuer_name: issuerName,
|
||||
reservation_number: reservation_number,
|
||||
card_number: card_number,
|
||||
},
|
||||
});
|
||||
}
|
||||
} else if (url == "/api/topup6" || url == "/api/topup7") {
|
||||
let card_number = info.meta.req.body.card_number;
|
||||
let uid = info.meta.req.body.uid;
|
||||
let trxID = info.meta.res.body.data.trxID;
|
||||
if (
|
||||
statusCode != "00" &&
|
||||
statusCode != "01" &&
|
||||
statusCode != "02" &&
|
||||
statusCode != "03" &&
|
||||
statusCode != "04"
|
||||
) {
|
||||
winstonLoki.log.error({
|
||||
message: message,
|
||||
labels: {
|
||||
route: url,
|
||||
status_code: statusCode,
|
||||
issuer_name: issuerName,
|
||||
card_number: card_number,
|
||||
uid: uid,
|
||||
trxID: trxID,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
winstonLoki.log.info({
|
||||
message: message,
|
||||
labels: {
|
||||
route: url,
|
||||
status_code: statusCode,
|
||||
issuer_name: issuerName,
|
||||
card_number: card_number,
|
||||
uid: uid,
|
||||
trxID: trxID,
|
||||
},
|
||||
});
|
||||
}
|
||||
} else {
|
||||
let trxID = info.meta.res.body.data.trxID;
|
||||
if (
|
||||
statusCode != "00" &&
|
||||
statusCode != "01" &&
|
||||
statusCode != "02" &&
|
||||
statusCode != "03" &&
|
||||
statusCode != "04"
|
||||
) {
|
||||
winstonLoki.log.error({
|
||||
message: message,
|
||||
labels: {
|
||||
route: url,
|
||||
status_code: statusCode,
|
||||
issuer_name: issuerName,
|
||||
trxID: trxID,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
winstonLoki.log.info({
|
||||
message: message,
|
||||
labels: {
|
||||
route: url,
|
||||
status_code: statusCode,
|
||||
issuer_name: issuerName,
|
||||
trxID: trxID,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
topuponline_metrics
|
||||
.labels({
|
||||
issuer_name: issuerName,
|
||||
route: url,
|
||||
status_code: statusCode,
|
||||
date: date,
|
||||
month: month,
|
||||
year: year,
|
||||
})
|
||||
.observe(info.meta.responseTime);
|
||||
|
||||
topuponline_metrics_response_time
|
||||
.labels({
|
||||
issuer_name: issuerName,
|
||||
route: url,
|
||||
status_code: statusCode,
|
||||
date: date,
|
||||
month: month,
|
||||
year: year,
|
||||
response_time: info.meta.responseTime,
|
||||
})
|
||||
.observe(info.meta.responseTime);
|
||||
|
||||
return `[${moment().format()}] | ${JSON.stringify(body)}`;
|
||||
})
|
||||
),
|
||||
skip: (req, res) => {
|
||||
return routes.indexOf(req.originalUrl) === -1;
|
||||
},
|
||||
responseWhitelist: [...expressWinston.responseWhitelist, "body"],
|
||||
requestWhitelist: [...expressWinston.requestWhitelist, "body", "id", "ip"],
|
||||
requestWhitelist: [
|
||||
...expressWinston.requestWhitelist,
|
||||
"body",
|
||||
"id",
|
||||
"ip",
|
||||
"partner_id_token",
|
||||
],
|
||||
}),
|
||||
request: expressWinston.logger({
|
||||
transports: [
|
||||
@@ -68,7 +270,6 @@ const logger = {
|
||||
filename: "./expresswinstonlog/%DATE%.log",
|
||||
frequency: "24h",
|
||||
datePattern: "YYYY/MM/DD",
|
||||
zippedArchive: true,
|
||||
maxFiles: "1d",
|
||||
}),
|
||||
],
|
||||
@@ -89,4 +290,10 @@ const logger = {
|
||||
}),
|
||||
};
|
||||
|
||||
const getPartner = async (id) => {
|
||||
let result = await knex("t_m_partner").where("i_partner", "=", id).first();
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports = { logger, filename };
|
||||
|
||||
@@ -4,6 +4,7 @@ const loki = require("winston-loki");
|
||||
require("winston-daily-rotate-file");
|
||||
require("dotenv").config();
|
||||
const { combine, timestamp, printf, colorize, align, json } = winston.format;
|
||||
let lokiUrl = process.env.LOKI_URL;
|
||||
|
||||
const logLevels = {
|
||||
fatal: 0,
|
||||
@@ -41,7 +42,7 @@ if (
|
||||
defaultMeta: { service: "topuponline" },
|
||||
transports: [
|
||||
new loki({
|
||||
host: "http://localhost:3100",
|
||||
host: lokiUrl,
|
||||
labels: { app: "topuponline" },
|
||||
json: true,
|
||||
format: json(),
|
||||
@@ -57,7 +58,7 @@ if (
|
||||
log = winston.createLogger({
|
||||
transports: [
|
||||
new loki({
|
||||
host: "http://localhost:3100",
|
||||
host: lokiUrl,
|
||||
labels: { app: "topuponline" },
|
||||
handleExceptions: true,
|
||||
handleRejections: true,
|
||||
|
||||
@@ -3,12 +3,39 @@ const client = require("prom-client");
|
||||
const topuponline_metrics = new client.Histogram({
|
||||
name: "topuponline",
|
||||
help: "this is the metric for getting request data based on code status",
|
||||
labelNames: ["route", "status_code", "issuer_name", "date", "month", "year"],
|
||||
});
|
||||
|
||||
const topuponline_metrics_response_time = new client.Histogram({
|
||||
name: "topuponline_response_time",
|
||||
help: "this is the metric for getting request data based on response time",
|
||||
labelNames: [
|
||||
"route",
|
||||
"status_code",
|
||||
"issuer_name",
|
||||
"method",
|
||||
"date",
|
||||
"month",
|
||||
"year",
|
||||
"response_time",
|
||||
],
|
||||
});
|
||||
|
||||
module.exports = { topuponline_metrics };
|
||||
const topuponline_metrics_load_balance = new client.Histogram({
|
||||
name: "topuponline_load_balance",
|
||||
help: "this is the metric for getting request data based on response time",
|
||||
labelNames: [
|
||||
"route",
|
||||
"status_code",
|
||||
"issuer_name",
|
||||
"date",
|
||||
"month",
|
||||
"year",
|
||||
"trxId",
|
||||
],
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
topuponline_metrics,
|
||||
topuponline_metrics_response_time,
|
||||
topuponline_metrics_load_balance,
|
||||
};
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
const winstonLoki = require("../helpers/loki");
|
||||
|
||||
const lokiMiddleware = (req, res, next) => {
|
||||
// return console.log(res)
|
||||
res.on("finish", () => {
|
||||
// return console.log(res.body.code)
|
||||
// console.log(`request url = ${req.originalUrl}`);
|
||||
// console.log(res.getHeader("x-response-time"));
|
||||
// console.log(res.statusCode);
|
||||
|
||||
let url = req.originalUrl;
|
||||
let responseTime = Math.round(parseInt(res.getHeader("x-response-time")));
|
||||
let statusCode = res.body.code;
|
||||
let method = req.method;
|
||||
|
||||
if (statusCode != "200" && statusCode != "204") {
|
||||
winstonLoki.log.error({
|
||||
message: "error",
|
||||
labels: {
|
||||
method: method,
|
||||
url: url,
|
||||
responseTime: responseTime,
|
||||
status: statusCode,
|
||||
// data: res.body.data,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
winstonLoki.log.info({
|
||||
message: "success",
|
||||
labels: {
|
||||
method: method,
|
||||
url: url,
|
||||
responseTime: responseTime,
|
||||
status: statusCode,
|
||||
// data: res.body.data,
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
next();
|
||||
};
|
||||
|
||||
module.exports = lokiMiddleware;
|
||||
@@ -1,33 +0,0 @@
|
||||
const { topuponline_metrics } = require("../helpers/prometheusmetrics");
|
||||
|
||||
const prometheusMiddleware = (req, res, next) => {
|
||||
res.on("finish", () => {
|
||||
let url = req.originalUrl;
|
||||
let responseTime = Math.round(parseInt(res.getHeader("x-response-time")));
|
||||
let statusCode = res.body.code;
|
||||
let method = req.method;
|
||||
|
||||
if (statusCode != "200" && statusCode != "204") {
|
||||
topuponline_metrics
|
||||
.labels({
|
||||
issuer_name: "CMS",
|
||||
method: method,
|
||||
route: url,
|
||||
status_code: statusCode,
|
||||
})
|
||||
.observe(responseTime);
|
||||
} else {
|
||||
topuponline_metrics
|
||||
.labels({
|
||||
issuer_name: "CMS",
|
||||
method: method,
|
||||
route: url,
|
||||
status_code: statusCode,
|
||||
})
|
||||
.observe(responseTime);
|
||||
}
|
||||
});
|
||||
next();
|
||||
};
|
||||
|
||||
module.exports = { prometheusMiddleware };
|
||||
@@ -13,13 +13,13 @@ let redisClient;
|
||||
password: '',
|
||||
});
|
||||
|
||||
redisClient.on('error', (error) => console.error(`Error : ${error}`));
|
||||
redisClient.on('error', (error) => {});
|
||||
|
||||
redisClient.on('connect', () => console.log('Redis is Connected'));
|
||||
|
||||
redisClient.on('ready', () => console.log('Redis is Ready'));
|
||||
|
||||
redisClient.on('reconnecting', () => console.log('Redis is Reconnecting'));
|
||||
redisClient.on('reconnecting', () => {});
|
||||
|
||||
await redisClient.connect();
|
||||
})();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -73,6 +73,11 @@ const validate = (method) => {
|
||||
.isEmpty()
|
||||
.withMessage('Reservation Number is required'),
|
||||
];
|
||||
case 'cancelReservationValidateV2':
|
||||
return [
|
||||
body('mid').not().isEmpty().withMessage('MID is required'),
|
||||
body('tid').not().isEmpty().withMessage('TID is required'),
|
||||
];
|
||||
case 'cancelReservationV2':
|
||||
return [
|
||||
body('cancel_reservation_data')
|
||||
@@ -965,16 +970,31 @@ const reservationValidateV2 = async (req, res) => {
|
||||
);
|
||||
|
||||
// get total reservation pending bersarkan nomor kartu yang di request yaitu total transaksi yang status nya pending beserta jumlah amount nya
|
||||
let getReservationPending = await model.getReservationPending(
|
||||
let getReservationPending = await model.getReservationPendingV2(
|
||||
card_number,
|
||||
now
|
||||
);
|
||||
|
||||
let dataReservationPending = [];
|
||||
let totalNominalReservationPending = 0;
|
||||
if (getReservationPending.length > 0) {
|
||||
for (const item of getReservationPending) {
|
||||
// hitung total reservasi yang masih pending / belum di topup
|
||||
totalNominalReservationPending =
|
||||
totalNominalReservationPending + parseInt(item.i_reservation_amount);
|
||||
|
||||
dataReservationPending.push({
|
||||
reservation_date: item.d_reservation,
|
||||
amount: parseInt(item.i_reservation_amount),
|
||||
partner_name: item.c_partner_name,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// jika nomor kartu yang di request ditemukan transaksi reservasi dengan status pending pada transaksi sebelumnya, maka jumlahkan total amount reservasi sebelumnya dengan amount reservasi yang dilakukan sekarang
|
||||
let totalReservationPending =
|
||||
getReservationPending.total_nominal_reservation > 0
|
||||
? parseInt(getReservationPending.total_nominal_reservation) +
|
||||
parseInt(amount)
|
||||
totalNominalReservationPending > 0
|
||||
? parseInt(totalNominalReservationPending) + parseInt(amount)
|
||||
: parseInt(amount);
|
||||
|
||||
// jika total amount reservasi melebihi maksimum reservasi sesuai dengan parameter setting di sistem CMS maka transaksi akan di tolak
|
||||
@@ -1057,9 +1077,12 @@ const reservationValidateV2 = async (req, res) => {
|
||||
code: '00',
|
||||
message: 'validation successfully.',
|
||||
data: {
|
||||
card_number: card_number,
|
||||
amount: amount,
|
||||
reservation_data: hash,
|
||||
reservation_detail: {
|
||||
card_number: card_number,
|
||||
amount: amount,
|
||||
},
|
||||
reservation_pending: dataReservationPending,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -2113,16 +2136,31 @@ const reservationV2 = async (req, res) => {
|
||||
);
|
||||
|
||||
// get total reservation pending bersarkan nomor kartu yang di request yaitu total transaksi yang status nya pending beserta jumlah amount nya
|
||||
let getReservationPending = await model.getReservationPending(
|
||||
let getReservationPending = await model.getReservationPendingV2(
|
||||
card_number,
|
||||
now
|
||||
);
|
||||
|
||||
let dataReservationPending = [];
|
||||
let totalNominalReservationPending = 0;
|
||||
if (getReservationPending.length > 0) {
|
||||
for (const item of getReservationPending) {
|
||||
// hitung total reservasi yang masih pending / belum di topup
|
||||
totalNominalReservationPending =
|
||||
totalNominalReservationPending + parseInt(item.i_reservation_amount);
|
||||
|
||||
dataReservationPending.push({
|
||||
reservation_date: item.d_reservation,
|
||||
amount: parseInt(item.i_reservation_amount),
|
||||
partner_name: item.c_partner_name,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// jika nomor kartu yang di request ditemukan transaksi reservasi dengan status pending pada transaksi sebelumnya, maka jumlahkan total amount reservasi sebelumnya dengan amount reservasi yang dilakukan sekarang
|
||||
let totalReservationPending =
|
||||
getReservationPending.total_nominal_reservation > 0
|
||||
? parseInt(getReservationPending.total_nominal_reservation) +
|
||||
parseInt(amount)
|
||||
totalNominalReservationPending > 0
|
||||
? parseInt(totalNominalReservationPending) + parseInt(amount)
|
||||
: parseInt(amount);
|
||||
|
||||
// jika total amount reservasi melebihi maksimum reservasi sesuai dengan parameter setting di sistem CMS maka transaksi akan di tolak
|
||||
@@ -2950,7 +2988,12 @@ const inquiryReservation = async (req, res) => {
|
||||
const inquiryReservationByReservation = async (req, res) => {
|
||||
try {
|
||||
// param
|
||||
let { reservation_number, ref_no, load_balance_number } = req.body;
|
||||
let {
|
||||
reservation_number,
|
||||
ref_no,
|
||||
load_balance_number,
|
||||
show_complete_data,
|
||||
} = req.body;
|
||||
|
||||
let result;
|
||||
|
||||
@@ -2965,7 +3008,7 @@ const inquiryReservationByReservation = async (req, res) => {
|
||||
}
|
||||
|
||||
// check reservation
|
||||
result = await model.inquiryListByRefNumber(ref_no);
|
||||
result = await model.inquiryListByRefNumber(ref_no, show_complete_data);
|
||||
} else if (req.query.search === 'load-balance-number') {
|
||||
// validation parameter inquiry
|
||||
if (!load_balance_number) {
|
||||
@@ -2977,7 +3020,10 @@ const inquiryReservationByReservation = async (req, res) => {
|
||||
}
|
||||
|
||||
// check reservation
|
||||
result = await model.inquiryListByLoadNumber(load_balance_number);
|
||||
result = await model.inquiryListByLoadNumber(
|
||||
load_balance_number,
|
||||
show_complete_data
|
||||
);
|
||||
} else {
|
||||
// validation parameter inquiry
|
||||
if (!reservation_number) {
|
||||
@@ -2989,7 +3035,10 @@ const inquiryReservationByReservation = async (req, res) => {
|
||||
}
|
||||
|
||||
// check reservation
|
||||
result = await model.inquiryByReservationNumber(reservation_number);
|
||||
result = await model.inquiryByReservationNumber(
|
||||
reservation_number,
|
||||
show_complete_data
|
||||
);
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
@@ -3086,11 +3135,11 @@ const cancelReservationValidateV2 = async (req, res) => {
|
||||
let result = {};
|
||||
|
||||
// param
|
||||
let { mid, tid, reservation_number } = req.body;
|
||||
let { mid, tid, reservation_number, ref_no } = req.body;
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ REQUEST CANCEL-RESERVATION-VALIDATE ]: ${JSON.stringify(
|
||||
`${uniqueCode} [ REQUEST CANCEL-RESERVATION-VALIDATE-V2 ]: ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
@@ -3106,7 +3155,7 @@ const cancelReservationValidateV2 = async (req, res) => {
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE ]: ${JSON.stringify(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE-V2 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
@@ -3117,7 +3166,7 @@ const cancelReservationValidateV2 = async (req, res) => {
|
||||
// log debug
|
||||
// proses pengecekkan data partner berdasarkan mid dan tid yang di request, apakah terdaftar di sistem CMS atau tidak
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING CANCEL-RESERVATION-VALIDATE ]: checking partner...`
|
||||
`${uniqueCode} [ PROCESSING CANCEL-RESERVATION-VALIDATE-V2 ]: checking partner...`
|
||||
);
|
||||
|
||||
// get partner, merchant, terminal from tid
|
||||
@@ -3131,40 +3180,109 @@ const cancelReservationValidateV2 = async (req, res) => {
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE ]: ${JSON.stringify(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE-V2 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
// proses pengecekkan status reservation number yang di request
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING CANCEL-RESERVATION-VALIDATE ]: getting reservation by reservation number...`
|
||||
);
|
||||
let getReservationCanBeCanceled;
|
||||
|
||||
// get reservation berdasarkan reservation number yang di request
|
||||
let getReservationCanBeCanceled = await model.getReservationCanBeCanceled(
|
||||
reservation_number
|
||||
);
|
||||
// jika cancelation reservation dilakukan dengan menggunakan ref no
|
||||
if (ref_no) {
|
||||
if (!ref_no) {
|
||||
result = {
|
||||
code: '400',
|
||||
message: 'Ref no is required',
|
||||
data: {},
|
||||
};
|
||||
|
||||
if (!getReservationCanBeCanceled) {
|
||||
result = {
|
||||
code: '414',
|
||||
message: "Reservation doesn't exist.",
|
||||
data: {},
|
||||
};
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE-V2 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
// proses pengecekkan status reservation number yang di request
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING CANCEL-RESERVATION-VALIDATE-V2 ]: getting reservation by ref no...`
|
||||
);
|
||||
return res.status(200).json(result);
|
||||
|
||||
// get reservation berdasarkan ref_no yang di request
|
||||
getReservationCanBeCanceled =
|
||||
await model.getReservationCanBeCanceledByRefno(ref_no);
|
||||
|
||||
if (!getReservationCanBeCanceled) {
|
||||
result = {
|
||||
code: '440',
|
||||
message: "Ref no doesn't exist.",
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE-V2 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
} else {
|
||||
if (!reservation_number) {
|
||||
result = {
|
||||
code: '400',
|
||||
message: 'Reservation number is required',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE-V2 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
// proses pengecekkan status reservation number yang di request
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING CANCEL-RESERVATION-VALIDATE-V2 ]: getting reservation by reservation number...`
|
||||
);
|
||||
|
||||
// get reservation berdasarkan reservation number yang di request
|
||||
getReservationCanBeCanceled = await model.getReservationCanBeCanceled(
|
||||
reservation_number
|
||||
);
|
||||
|
||||
if (!getReservationCanBeCanceled) {
|
||||
result = {
|
||||
code: '414',
|
||||
message: "Reservation doesn't exist.",
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE-V2 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
}
|
||||
|
||||
let reservationNumber = getReservationCanBeCanceled?.c_reservation_no;
|
||||
let cardNumber = getReservationCanBeCanceled?.c_card_number;
|
||||
let amount = getReservationCanBeCanceled?.i_reservation_amount;
|
||||
|
||||
// get value global parameter
|
||||
let getGlobalParameter = await model.getGlobalParameter();
|
||||
// check value global parameter
|
||||
@@ -3177,7 +3295,7 @@ const cancelReservationValidateV2 = async (req, res) => {
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE ]: ${JSON.stringify(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE-V2 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
@@ -3194,7 +3312,7 @@ const cancelReservationValidateV2 = async (req, res) => {
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE ]: ${JSON.stringify(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE-V2 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
@@ -3211,7 +3329,7 @@ const cancelReservationValidateV2 = async (req, res) => {
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE ]: ${JSON.stringify(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE-V2 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
@@ -3228,7 +3346,7 @@ const cancelReservationValidateV2 = async (req, res) => {
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE ]: ${JSON.stringify(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE-V2 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
@@ -3252,7 +3370,7 @@ const cancelReservationValidateV2 = async (req, res) => {
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE ]: ${JSON.stringify(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE-V2 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
@@ -3273,7 +3391,7 @@ const cancelReservationValidateV2 = async (req, res) => {
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE cancel reservation validate: ${JSON.stringify(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE-V2 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
@@ -3289,7 +3407,7 @@ const cancelReservationValidateV2 = async (req, res) => {
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE ]: ${JSON.stringify(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE-V2 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
@@ -3306,7 +3424,7 @@ const cancelReservationValidateV2 = async (req, res) => {
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE ]: ${JSON.stringify(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE-V2 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
@@ -3333,7 +3451,7 @@ const cancelReservationValidateV2 = async (req, res) => {
|
||||
// log debug
|
||||
// process enkripsi data reservasi dengan AES yang nanti nya akan di kirim ke end point reservation api untuk menyimpan data reservasi
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING RESERVATION-VALIDATE-V2 ] encrypting data reservation: ${JSON.stringify(
|
||||
`${uniqueCode} [ PROCESSING CANCEL-RESERVATION-VALIDATE-V2 ] encrypting data reservation: ${JSON.stringify(
|
||||
reservationData
|
||||
)}`
|
||||
);
|
||||
@@ -3346,12 +3464,17 @@ const cancelReservationValidateV2 = async (req, res) => {
|
||||
message: 'reservation can be canceled.',
|
||||
data: {
|
||||
cancel_reservation_data: hash,
|
||||
cancel_reservation_detail: {
|
||||
reservation_number: reservationNumber,
|
||||
card_number: cardNumber,
|
||||
amount: amount,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE ]: ${JSON.stringify(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE-V2 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
@@ -3360,7 +3483,7 @@ const cancelReservationValidateV2 = async (req, res) => {
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`[ RESPONSE CANCEL-RESERVATION-VALIDATE ]: 500 internal server error - backend server | ${error.message}`
|
||||
`[ RESPONSE CANCEL-RESERVATION-VALIDATE-V2 ]: 500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return res.status(200).json({
|
||||
@@ -3661,6 +3784,278 @@ const cancelReservationV2 = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
// ================================================================= CANCEL RESERVATION V2.1 =================================================================
|
||||
// *Created By: Mohamad Ihsan*
|
||||
// *Description:*
|
||||
// proses validate sekaligus insert data pembatalan reservasi saldo dengan memberikan flag pada reservation number yang di request sehingga reservation number tersebut tidak ter-load saat melakukan topup ke dalam kartu
|
||||
// proses di version v2.1 ini, bisa digunakan tanpa harus melakukan cancel reservation validate terlebih dahulu
|
||||
|
||||
const cancelReservationV2_1 = async (req, res) => {
|
||||
try {
|
||||
// generate unique code
|
||||
// unique code ini digunakan untuk keperluan log agar mudah untuk dibaca
|
||||
let uniqueCode = await helper.getUniqueCode();
|
||||
let result = {};
|
||||
|
||||
// param
|
||||
let { mid, tid, reservation_number } = req.body;
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ REQUEST CANCEL-RESERVATION-V2.1 ]: ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
|
||||
// check validator
|
||||
const err = validationResult(req, res);
|
||||
if (!err.isEmpty()) {
|
||||
result = {
|
||||
code: '400',
|
||||
message: err.errors[0].msg,
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-V2.1 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
// proses pengecekkan data partner berdasarkan mid dan tid yang di request, apakah terdaftar di sistem CMS atau tidak
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING CANCEL-RESERVATION-V2.1 ]: checking partner...`
|
||||
);
|
||||
|
||||
// get partner, merchant, terminal from tid
|
||||
let getPartner = await model.getPartner(mid, tid);
|
||||
if (!getPartner) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'terminal id is not valid',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-V2.1 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
// proses pengecekkan status reservation number yang di request
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING CANCEL-RESERVATION-V2.1 ]: getting reservation by reservation number...`
|
||||
);
|
||||
|
||||
// get reservation berdasarkan reservation number yang di request
|
||||
let getReservationCanBeCanceled = await model.getReservationCanBeCanceled(
|
||||
reservation_number
|
||||
);
|
||||
|
||||
// jika data reservasi ditemukan
|
||||
if (getReservationCanBeCanceled) {
|
||||
// jika status dari reservation number yang di request adalah I = In Progress atau A = Loaded, maka proses cancel reservasi akan di tolak
|
||||
if (
|
||||
getReservationCanBeCanceled.c_status == 'I' ||
|
||||
getReservationCanBeCanceled.c_status == 'A'
|
||||
) {
|
||||
result = {
|
||||
code: '429',
|
||||
message: 'can not be cancelled. The transaction has been loaded.',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-V2.1 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
} else if (getReservationCanBeCanceled.c_status == 'X') {
|
||||
// jika status dari reservation number yang di request adalah X = Deleted, maka proses cancel reservasi akan di tolak
|
||||
let cancelDate = getReservationCanBeCanceled.d_cancel
|
||||
? moment(getReservationCanBeCanceled.d_cancel).format(
|
||||
'DD-MM-YYYY HH:mm:ss'
|
||||
)
|
||||
: '';
|
||||
result = {
|
||||
code: '430',
|
||||
message: `can not be cancelled. The transaction has been canceled at ${cancelDate}.`,
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE cancel reservation validate: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
} else if (getReservationCanBeCanceled.c_payment_recon_no) {
|
||||
// jika reservation number yang di request sudah dilakukan payment recon, maka proses cancel reservasi akan di tolak
|
||||
result = {
|
||||
code: '430',
|
||||
message: `can not be cancelled. The transaction has been recon.`,
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-V2.1 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
} else {
|
||||
// jika reservation number yang di request tidak ditemukan di sistem CMS
|
||||
result = {
|
||||
code: '414',
|
||||
message: "Reservation doesn't exist.",
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-V2.1 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
// proses checking partner yang request cancel dengan data reservasi yang mau di cancel apakah dari partner yang sama
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING CANCEL-RESERVATION-V2.1 ]: checking partner request with partner reservation...`
|
||||
);
|
||||
|
||||
if (getPartner.i_partner != getReservationCanBeCanceled.i_partner) {
|
||||
// partner yang request cancel tidak sama dengan partner dari data reservasi
|
||||
result = {
|
||||
code: '438',
|
||||
message: `can not be cancelled on different source.`,
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-V2.1 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
// proses pencarian saldo terakhir dari nomor kartu yang di request berdasarkan data log hitory
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING CANCEL-RESERVATION-V2.1 ]: getting last balance on the card by card history...`
|
||||
);
|
||||
|
||||
// get last balance on the card
|
||||
let balance = 0;
|
||||
let getLastBalanceFromCardHistory =
|
||||
await model.getLastBalanceFromCardHistory(
|
||||
getReservationCanBeCanceled.c_card_number
|
||||
);
|
||||
if (getLastBalanceFromCardHistory) {
|
||||
balance = getLastBalanceFromCardHistory.m_balance_after;
|
||||
}
|
||||
|
||||
// time
|
||||
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||
|
||||
// binding data
|
||||
let data = {
|
||||
c_status: 'X',
|
||||
c_status_name: 'CANCELED',
|
||||
d_cancel: now,
|
||||
};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING CANCEL-RESERVATION-V2.1 ]: updating reservation to status cancel...`
|
||||
);
|
||||
|
||||
// cancel transaction
|
||||
await model.cancelReservation(data, reservation_number);
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING CANCEL-RESERVATION-V2.1 ]: inserting log for card history...`
|
||||
);
|
||||
|
||||
// log card history
|
||||
await model.createReserveBalanceLog({
|
||||
i_log_name: 110,
|
||||
d_log: now,
|
||||
c_card_number: getReservationCanBeCanceled.c_card_number,
|
||||
c_source: 'CMS',
|
||||
c_location: getPartner ? getPartner.partner_name : null,
|
||||
m_balance_before: balance > 0 ? balance : 0,
|
||||
m_amount: 0,
|
||||
m_balance_after: balance > 0 ? balance : 0,
|
||||
j_new_data: data,
|
||||
j_old_data: getReservationCanBeCanceled,
|
||||
c_note: `CANCEL RESERVE BALANCE ${
|
||||
getReservationCanBeCanceled.i_reservation_amount
|
||||
} FROM ${getPartner ? getPartner.partner_name : null}`,
|
||||
c_status: 'S',
|
||||
d_created: now,
|
||||
i_create: null,
|
||||
c_create_username: 'HSM',
|
||||
c_create_fullname: 'HARDWARE SECURE MODULE',
|
||||
c_category: 'T',
|
||||
});
|
||||
|
||||
result = {
|
||||
code: '00',
|
||||
message: 'reservation successfully canceled.',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-V2.1 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`[ RESPONSE CANCEL-RESERVATION-V2.1 ]: 500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return res.status(200).json({
|
||||
code: '500',
|
||||
message:
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
validate,
|
||||
checkReservation,
|
||||
@@ -3675,4 +4070,5 @@ module.exports = {
|
||||
inquiryListReservationByReservation,
|
||||
cancelReservationValidateV2,
|
||||
cancelReservationV2,
|
||||
cancelReservationV2_1,
|
||||
};
|
||||
|
||||
@@ -137,53 +137,101 @@ const getMaxReservation = () => {
|
||||
};
|
||||
|
||||
// INQUIRY BY RESERVATION NUMBER
|
||||
let inquiryByReservationNumber = (reservationNumber) => {
|
||||
let result = knex('trx.t_d_reservation_balance')
|
||||
.select(
|
||||
'c_reservation_no as reservation_number',
|
||||
'd_reservation as reservation_date',
|
||||
'c_ref_no as ref_no',
|
||||
'c_partner_name as partner_name',
|
||||
'c_merchant_name as merchant_name',
|
||||
'c_terminal_name as terminal_name',
|
||||
'c_card_number as card_number',
|
||||
'i_reservation_amount as reservation_amount',
|
||||
'i_issuer_fee as issuer_fee',
|
||||
'i_channel_fee as channel_fee',
|
||||
'c_payment_recon_no as payment_recon_no',
|
||||
'd_payment_recon as recon_date',
|
||||
'c_status as status_code',
|
||||
'c_status_name as description'
|
||||
)
|
||||
.where('c_reservation_no', reservationNumber)
|
||||
let inquiryByReservationNumber = (reservationNumber, show_complete_data) => {
|
||||
let result = knex('trx.t_d_reservation_balance');
|
||||
if (show_complete_data === true) {
|
||||
result.select(
|
||||
'trx.t_d_reservation_balance.c_reservation_no as reservation_number',
|
||||
'trx.t_d_reservation_balance.d_reservation as reservation_date',
|
||||
'trx.t_d_reservation_balance.c_ref_no as ref_no',
|
||||
'trx.t_d_reservation_balance.c_partner_name as partner_name_reservation',
|
||||
'trx.t_d_reservation_balance.c_merchant_name as merchant_name_reservation',
|
||||
'trx.t_d_reservation_balance.c_terminal_name as terminal_name_reservation',
|
||||
'trx.t_d_load_balance.d_load_balance as load_date',
|
||||
'trx.t_d_load_balance.c_partner_name as partner_name_load',
|
||||
'trx.t_d_load_balance.c_merchant_name as merchant_name_load',
|
||||
'trx.t_d_load_balance.c_terminal_name as terminal_name_load',
|
||||
'trx.t_d_reservation_balance.c_card_number as card_number',
|
||||
'trx.t_d_reservation_balance.i_reservation_amount as amount',
|
||||
'trx.t_d_reservation_balance.i_issuer_fee as issuer_fee',
|
||||
'trx.t_d_reservation_balance.i_channel_fee as channel_fee',
|
||||
'trx.t_d_reservation_balance.c_payment_recon_no as payment_recon_no',
|
||||
'trx.t_d_reservation_balance.d_payment_recon as recon_date',
|
||||
'trx.t_d_reservation_balance.c_status as status_code',
|
||||
'trx.t_d_reservation_balance.c_status_name as description'
|
||||
);
|
||||
} else {
|
||||
result.select(
|
||||
'trx.t_d_reservation_balance.c_reservation_no as reservation_number',
|
||||
'trx.t_d_reservation_balance.d_reservation as reservation_date',
|
||||
'trx.t_d_reservation_balance.c_ref_no as ref_no',
|
||||
'trx.t_d_reservation_balance.c_partner_name as partner_name_reservation',
|
||||
'trx.t_d_load_balance.d_load_balance as load_date',
|
||||
'trx.t_d_load_balance.c_partner_name as partner_name_load',
|
||||
'trx.t_d_reservation_balance.c_card_number as card_number',
|
||||
'trx.t_d_reservation_balance.i_reservation_amount as amount',
|
||||
'trx.t_d_reservation_balance.c_status as status_code',
|
||||
'trx.t_d_reservation_balance.c_status_name as description'
|
||||
);
|
||||
}
|
||||
|
||||
result.leftJoin('trx.t_d_load_balance', function () {
|
||||
this.on(
|
||||
'trx.t_d_reservation_balance.c_load_balance_no',
|
||||
'=',
|
||||
'trx.t_d_load_balance.c_load_balance_no'
|
||||
);
|
||||
});
|
||||
|
||||
result
|
||||
.where('trx.t_d_reservation_balance.c_reservation_no', reservationNumber)
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// INQUIRY LIST RESERVATION
|
||||
let inquiryListReservation = (partnerID, startDate, endDate) => {
|
||||
let result = knex('trx.t_d_reservation_balance')
|
||||
.select(
|
||||
'c_reservation_no as reservation_number',
|
||||
'd_reservation as reservation_date',
|
||||
'c_ref_no as ref_no',
|
||||
'c_partner_name as partner_name',
|
||||
'c_merchant_name as merchant_name',
|
||||
'c_terminal_name as terminal_name',
|
||||
'c_card_number as card_number',
|
||||
'i_reservation_amount as reservation_amount',
|
||||
'i_issuer_fee as issuer_fee',
|
||||
'i_channel_fee as channel_fee',
|
||||
'c_payment_recon_no as payment_recon_no',
|
||||
'd_payment_recon as recon_date',
|
||||
'c_status as status_code',
|
||||
'c_status_name as description'
|
||||
)
|
||||
.where('i_partner', partnerID);
|
||||
let result = knex('trx.t_d_reservation_balance');
|
||||
result.select(
|
||||
'trx.t_d_reservation_balance.c_reservation_no as reservation_number',
|
||||
'trx.t_d_reservation_balance.d_reservation as reservation_date',
|
||||
'trx.t_d_reservation_balance.c_ref_no as ref_no',
|
||||
'trx.t_d_reservation_balance.c_partner_name as partner_name_reservation',
|
||||
'trx.t_d_reservation_balance.c_merchant_name as merchant_name_reservation',
|
||||
'trx.t_d_reservation_balance.c_terminal_name as terminal_name_reservation',
|
||||
'trx.t_d_load_balance.d_load_balance as load_date',
|
||||
'trx.t_d_load_balance.c_partner_name as partner_name_load',
|
||||
'trx.t_d_load_balance.c_merchant_name as merchant_name_load',
|
||||
'trx.t_d_load_balance.c_terminal_name as terminal_name_load',
|
||||
'trx.t_d_reservation_balance.c_card_number as card_number',
|
||||
'trx.t_d_reservation_balance.i_reservation_amount as amount',
|
||||
'trx.t_d_reservation_balance.i_issuer_fee as issuer_fee',
|
||||
'trx.t_d_reservation_balance.i_channel_fee as channel_fee',
|
||||
'trx.t_d_reservation_balance.c_payment_recon_no as payment_recon_no',
|
||||
'trx.t_d_reservation_balance.d_payment_recon as recon_date',
|
||||
'trx.t_d_reservation_balance.c_status as status_code',
|
||||
'trx.t_d_reservation_balance.c_status_name as description'
|
||||
);
|
||||
|
||||
result.leftJoin('trx.t_d_load_balance', function () {
|
||||
this.on(
|
||||
'trx.t_d_reservation_balance.c_load_balance_no',
|
||||
'=',
|
||||
'trx.t_d_load_balance.c_load_balance_no'
|
||||
);
|
||||
});
|
||||
|
||||
result.where('trx.t_d_reservation_balance.i_partner', partnerID);
|
||||
|
||||
if (startDate && endDate) {
|
||||
result.whereRaw('??::date >= ?', ['d_reservation', startDate]);
|
||||
result.whereRaw('??::date <= ?', ['d_reservation', endDate]);
|
||||
result.whereRaw('??::date >= ?', [
|
||||
'trx.t_d_reservation_balance.d_reservation',
|
||||
startDate,
|
||||
]);
|
||||
result.whereRaw('??::date <= ?', [
|
||||
'trx.t_d_reservation_balance.d_reservation',
|
||||
endDate,
|
||||
]);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -200,7 +248,7 @@ let inquiryByCardNumber = (cardNumber, startDate, endDate) => {
|
||||
'c_merchant_name as merchant_name',
|
||||
'c_terminal_name as terminal_name',
|
||||
'c_card_number as card_number',
|
||||
'i_reservation_amount as reservation_amount',
|
||||
'i_reservation_amount as amount',
|
||||
'i_issuer_fee as issuer_fee',
|
||||
'i_channel_fee as channel_fee',
|
||||
'c_status as status_code',
|
||||
@@ -222,11 +270,37 @@ const getReservationPending = (cardNumber, time) => {
|
||||
.sum('i_reservation_amount as total_nominal_reservation')
|
||||
.where('c_card_number', cardNumber)
|
||||
.where('c_status', 'P')
|
||||
.whereRaw(
|
||||
`c_reservation_no NOT IN (SELECT c_reservation_no FROM trx.t_d_fraud tdf WHERE tdf.c_status = 'A' AND tdf.c_card_number = '${cardNumber}')`
|
||||
)
|
||||
// .where("d_expired", ">=", time)
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
const getReservationPendingV2 = (cardNumber, time) => {
|
||||
let result = knex('trx.t_d_reservation_balance')
|
||||
// .sum("i_reservation_amount as total_reservation_amount")
|
||||
// .count("* as total_reservation")
|
||||
.select(
|
||||
'i_reservation_amount',
|
||||
'c_reservation_no',
|
||||
'c_partner_name',
|
||||
'c_flag',
|
||||
'd_reservation',
|
||||
'c_ref_no',
|
||||
'c_card_number',
|
||||
'c_status'
|
||||
)
|
||||
.where('c_card_number', cardNumber)
|
||||
.where('c_status', 'P')
|
||||
.whereRaw(
|
||||
`c_reservation_no NOT IN (SELECT c_reservation_no FROM trx.t_d_fraud tdf WHERE tdf.c_status = 'A' AND tdf.c_card_number = '${cardNumber}')`
|
||||
);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET RESERVATION WITH FLAG
|
||||
const getReservationWithFlag = (cardNumber, time) => {
|
||||
let result = knex('trx.t_d_reservation_balance')
|
||||
@@ -304,6 +378,14 @@ const getReservationCanBeCanceled = (reservation_number) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET RESERVATION PENDING AND NOT YET PAYMENT RECON
|
||||
const getReservationCanBeCanceledByRefno = (ref_no) => {
|
||||
let result = knex('trx.t_d_reservation_balance')
|
||||
.where('c_ref_no', ref_no)
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
const insertReservationNumber = (reservationNumber) => {
|
||||
let result = knex('trx.t_d_reservation_no_validate')
|
||||
.insert({
|
||||
@@ -328,36 +410,10 @@ const deleteReservationNumberValidate = (reservationNumber) => {
|
||||
};
|
||||
|
||||
// INQUIRY BY REF NUMBER
|
||||
let inquiryListByRefNumber = (refNumber) => {
|
||||
let result = knex('trx.t_d_reservation_balance')
|
||||
.select(
|
||||
'c_reservation_no as reservation_number',
|
||||
'd_reservation as reservation_date',
|
||||
'c_ref_no as ref_no',
|
||||
'c_partner_name as partner_name',
|
||||
'c_merchant_name as merchant_name',
|
||||
'c_terminal_name as terminal_name',
|
||||
'c_card_number as card_number',
|
||||
'i_reservation_amount as reservation_amount',
|
||||
'i_issuer_fee as issuer_fee',
|
||||
'i_channel_fee as channel_fee',
|
||||
'c_status as status_code',
|
||||
'c_status_name as description'
|
||||
)
|
||||
.where('c_ref_no', refNumber);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
// ================================================================= INQUIRY LOAD BALANCE =================================================================
|
||||
// *Created By: Teddy Setiawan*
|
||||
// *Description:*
|
||||
//
|
||||
|
||||
// INQUIRY BY LOAD BALANCE NUMBER
|
||||
const inquiryListByLoadNumber = (load_balance_number) => {
|
||||
let result = knex('trx.t_d_reservation_balance')
|
||||
.select(
|
||||
let inquiryListByRefNumber = (refNumber, show_complete_data) => {
|
||||
let result = knex('trx.t_d_reservation_balance');
|
||||
if (show_complete_data === true) {
|
||||
result.select(
|
||||
'trx.t_d_reservation_balance.c_reservation_no as reservation_number',
|
||||
'trx.t_d_reservation_balance.d_reservation as reservation_date',
|
||||
'trx.t_d_reservation_balance.c_ref_no as ref_no',
|
||||
@@ -369,14 +425,86 @@ const inquiryListByLoadNumber = (load_balance_number) => {
|
||||
'trx.t_d_load_balance.c_merchant_name as merchant_name_load',
|
||||
'trx.t_d_load_balance.c_terminal_name as terminal_name_load',
|
||||
'trx.t_d_reservation_balance.c_card_number as card_number',
|
||||
'trx.t_d_reservation_balance.i_reservation_amount as reservation_amount',
|
||||
'trx.t_d_reservation_balance.i_reservation_amount as amount',
|
||||
'trx.t_d_reservation_balance.i_issuer_fee as issuer_fee',
|
||||
'trx.t_d_reservation_balance.i_channel_fee as channel_fee',
|
||||
'trx.t_d_reservation_balance.c_status as status_code',
|
||||
'trx.t_d_reservation_balance.c_status_name as description'
|
||||
);
|
||||
} else {
|
||||
result.select(
|
||||
'trx.t_d_reservation_balance.c_reservation_no as reservation_number',
|
||||
'trx.t_d_reservation_balance.d_reservation as reservation_date',
|
||||
'trx.t_d_reservation_balance.c_ref_no as ref_no',
|
||||
'trx.t_d_reservation_balance.c_partner_name as partner_name_reservation',
|
||||
'trx.t_d_load_balance.d_load_balance as load_date',
|
||||
'trx.t_d_load_balance.c_partner_name as partner_name_load',
|
||||
'trx.t_d_reservation_balance.c_card_number as card_number',
|
||||
'trx.t_d_reservation_balance.i_reservation_amount as amount',
|
||||
'trx.t_d_reservation_balance.c_status as status_code',
|
||||
'trx.t_d_reservation_balance.c_status_name as description'
|
||||
);
|
||||
}
|
||||
|
||||
result.leftJoin('trx.t_d_load_balance', function () {
|
||||
this.on(
|
||||
'trx.t_d_reservation_balance.c_load_balance_no',
|
||||
'=',
|
||||
'trx.t_d_load_balance.c_load_balance_no'
|
||||
);
|
||||
});
|
||||
|
||||
result.where('trx.t_d_reservation_balance.c_ref_no', refNumber).first();
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
// ================================================================= INQUIRY LOAD BALANCE =================================================================
|
||||
// *Created By: Teddy Setiawan*
|
||||
// *Description:*
|
||||
//
|
||||
|
||||
// INQUIRY BY LOAD BALANCE NUMBER
|
||||
const inquiryListByLoadNumber = (load_balance_number, show_complete_data) => {
|
||||
let result = knex('trx.t_d_reservation_balance');
|
||||
|
||||
if (show_complete_data === true) {
|
||||
result.select(
|
||||
'trx.t_d_reservation_balance.c_reservation_no as reservation_number',
|
||||
'trx.t_d_reservation_balance.d_reservation as reservation_date',
|
||||
'trx.t_d_reservation_balance.c_ref_no as ref_no',
|
||||
'trx.t_d_reservation_balance.c_partner_name as partner_name_reservation',
|
||||
'trx.t_d_reservation_balance.c_merchant_name as merchant_name_reservation',
|
||||
'trx.t_d_reservation_balance.c_terminal_name as terminal_name_reservation',
|
||||
'trx.t_d_load_balance.d_load_balance as load_date',
|
||||
'trx.t_d_load_balance.c_partner_name as partner_name_load',
|
||||
'trx.t_d_load_balance.c_merchant_name as merchant_name_load',
|
||||
'trx.t_d_load_balance.c_terminal_name as terminal_name_load',
|
||||
'trx.t_d_reservation_balance.c_card_number as card_number',
|
||||
'trx.t_d_reservation_balance.i_reservation_amount as amount',
|
||||
'trx.t_d_reservation_balance.i_issuer_fee as issuer_fee',
|
||||
'trx.t_d_reservation_balance.i_channel_fee as channel_fee',
|
||||
'trx.t_d_reservation_balance.c_payment_recon_no as payment_recon_no',
|
||||
'trx.t_d_reservation_balance.d_payment_recon as recon_date',
|
||||
'trx.t_d_reservation_balance.c_status as status_code',
|
||||
'trx.t_d_reservation_balance.c_status_name as description'
|
||||
)
|
||||
);
|
||||
} else {
|
||||
result.select(
|
||||
'trx.t_d_reservation_balance.c_reservation_no as reservation_number',
|
||||
'trx.t_d_reservation_balance.d_reservation as reservation_date',
|
||||
'trx.t_d_reservation_balance.c_ref_no as ref_no',
|
||||
'trx.t_d_reservation_balance.c_partner_name as partner_name_reservation',
|
||||
'trx.t_d_load_balance.d_load_balance as load_date',
|
||||
'trx.t_d_load_balance.c_partner_name as partner_name_load',
|
||||
'trx.t_d_reservation_balance.c_card_number as card_number',
|
||||
'trx.t_d_reservation_balance.i_reservation_amount as amount',
|
||||
'trx.t_d_reservation_balance.c_status as status_code',
|
||||
'trx.t_d_reservation_balance.c_status_name as description'
|
||||
);
|
||||
}
|
||||
|
||||
result
|
||||
.leftJoin('trx.t_d_load_balance', function () {
|
||||
this.on(
|
||||
'trx.t_d_reservation_balance.c_load_balance_no',
|
||||
@@ -417,6 +545,7 @@ module.exports = {
|
||||
inquiryListReservation,
|
||||
inquiryByCardNumber,
|
||||
getReservationPending,
|
||||
getReservationPendingV2,
|
||||
getReservationWithFlag,
|
||||
insertReservation,
|
||||
getLastBalanceFromCardHistory,
|
||||
@@ -424,6 +553,7 @@ module.exports = {
|
||||
createReserveBalanceLog,
|
||||
getReservationWithPendingAndInProgressStatus,
|
||||
getReservationCanBeCanceled,
|
||||
getReservationCanBeCanceledByRefno,
|
||||
insertReservationNumber,
|
||||
cancelReservation,
|
||||
deleteReservationNumberValidate,
|
||||
|
||||
@@ -10,17 +10,4 @@ router.post(
|
||||
controller.loadingBalanceRequest
|
||||
);
|
||||
|
||||
router.post(
|
||||
'/loadbalance',
|
||||
auth.authenticateToken,
|
||||
controller.validate('loadingBalance'),
|
||||
controller.loadingBalance
|
||||
);
|
||||
|
||||
router.post(
|
||||
'/loadbalance/inquiry',
|
||||
auth.authenticateToken,
|
||||
controller.inquiryLoadingBalance
|
||||
);
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const auth = require('../middlewares/jwt.middleware');
|
||||
const lokiMiddleware = require('../middlewares/loki.middleware');
|
||||
const {
|
||||
prometheusMiddleware,
|
||||
} = require('../middlewares/prometheus.middleware');
|
||||
const {
|
||||
getReservationNumberSequence,
|
||||
} = require('../middlewares/redis.middleware');
|
||||
@@ -28,8 +24,6 @@ router.post(
|
||||
router.post(
|
||||
'/reservation',
|
||||
auth.authenticateToken,
|
||||
prometheusMiddleware,
|
||||
lokiMiddleware,
|
||||
getReservationNumberSequence,
|
||||
controller.validate('reservation'),
|
||||
controller.reservation
|
||||
@@ -78,8 +72,6 @@ router.post(
|
||||
router.post(
|
||||
'/reservation/v2',
|
||||
auth.authenticateToken,
|
||||
prometheusMiddleware,
|
||||
lokiMiddleware,
|
||||
getReservationNumberSequence,
|
||||
controller.validate('reservationV2'),
|
||||
controller.reservationV2
|
||||
@@ -88,7 +80,7 @@ router.post(
|
||||
router.post(
|
||||
'/reservation/cancel/validate/v2',
|
||||
auth.authenticateToken,
|
||||
controller.validate('cancelReservation'),
|
||||
controller.validate('cancelReservationValidateV2'),
|
||||
controller.cancelReservationValidateV2
|
||||
);
|
||||
|
||||
@@ -99,4 +91,11 @@ router.post(
|
||||
controller.cancelReservationV2
|
||||
);
|
||||
|
||||
// router.post(
|
||||
// '/reservation/cancel/v2.1',
|
||||
// auth.authenticateToken,
|
||||
// controller.validate('cancelReservation'),
|
||||
// controller.cancelReservationV2_1
|
||||
// );
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -21,6 +21,12 @@ DB_PASSWORD_LOCAL=postgres
|
||||
REDIS_URL=redis://localhost:6379
|
||||
REDIS_PASSWORD=
|
||||
|
||||
# ==================================== LOKI =====================================
|
||||
LOKI_URL=http://10.20.14.30:3100
|
||||
|
||||
# ==================================== APP PROMETHEUS =====================================
|
||||
PROM_APP = topuponline
|
||||
|
||||
# ================================== SECRET KEY ==================================
|
||||
# FOR PRODUCTION
|
||||
#SECRET_KEY=U2FsdGVkX19keaNhiBfdNSWnKA2a8Z5deBu/KkU6BNg=
|
||||
|
||||
+5
-2
@@ -21,14 +21,17 @@ const { logger } = require('../application/helpers/getbodyrequest');
|
||||
const client = require('prom-client');
|
||||
const register = new client.Registry();
|
||||
const {
|
||||
topuponline_metrics,
|
||||
topuponline_metrics, topuponline_metrics_response_time,topuponline_metrics_load_balance
|
||||
} = require('../application/helpers/prometheusmetrics');
|
||||
|
||||
const app = express();
|
||||
|
||||
register.setDefaultLabels({ app: 'topuponline' });
|
||||
let promApp = process.env.PROM_APP || "topuponline";
|
||||
register.setDefaultLabels({ app: promApp });
|
||||
client.collectDefaultMetrics({ register });
|
||||
register.registerMetric(topuponline_metrics);
|
||||
register.registerMetric(topuponline_metrics_response_time);
|
||||
register.registerMetric(topuponline_metrics_load_balance);
|
||||
|
||||
app.get('/metrics', (req, res) => {
|
||||
res.setHeader('Content-Type', register.contentType);
|
||||
|
||||
Reference in New Issue
Block a user