mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-05 17:36:28 +00:00
Compare commits
57 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 98c9fbe577 | |||
| dcea11420b | |||
| ff84e687ed | |||
| 2c132afdb1 | |||
| 6df951da14 | |||
| d3d28e496f | |||
| 11b5d2317c | |||
| fb5565f399 | |||
| 0df4fc0091 | |||
| 05c69b0e1d | |||
| 7ca95e17c0 | |||
| b07e9eda89 | |||
| 920284f07d | |||
| f97c9e6c66 | |||
| c885c49925 | |||
| 04128c8b86 | |||
| 663b92c759 | |||
| ff1582e50d | |||
| 0b921f3dc6 | |||
| ee9fa58b94 | |||
| 625ad19907 | |||
| f1e659c64a | |||
| df7d6909a3 | |||
| c5b75058d3 | |||
| 18cab4b93b | |||
| 40990b3498 | |||
| fa43d34c90 | |||
| 5a0d579405 | |||
| 8e9f9dca82 | |||
| c8755f9e2d | |||
| f2e6b31b82 | |||
| 751191e10e | |||
| 33039fab21 | |||
| 2c31a4e425 | |||
| b5b72ecf6c | |||
| b7e5d0c426 | |||
| 82bd1c5276 | |||
| c39675b1ac | |||
| 146e64fc63 | |||
| 058cd6edfc | |||
| 3fb2124534 | |||
| c4f276289a | |||
| f8aacae0ea | |||
| 0e237bd66d | |||
| 8e8704a1a2 | |||
| 25c3d03761 | |||
| 3be8c88db4 | |||
| 983902d08e | |||
| 7a09320404 | |||
| ff245148f6 | |||
| 5a4870408c | |||
| e3ef16753e | |||
| 90aaf3f6f6 | |||
| 0437eaab25 | |||
| 4a98a1c5cd | |||
| 3c927b6385 | |||
| 41bdf42bac |
@@ -3,6 +3,13 @@ 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 filename = () => {
|
||||
if (!fs.existsSync(`./expresswinstonlog`)) {
|
||||
@@ -28,6 +35,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 +56,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 +71,192 @@ 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"
|
||||
) {
|
||||
console.log(statusCode);
|
||||
winstonLoki.log.error({
|
||||
message: message,
|
||||
labels: {
|
||||
route: url,
|
||||
status_code: statusCode,
|
||||
issuer_name: issuerName,
|
||||
},
|
||||
});
|
||||
} 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 +264,6 @@ const logger = {
|
||||
filename: "./expresswinstonlog/%DATE%.log",
|
||||
frequency: "24h",
|
||||
datePattern: "YYYY/MM/DD",
|
||||
zippedArchive: true,
|
||||
maxFiles: "1d",
|
||||
}),
|
||||
],
|
||||
@@ -89,4 +284,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,23 @@ let redisClient;
|
||||
password: '',
|
||||
});
|
||||
|
||||
redisClient.on('error', (error) => console.error(`Error : ${error}`));
|
||||
redisClient.on('error', (error) =>
|
||||
// process.env.NODE_ENV.toUpperCase() != 'PRODUCTION'
|
||||
// ? console.error(`Error : ${error}`)
|
||||
// : ''
|
||||
process.env.NODE_ENV.toUpperCase() != 'PRODUCTION' ? '' : ''
|
||||
);
|
||||
|
||||
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', () =>
|
||||
// process.env.NODE_ENV.toUpperCase() != 'PRODUCTION'
|
||||
// ? console.log('Redis is Reconnecting')
|
||||
// : ''
|
||||
process.env.NODE_ENV.toUpperCase() != 'PRODUCTION' ? '' : ''
|
||||
);
|
||||
|
||||
await redisClient.connect();
|
||||
})();
|
||||
|
||||
@@ -42,7 +42,7 @@ const cardHistory = async (req, res) => {
|
||||
// generate unique code
|
||||
// unique code ini digunakan untuk keperluan log agar mudah untuk dibaca
|
||||
let uniqueCode = await helper.getUniqueCode();
|
||||
let result = {};
|
||||
let result = [];
|
||||
|
||||
// param
|
||||
let { data } = req.body;
|
||||
@@ -58,7 +58,7 @@ const cardHistory = async (req, res) => {
|
||||
result = {
|
||||
code: '400',
|
||||
message: err.errors[0].msg,
|
||||
data: {},
|
||||
data: [],
|
||||
};
|
||||
|
||||
// log warn
|
||||
@@ -178,7 +178,7 @@ const cardHistory = async (req, res) => {
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
data: [],
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
const helper = require("../../helpers/helper");
|
||||
const winston = require("../../helpers/winston.logger");
|
||||
const generate = require("./utils/utils");
|
||||
const helper = require('../../helpers/helper');
|
||||
const winston = require('../../helpers/winston.logger');
|
||||
const generate = require('./utils/utils');
|
||||
const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
require("dotenv").config();
|
||||
require('dotenv').config();
|
||||
|
||||
let useClient;
|
||||
var counterDirect = 0;
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == "1") {
|
||||
var { client } = require("./services/webSocket");
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '1') {
|
||||
var { client } = require('./services/webSocket');
|
||||
|
||||
useClient = client;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == "2") {
|
||||
var { client2 } = require("./services/webSocket2");
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '2') {
|
||||
var { client2 } = require('./services/webSocket2');
|
||||
|
||||
useClient = client2;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == "12") {
|
||||
var { client } = require("./services/webSocket");
|
||||
var { client2 } = require("./services/webSocket2");
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
var { client } = require('./services/webSocket');
|
||||
var { client2 } = require('./services/webSocket2');
|
||||
}
|
||||
|
||||
const controller = async (req, res) => {
|
||||
@@ -31,11 +31,11 @@ const controller = async (req, res) => {
|
||||
let { body } = req;
|
||||
// uniqueCode = body.unique_code;
|
||||
let uniqueCode = await helper.getUniqueCode();
|
||||
uniqueCode = uniqueCode+''+counterDirect;
|
||||
uniqueCode = uniqueCode + '' + counterDirect;
|
||||
let result = {};
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == "12") {
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
// set request to HSM server 2
|
||||
if (uniqueCode) {
|
||||
if (parseInt(uniqueCode) % 2 == 0) {
|
||||
@@ -74,11 +74,15 @@ const controller = async (req, res) => {
|
||||
}
|
||||
|
||||
// log info
|
||||
winston.logger.info(`${uniqueCode} REQUEST load balance - STARTING...`);
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ REQUEST LOADING-BALANCE TOPUP-1 ]: STARTING TOP UP...`
|
||||
);
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} request HSM - auth1v2: ${JSON.stringify(req.body)}`
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE TOPUP-1 ]: ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
|
||||
let felicaPollingResponse = Buffer.from(
|
||||
@@ -107,7 +111,7 @@ const controller = async (req, res) => {
|
||||
_timeOut = true;
|
||||
}, 10000);
|
||||
|
||||
useClient.ws.on("message", (message) => {
|
||||
useClient.ws.on('message', (message) => {
|
||||
let __validasi = generate.buf2hex(message).slice(14, 30);
|
||||
while (
|
||||
message[2] == 1 &&
|
||||
@@ -119,7 +123,9 @@ const controller = async (req, res) => {
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} HSM - message Auth1v2: ${generate.buf2hex(message)}`
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE TOPUP-1 ]: message from HSM ${generate.buf2hex(
|
||||
message
|
||||
)}`
|
||||
);
|
||||
|
||||
respData = message;
|
||||
@@ -155,8 +161,8 @@ const controller = async (req, res) => {
|
||||
|
||||
if (respData1) {
|
||||
result = {
|
||||
code: "00",
|
||||
message: "Request Authenticate 1 Success",
|
||||
code: '00',
|
||||
message: 'Request Authenticate 1 Success',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respCode,
|
||||
@@ -167,8 +173,8 @@ const controller = async (req, res) => {
|
||||
};
|
||||
} else {
|
||||
result = {
|
||||
code: "5004",
|
||||
message: "Empty Data from HSM",
|
||||
code: '5004',
|
||||
message: 'Empty Data from HSM',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respCode,
|
||||
@@ -181,22 +187,24 @@ const controller = async (req, res) => {
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} response HSM - auth1v2: ${JSON.stringify(result)}`
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE TOPUP-1 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`500 internal server error - backend server | ${error.message}`
|
||||
`[ RESPONSE LOADING-BALANCE TOPUP-1 ]: 500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
code: "5001",
|
||||
code: '5001',
|
||||
message:
|
||||
process.env.NODE_ENV != "production"
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: "500 internal server error - backend server.",
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
const winston = require("../../helpers/winston.logger");
|
||||
const generate = require("./utils/utils");
|
||||
const winston = require('../../helpers/winston.logger');
|
||||
const generate = require('./utils/utils');
|
||||
const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
require("dotenv").config();
|
||||
require('dotenv').config();
|
||||
|
||||
let useClient;
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == "1") {
|
||||
var { client } = require("./services/webSocket");
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '1') {
|
||||
var { client } = require('./services/webSocket');
|
||||
|
||||
useClient = client;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == "2") {
|
||||
var { client2 } = require("./services/webSocket2");
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '2') {
|
||||
var { client2 } = require('./services/webSocket2');
|
||||
|
||||
useClient = client2;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == "12") {
|
||||
var { client } = require("./services/webSocket");
|
||||
var { client2 } = require("./services/webSocket2");
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
var { client } = require('./services/webSocket');
|
||||
var { client2 } = require('./services/webSocket2');
|
||||
}
|
||||
|
||||
const controller = async (req, res) => {
|
||||
@@ -27,11 +27,13 @@ const controller = async (req, res) => {
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} request HSM - auth2v2: ${JSON.stringify(req.body)}`
|
||||
`${uniqueCode} [ REQUEST LOADING-BALANCE TOPUP-2 ]: ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == "12") {
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
// set request to HSM server 2
|
||||
if (uniqueCode) {
|
||||
if (parseInt(uniqueCode) % 2 == 0) {
|
||||
@@ -60,14 +62,16 @@ const controller = async (req, res) => {
|
||||
|
||||
if (auth2v2requestData[0] != 0x41) {
|
||||
result = {
|
||||
code: "5003",
|
||||
message: "Wrong Respone from Card",
|
||||
code: '5003',
|
||||
message: 'Wrong Respone from Card',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} response HSM - auth2v2: ${JSON.stringify(result)}`
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE TOPUP-2 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
@@ -84,7 +88,7 @@ const controller = async (req, res) => {
|
||||
|
||||
let respData = null;
|
||||
let respData1 = null;
|
||||
useClient.ws.on("message", (message) => {
|
||||
useClient.ws.on('message', (message) => {
|
||||
while (
|
||||
message[2] == 2 &&
|
||||
message[0] == _validationTrxID[0] &&
|
||||
@@ -96,7 +100,9 @@ const controller = async (req, res) => {
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} HSM - message Auth2v2: ${generate.buf2hex(message)}`
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE TOPUP-2 ]: message from HSM ${generate.buf2hex(
|
||||
message
|
||||
)}`
|
||||
);
|
||||
|
||||
respData = message;
|
||||
@@ -116,8 +122,8 @@ const controller = async (req, res) => {
|
||||
respData1 = generate.getResponseData(respData);
|
||||
|
||||
result = {
|
||||
code: "00",
|
||||
message: "Request Authenticate 2 Success",
|
||||
code: '00',
|
||||
message: 'Request Authenticate 2 Success',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respCode,
|
||||
@@ -128,22 +134,24 @@ const controller = async (req, res) => {
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} response HSM - auth2v2: ${JSON.stringify(result)}`
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE TOPUP-2 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`500 internal server error - backend server | ${error.message}`
|
||||
`[ RESPONSE LOADING-BALANCE TOPUP-2 ]: 500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
code: "5001",
|
||||
code: '5001',
|
||||
message:
|
||||
process.env.NODE_ENV != "production"
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: "500 internal server error - backend server.",
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
const winston = require("../../helpers/winston.logger");
|
||||
const generate = require("./utils/utils");
|
||||
const winston = require('../../helpers/winston.logger');
|
||||
const generate = require('./utils/utils');
|
||||
const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
require("dotenv").config();
|
||||
require('dotenv').config();
|
||||
|
||||
let useClient;
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == "1") {
|
||||
var { client } = require("./services/webSocket");
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '1') {
|
||||
var { client } = require('./services/webSocket');
|
||||
|
||||
useClient = client;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == "2") {
|
||||
var { client2 } = require("./services/webSocket2");
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '2') {
|
||||
var { client2 } = require('./services/webSocket2');
|
||||
|
||||
useClient = client2;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == "12") {
|
||||
var { client } = require("./services/webSocket");
|
||||
var { client2 } = require("./services/webSocket2");
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
var { client } = require('./services/webSocket');
|
||||
var { client2 } = require('./services/webSocket2');
|
||||
}
|
||||
|
||||
const controller = async (req, res) => {
|
||||
@@ -27,11 +27,13 @@ const controller = async (req, res) => {
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} request auth2v2 Resp: ${JSON.stringify(req.body)}`
|
||||
`${uniqueCode} [ REQUEST LOADING-BALANCE TOPUP-3 ]: request to HSM ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == "12") {
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
// set request to HSM server 2
|
||||
if (uniqueCode) {
|
||||
if (parseInt(uniqueCode) % 2 == 0) {
|
||||
@@ -62,14 +64,16 @@ const controller = async (req, res) => {
|
||||
|
||||
if (auth2v2responseSetData[0] != 0x43) {
|
||||
result = {
|
||||
code: "5003",
|
||||
message: "Wrong Respone from Card",
|
||||
code: '5003',
|
||||
message: 'Wrong Respone from Card',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} response HSM - auth2v2 resp: ${JSON.stringify(result)}`
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE TOPUP-3 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
@@ -87,7 +91,7 @@ const controller = async (req, res) => {
|
||||
let respData = null;
|
||||
let respData1 = null;
|
||||
|
||||
useClient.ws.on("message", (message) => {
|
||||
useClient.ws.on('message', (message) => {
|
||||
while (
|
||||
message[2] == 3 &&
|
||||
message[0] == transactionId[0] &&
|
||||
@@ -99,7 +103,7 @@ const controller = async (req, res) => {
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} HSM - message auth2v2 Resp: ${generate.buf2hex(
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE TOPUP-3 ]: message from HSM ${generate.buf2hex(
|
||||
message
|
||||
)}`
|
||||
);
|
||||
@@ -121,8 +125,8 @@ const controller = async (req, res) => {
|
||||
respData1 = generate.getResponseData(respData);
|
||||
|
||||
result = {
|
||||
code: "00",
|
||||
message: "Request Authenticate Resp Success",
|
||||
code: '00',
|
||||
message: 'Request Authenticate Resp Success',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respCode,
|
||||
@@ -133,22 +137,24 @@ const controller = async (req, res) => {
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} response HSM - auth2v2 resp: ${JSON.stringify(result)}`
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE TOPUP-3 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`500 internal server error - backend server | ${error.message}`
|
||||
`[ RESPONSE LOADING-BALANCE TOPUP-3 ]: 500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
code: "5001",
|
||||
code: '5001',
|
||||
message:
|
||||
process.env.NODE_ENV != "production"
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: "500 internal server error - backend server.",
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
const winston = require("../../helpers/winston.logger");
|
||||
const generate = require("./utils/utils");
|
||||
const winston = require('../../helpers/winston.logger');
|
||||
const generate = require('./utils/utils');
|
||||
const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
require("dotenv").config();
|
||||
require('dotenv').config();
|
||||
|
||||
let useClient;
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == "1") {
|
||||
var { client } = require("./services/webSocket");
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '1') {
|
||||
var { client } = require('./services/webSocket');
|
||||
|
||||
useClient = client;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == "2") {
|
||||
var { client2 } = require("./services/webSocket2");
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '2') {
|
||||
var { client2 } = require('./services/webSocket2');
|
||||
|
||||
useClient = client2;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == "12") {
|
||||
var { client } = require("./services/webSocket");
|
||||
var { client2 } = require("./services/webSocket2");
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
var { client } = require('./services/webSocket');
|
||||
var { client2 } = require('./services/webSocket2');
|
||||
}
|
||||
|
||||
const controller = async (req, res) => {
|
||||
@@ -27,11 +27,13 @@ const controller = async (req, res) => {
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} request HSM - end transaction: ${JSON.stringify(req.body)}`
|
||||
`${uniqueCode} [ REQUEST LOADING-BALANCE TOPUP-8 ]: ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == "12") {
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
// set request to HSM server 2
|
||||
if (uniqueCode) {
|
||||
if (parseInt(uniqueCode) % 2 == 0) {
|
||||
@@ -70,7 +72,7 @@ const controller = async (req, res) => {
|
||||
let respData = null;
|
||||
let respData1 = null;
|
||||
|
||||
useClient.ws.on("message", (message) => {
|
||||
useClient.ws.on('message', (message) => {
|
||||
while (
|
||||
message[2] == 6 &&
|
||||
message[0] == transactionId[0] &&
|
||||
@@ -82,7 +84,7 @@ const controller = async (req, res) => {
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} HSM - message end transaction: ${generate.buf2hex(
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE TOPUP-8 ]: message from HSM ${generate.buf2hex(
|
||||
message
|
||||
)}`
|
||||
);
|
||||
@@ -104,35 +106,34 @@ const controller = async (req, res) => {
|
||||
respData1 = generate.getResponseData(respData);
|
||||
|
||||
result = {
|
||||
code: "00",
|
||||
message: "End Transaction Success",
|
||||
code: '00',
|
||||
message: 'End Transaction Success',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respCode,
|
||||
},
|
||||
};
|
||||
|
||||
// log info
|
||||
winston.logger.info(`${uniqueCode} RESPONSE load balance - END...`);
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} response HSM - end transaction: ${JSON.stringify(result)}`
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE TOPUP-8 ]: ENDING TOP UP... ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`500 internal server error - backend server | ${error.message}`
|
||||
`[ RESPONSE LOADING-BALANCE TOPUP-8 ]: 500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
code: "5001",
|
||||
code: '5001',
|
||||
message:
|
||||
process.env.NODE_ENV != "production"
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: "500 internal server error - backend server.",
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
const winston = require("../../helpers/winston.logger");
|
||||
const generate = require("./utils/utils");
|
||||
const winston = require('../../helpers/winston.logger');
|
||||
const generate = require('./utils/utils');
|
||||
const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
require("dotenv").config();
|
||||
require('dotenv').config();
|
||||
|
||||
let useClient;
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == "1") {
|
||||
var { client } = require("./services/webSocket");
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '1') {
|
||||
var { client } = require('./services/webSocket');
|
||||
|
||||
useClient = client;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == "2") {
|
||||
var { client2 } = require("./services/webSocket2");
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '2') {
|
||||
var { client2 } = require('./services/webSocket2');
|
||||
|
||||
useClient = client2;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == "12") {
|
||||
var { client } = require("./services/webSocket");
|
||||
var { client2 } = require("./services/webSocket2");
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
var { client } = require('./services/webSocket');
|
||||
var { client2 } = require('./services/webSocket2');
|
||||
}
|
||||
|
||||
const controller = async (req, res) => {
|
||||
@@ -27,11 +27,13 @@ const controller = async (req, res) => {
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} request HSM - read data: ${JSON.stringify(req.body)}`
|
||||
`${uniqueCode} [ REQUEST LOADING-BALANCE TOPUP-4 ]: ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == "12") {
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
// set request to HSM server 2
|
||||
if (uniqueCode) {
|
||||
if (parseInt(uniqueCode) % 2 == 0) {
|
||||
@@ -70,7 +72,7 @@ const controller = async (req, res) => {
|
||||
let respData = null;
|
||||
let respData1 = null;
|
||||
|
||||
useClient.ws.on("message", (message) => {
|
||||
useClient.ws.on('message', (message) => {
|
||||
while (
|
||||
message[2] == 4 &&
|
||||
message[0] == transactionId[0] &&
|
||||
@@ -84,7 +86,9 @@ const controller = async (req, res) => {
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} HSM - message read data: ${generate.buf2hex(message)}`
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE TOPUP-4 ]: message from HSM ${generate.buf2hex(
|
||||
message
|
||||
)}`
|
||||
);
|
||||
|
||||
respData = message;
|
||||
@@ -104,8 +108,8 @@ const controller = async (req, res) => {
|
||||
respData1 = generate.getResponseData(respData);
|
||||
|
||||
result = {
|
||||
code: "00",
|
||||
message: "Read Succeess",
|
||||
code: '00',
|
||||
message: 'Read Succeess',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respCode,
|
||||
@@ -116,22 +120,24 @@ const controller = async (req, res) => {
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} response HSM - read data: ${JSON.stringify(result)}`
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE TOPUP-4 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`500 internal server error - backend server | ${error.message}`
|
||||
`[ RESPONSE LOADING-BALANCE TOPUP-4 ]: 500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
code: "5001",
|
||||
code: '5001',
|
||||
message:
|
||||
process.env.NODE_ENV != "production"
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: "500 internal server error - backend server.",
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
const winston = require("../../helpers/winston.logger");
|
||||
const generate = require("./utils/utils");
|
||||
const winston = require('../../helpers/winston.logger');
|
||||
const generate = require('./utils/utils');
|
||||
const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
require("dotenv").config();
|
||||
require('dotenv').config();
|
||||
|
||||
let useClient;
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == "1") {
|
||||
var { client } = require("./services/webSocket");
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '1') {
|
||||
var { client } = require('./services/webSocket');
|
||||
|
||||
useClient = client;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == "2") {
|
||||
var { client2 } = require("./services/webSocket2");
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '2') {
|
||||
var { client2 } = require('./services/webSocket2');
|
||||
|
||||
useClient = client2;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == "12") {
|
||||
var { client } = require("./services/webSocket");
|
||||
var { client2 } = require("./services/webSocket2");
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
var { client } = require('./services/webSocket');
|
||||
var { client2 } = require('./services/webSocket2');
|
||||
}
|
||||
|
||||
const controller = async (req, res) => {
|
||||
@@ -27,11 +27,13 @@ const controller = async (req, res) => {
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} request HSM - read data resp: ${JSON.stringify(req.body)}`
|
||||
`${uniqueCode} [ REQUEST LOADING-BALANCE TOPUP-5 ]: ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == "12") {
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
// set request to HSM server 2
|
||||
if (uniqueCode) {
|
||||
if (parseInt(uniqueCode) % 2 == 0) {
|
||||
@@ -58,14 +60,16 @@ const controller = async (req, res) => {
|
||||
let _stopMessage = 1;
|
||||
if (packet[0] != 0x45) {
|
||||
result = {
|
||||
code: "03",
|
||||
message: "Respone Card Wrong",
|
||||
code: '03',
|
||||
message: 'Respone Card Wrong',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} response HSM - read data resp: ${JSON.stringify(result)}`
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE TOPUP-5 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
@@ -79,7 +83,7 @@ const controller = async (req, res) => {
|
||||
let respData = null;
|
||||
let respData1 = null;
|
||||
|
||||
useClient.ws.on("message", (message) => {
|
||||
useClient.ws.on('message', (message) => {
|
||||
while (
|
||||
message[2] == 5 &&
|
||||
message[0] == transactionId[0] &&
|
||||
@@ -93,7 +97,7 @@ const controller = async (req, res) => {
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} HSM - message read data resp: ${generate.buf2hex(
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE TOPUP-5 ]: message from HSM ${generate.buf2hex(
|
||||
message
|
||||
)}`
|
||||
);
|
||||
@@ -115,8 +119,8 @@ const controller = async (req, res) => {
|
||||
respData1 = generate.getResponseData(respData);
|
||||
|
||||
result = {
|
||||
code: "00",
|
||||
message: "Read Succeess",
|
||||
code: '00',
|
||||
message: 'Read Succeess',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respCode,
|
||||
@@ -127,22 +131,24 @@ const controller = async (req, res) => {
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} response HSM - read data resp: ${JSON.stringify(result)}`
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE TOPUP-5 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`500 internal server error - backend server | ${error.message}`
|
||||
`[ RESPONSE LOADING-BALANCE TOPUP-5 ]: 500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
code: "5001",
|
||||
code: '5001',
|
||||
message:
|
||||
process.env.NODE_ENV != "production"
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: "500 internal server error - backend server.",
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -98,6 +98,13 @@ const controller = async (req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ REQUEST LOADING-BALANCE TOPUP-6 ]: ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
|
||||
// check validator
|
||||
const err = validationResult(req, res);
|
||||
if (!err.isEmpty()) {
|
||||
@@ -109,17 +116,14 @@ const controller = async (req, res) => {
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} response HSM - write topup: ${JSON.stringify(result)}`
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE TOPUP-6 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} request HSM - write topup: ${JSON.stringify(req.body)}`
|
||||
);
|
||||
|
||||
let transactionId = Buffer.from(generate.hexToBytes(trxID));
|
||||
let trxrequestData = Buffer.from(generate.hexToBytes(requestData));
|
||||
let _stopMessage = 1;
|
||||
@@ -159,7 +163,7 @@ const controller = async (req, res) => {
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} HSM - message write topup: ${generate.buf2hex(
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE TOPUP-6 ]: message from HSM ${generate.buf2hex(
|
||||
message
|
||||
)}`
|
||||
);
|
||||
@@ -182,7 +186,7 @@ const controller = async (req, res) => {
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} HSM - inserting load balance transaction...`
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE TOPUP-6 ]: inserting load balance transaction...`
|
||||
);
|
||||
|
||||
let data = {
|
||||
@@ -232,14 +236,16 @@ const controller = async (req, res) => {
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} response HSM - write topup: ${JSON.stringify(result)}`
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE TOPUP-6 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`500 internal server error - backend server | ${error.message}`
|
||||
`[ RESPONSE LOADING-BALANCE TOPUP-6 ]: 500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
|
||||
@@ -1,55 +1,55 @@
|
||||
const { param, body, validationResult } = require("express-validator");
|
||||
const winston = require("../../helpers/winston.logger");
|
||||
const generate = require("./utils/utils");
|
||||
const loadBalance = require("../loadbalance/loadbalance.controller");
|
||||
const { param, body, validationResult } = require('express-validator');
|
||||
const winston = require('../../helpers/winston.logger');
|
||||
const generate = require('./utils/utils');
|
||||
const loadBalance = require('../loadbalance/loadbalance.controller');
|
||||
const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
require("dotenv").config();
|
||||
require('dotenv').config();
|
||||
|
||||
let useClient;
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == "1") {
|
||||
var { client } = require("./services/webSocket");
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '1') {
|
||||
var { client } = require('./services/webSocket');
|
||||
|
||||
useClient = client;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == "2") {
|
||||
var { client2 } = require("./services/webSocket2");
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '2') {
|
||||
var { client2 } = require('./services/webSocket2');
|
||||
|
||||
useClient = client2;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == "12") {
|
||||
var { client } = require("./services/webSocket");
|
||||
var { client2 } = require("./services/webSocket2");
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
var { client } = require('./services/webSocket');
|
||||
var { client2 } = require('./services/webSocket2');
|
||||
}
|
||||
|
||||
// VALIDATION
|
||||
const validate = (method) => {
|
||||
switch (method) {
|
||||
case "topupResponse":
|
||||
case 'topupResponse':
|
||||
return [
|
||||
body("mid").not().isEmpty().withMessage("MID is required"),
|
||||
body("tid").not().isEmpty().withMessage("TID is required"),
|
||||
body("uid").not().isEmpty().withMessage("UID is required"),
|
||||
body("flag").not().isEmpty().withMessage("Flag is required"),
|
||||
body("card_number")
|
||||
body('mid').not().isEmpty().withMessage('MID is required'),
|
||||
body('tid').not().isEmpty().withMessage('TID is required'),
|
||||
body('uid').not().isEmpty().withMessage('UID is required'),
|
||||
body('flag').not().isEmpty().withMessage('Flag is required'),
|
||||
body('card_number')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage("Card Number is required"),
|
||||
body("amount")
|
||||
.withMessage('Card Number is required'),
|
||||
body('amount')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage("Amount is required")
|
||||
.withMessage('Amount is required')
|
||||
.isNumeric()
|
||||
.withMessage("Amount is invalid format"),
|
||||
body("reservation_number")
|
||||
.withMessage('Amount is invalid format'),
|
||||
body('reservation_number')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage("Reservation Number is required")
|
||||
.withMessage('Reservation Number is required')
|
||||
.isArray()
|
||||
.withMessage("Reservation Number is invalid request format"),
|
||||
body("load_balance_number")
|
||||
.withMessage('Reservation Number is invalid request format'),
|
||||
body('load_balance_number')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage("Load Balance Number is required"),
|
||||
.withMessage('Load Balance Number is required'),
|
||||
];
|
||||
default:
|
||||
break;
|
||||
@@ -79,7 +79,7 @@ const controller = async (req, res) => {
|
||||
let result = {};
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == "12") {
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
// set request to HSM server 2
|
||||
if (uniqueCode) {
|
||||
if (parseInt(uniqueCode) % 2 == 0) {
|
||||
@@ -111,7 +111,9 @@ const controller = async (req, res) => {
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} request HSM - topup resp: ${JSON.stringify(req.body)}`
|
||||
`${uniqueCode} [ REQUEST LOADING-BALANCE TOPUP-7 ]: ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
|
||||
let transactionId = Buffer.from(generate.hexToBytes(trxID));
|
||||
@@ -119,14 +121,16 @@ const controller = async (req, res) => {
|
||||
let _stopMessage = 1;
|
||||
if (packet[0] != 0x47) {
|
||||
result = {
|
||||
code: "03",
|
||||
message: "Respone Card Wrong",
|
||||
code: '03',
|
||||
message: 'Respone Card Wrong',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} response HSM - topup resp: ${JSON.stringify(result)}`
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE TOPUP-7 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
@@ -140,7 +144,7 @@ const controller = async (req, res) => {
|
||||
let respData = null;
|
||||
let respData1 = null;
|
||||
|
||||
useClient.ws.on("message", (message) => {
|
||||
useClient.ws.on('message', (message) => {
|
||||
while (
|
||||
message[2] == 5 &&
|
||||
message[0] == transactionId[0] &&
|
||||
@@ -154,7 +158,9 @@ const controller = async (req, res) => {
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} HSM - message topup resp: ${generate.buf2hex(message)}`
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE TOPUP-7 ]: message from HSM ${generate.buf2hex(
|
||||
message
|
||||
)}`
|
||||
);
|
||||
|
||||
respData = message;
|
||||
@@ -186,7 +192,7 @@ const controller = async (req, res) => {
|
||||
amount: amount,
|
||||
reservation_number: reservation_number,
|
||||
ref_no: ref_no,
|
||||
write_status: "FW",
|
||||
write_status: 'FW',
|
||||
uid: uid,
|
||||
balance: parseInt(balance) + parseInt(amount),
|
||||
flag: parseInt(flag),
|
||||
@@ -196,15 +202,15 @@ const controller = async (req, res) => {
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} HSM - updating load balance transaction...`
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE TOPUP-7 ]: updating load balance transaction is FW...`
|
||||
);
|
||||
|
||||
// update data load balance
|
||||
await loadBalance.loadingBalanceUpdate(data);
|
||||
|
||||
result = {
|
||||
code: "5002",
|
||||
message: "failed from HSM",
|
||||
code: '5002',
|
||||
message: 'failed from HSM',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respData1.slice(6, 10),
|
||||
@@ -213,6 +219,11 @@ const controller = async (req, res) => {
|
||||
},
|
||||
};
|
||||
} else {
|
||||
// jika sudah mencapai maksimum counting flag, maka reset flag ke awal
|
||||
if (flag >= 255) {
|
||||
flag = -1;
|
||||
}
|
||||
|
||||
data = {
|
||||
mid: mid,
|
||||
tid: tid,
|
||||
@@ -230,16 +241,16 @@ const controller = async (req, res) => {
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} HSM - updating load balance transaction...`
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE TOPUP-7 ]: updating load balance transaction...`
|
||||
);
|
||||
|
||||
// update data load balance
|
||||
let update = await loadBalance.loadingBalanceUpdate(data);
|
||||
if (update) {
|
||||
if (update.code == "00") {
|
||||
if (update.code == '00') {
|
||||
result = {
|
||||
code: "00",
|
||||
message: "Topup Succeess",
|
||||
code: '00',
|
||||
message: 'Topup Succeess',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respCode,
|
||||
@@ -257,8 +268,8 @@ const controller = async (req, res) => {
|
||||
}
|
||||
} else {
|
||||
result = {
|
||||
code: "423",
|
||||
message: "update/insert failed",
|
||||
code: '423',
|
||||
message: 'update/insert failed',
|
||||
data: {},
|
||||
};
|
||||
}
|
||||
@@ -266,22 +277,24 @@ const controller = async (req, res) => {
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} HSM - message topup resp: ${JSON.stringify(result)}`
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE TOPUP-7 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`500 internal server error - backend server | ${error.message}`
|
||||
`[ RESPONSE LOADING-BALANCE TOPUP-7 ]: 500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
code: "5001",
|
||||
code: '5001',
|
||||
message:
|
||||
process.env.NODE_ENV != "production"
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: "500 internal server error - backend server.",
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -386,7 +386,7 @@ const insertLoadingBalance = async (
|
||||
return result.rowCount;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error.message);
|
||||
// console.log(error.message);
|
||||
return error.message;
|
||||
});
|
||||
};
|
||||
@@ -457,7 +457,7 @@ const updateLoadingBalance = async (
|
||||
return result;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error.message);
|
||||
// console.log(error.message);
|
||||
return error.message;
|
||||
});
|
||||
};
|
||||
@@ -548,7 +548,7 @@ const insertLoadingBalanceHistoryOnly = async (
|
||||
return result;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error.message);
|
||||
// console.log(error.message);
|
||||
return error.message;
|
||||
});
|
||||
};
|
||||
@@ -665,7 +665,7 @@ const updateReservationAndLoadingBalance = async (
|
||||
return result.rowCount;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error.message);
|
||||
// console.log(error.message);
|
||||
return error.message;
|
||||
});
|
||||
};
|
||||
@@ -745,7 +745,7 @@ const updateFlag = async (now, cardNumber, uid, balance, flag) => {
|
||||
return result;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error.message);
|
||||
// console.log(error.message);
|
||||
return error.message;
|
||||
});
|
||||
};
|
||||
@@ -793,14 +793,14 @@ const getReservationPendingWithoutFraud = (
|
||||
reservationNumber = []
|
||||
) => {
|
||||
if (reservationNumber.length > 0) {
|
||||
let rsv = ``;
|
||||
let rsv = '';
|
||||
if (reservationNumber.length > 0) {
|
||||
for (let index = 0; index < reservationNumber.length; index++) {
|
||||
if (index > 0) {
|
||||
rsv = rsv + `,`;
|
||||
rsv = rsv + ',';
|
||||
}
|
||||
|
||||
rsv = `'` + rsv + reservationNumber[index] + `'`;
|
||||
rsv = rsv + "'" + reservationNumber[index] + "'";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -862,14 +862,14 @@ const getLastHistory = (cardNumber) => {
|
||||
|
||||
// INSERT FRAUD TRANSACTION
|
||||
const insertFraudTransaction = (reservationNumber) => {
|
||||
let rsv = ``;
|
||||
let rsv = '';
|
||||
if (reservationNumber.length > 0) {
|
||||
for (let index = 0; index < reservationNumber.length; index++) {
|
||||
if (index > 0) {
|
||||
rsv = rsv + `,`;
|
||||
rsv = rsv + ',';
|
||||
}
|
||||
|
||||
rsv = `'` + rsv + reservationNumber[index] + `'`;
|
||||
rsv = rsv + "'" + reservationNumber[index] + "'";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1019,15 +1019,25 @@ const updateReservationAndInsertLoadingBalance = async (
|
||||
.catch(trx.rollback);
|
||||
})
|
||||
.then((result) => {
|
||||
console.log(result);
|
||||
// console.log(result);
|
||||
return result.rowCount;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error.message);
|
||||
// console.log(error.message);
|
||||
return error.message;
|
||||
});
|
||||
};
|
||||
|
||||
// GET TOPUP PARTIAL STATUS FROM GLOBAL PARAMETER
|
||||
const getTopupPartialStatus = () => {
|
||||
let result = knex('t_m_global_parameter')
|
||||
.select('c_value')
|
||||
.where('c_code', '=', 'HSM_TOPUP_PARTIAL_STAT')
|
||||
.first();
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
checkCardNumber,
|
||||
getPartner,
|
||||
@@ -1072,4 +1082,5 @@ module.exports = {
|
||||
getReservationPendingWithFlagV2,
|
||||
createDetailLoadBalanceFromReservation,
|
||||
updateReservationAndInsertLoadingBalance,
|
||||
getTopupPartialStatus,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,442 @@
|
||||
const moment = require("moment");
|
||||
moment.locale("id");
|
||||
const model = require("../pooling/pooling.model");
|
||||
const winston = require("../../helpers/winston.logger");
|
||||
|
||||
const pooling = async (req, res) => {
|
||||
try {
|
||||
let { batch } = req.body;
|
||||
// return console.log(batch);
|
||||
let dataInsert = [];
|
||||
if (batch) {
|
||||
let { data } = req.body;
|
||||
|
||||
if (!data) {
|
||||
return res.status(200).json({
|
||||
code: "409",
|
||||
message: "Data is required",
|
||||
data: [],
|
||||
});
|
||||
}
|
||||
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
let resObj = {
|
||||
c_card_number: data[i].card_number,
|
||||
c_idm: data[i].uid,
|
||||
};
|
||||
dataInsert.push(resObj);
|
||||
}
|
||||
|
||||
await model.insertDataPooling("raw", dataInsert);
|
||||
} else {
|
||||
let { card_number, uid } = req.body;
|
||||
|
||||
if (!card_number) {
|
||||
return res.status(200).json({
|
||||
code: "409",
|
||||
message: "Card Number is required",
|
||||
data: [],
|
||||
});
|
||||
}
|
||||
|
||||
if (!uid) {
|
||||
return res.status(200).json({
|
||||
code: "409",
|
||||
message: "uid is required",
|
||||
data: [],
|
||||
});
|
||||
}
|
||||
|
||||
let obj = {
|
||||
c_card_number: card_number,
|
||||
c_idm: uid,
|
||||
};
|
||||
|
||||
await model.insertDataPooling("raw", obj);
|
||||
}
|
||||
|
||||
let dataPooling = await model.getDataPooling();
|
||||
|
||||
if (dataPooling.length == 0) {
|
||||
return res.status(200).json({
|
||||
code: "00",
|
||||
message: "No Pooling Data",
|
||||
data: [],
|
||||
});
|
||||
}
|
||||
|
||||
let valid = [];
|
||||
let invalid = [];
|
||||
let validCardNo = [];
|
||||
let invalidCardNo = [];
|
||||
|
||||
// Validate data
|
||||
for (let i = 0; i < dataPooling.length; i++) {
|
||||
let cardno = dataPooling[i].c_card_number;
|
||||
let uid = dataPooling[i].c_idm;
|
||||
// Check duplikat card number
|
||||
let checkCardNo = await model.checkCardProduct(cardno, uid);
|
||||
let dataObject = {
|
||||
c_card_number: cardno,
|
||||
c_idm: uid,
|
||||
};
|
||||
|
||||
if (!checkCardNo) {
|
||||
valid.push(dataObject);
|
||||
validCardNo.push(cardno);
|
||||
} else {
|
||||
invalid.push(dataObject);
|
||||
invalidCardNo.push(cardno);
|
||||
}
|
||||
}
|
||||
|
||||
if (valid.length > 0) {
|
||||
await model.insertDataPooling("valid", valid, validCardNo);
|
||||
}
|
||||
|
||||
if (invalid.length > 0) {
|
||||
await model.insertDataPooling("invalid", invalid, invalidCardNo);
|
||||
}
|
||||
|
||||
let dataInsertCardNumber = await model.getDataValid();
|
||||
|
||||
if (dataInsertCardNumber.length == 0) {
|
||||
return res.status(200).json({
|
||||
code: "409",
|
||||
message: "No data valid",
|
||||
data: [],
|
||||
});
|
||||
}
|
||||
|
||||
let insertCardProduct = [];
|
||||
let cardNumber = [];
|
||||
for (let i = 0; i < dataInsertCardNumber.length; i++) {
|
||||
let cardno = dataInsertCardNumber[i].c_card_number;
|
||||
let uid = dataInsertCardNumber[i].c_idm;
|
||||
let obj = {
|
||||
c_card_number: cardno,
|
||||
c_idm: uid,
|
||||
};
|
||||
cardNumber.push(cardno);
|
||||
insertCardProduct.push(obj);
|
||||
}
|
||||
|
||||
let insertingCardNumber = await model.insertCardNumber(insertCardProduct);
|
||||
if (insertingCardNumber == "success") {
|
||||
let flagValid = await model.updateDataValid(dataCardNumber);
|
||||
if (flagValid == "error") {
|
||||
await model.deleteCardNumber(dataCardNumber);
|
||||
}
|
||||
}
|
||||
console.log(insertingCardNumber);
|
||||
if (insertingCardNumber == "error") {
|
||||
return res.status(200).json({
|
||||
code: "409",
|
||||
message: "Fail insert data card product",
|
||||
data: [],
|
||||
});
|
||||
}
|
||||
|
||||
return res.status(200).json({
|
||||
code: "00",
|
||||
message: "Success",
|
||||
data: [],
|
||||
});
|
||||
} catch (error) {
|
||||
return res.status(200).json({
|
||||
code: "500",
|
||||
message:
|
||||
process.env.NODE_ENV != "production"
|
||||
? error.message
|
||||
: "500 internal server error - backend server.",
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const validateData = async (req, res) => {
|
||||
let result = {};
|
||||
try {
|
||||
let data = await model.getDataPooling();
|
||||
|
||||
if (data.length == 0) {
|
||||
result = {
|
||||
code: "00",
|
||||
message: "No Pooling Data",
|
||||
data: [],
|
||||
};
|
||||
|
||||
winston.logger.warn(
|
||||
`[ RESPONSE VALIDATE-POOLING ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
let valid = [];
|
||||
let invalid = [];
|
||||
let validCardNo = [];
|
||||
let invalidCardNo = [];
|
||||
|
||||
winston.logger.debug(
|
||||
`[ PROCESSING VALIDATE-POOLING ]: checking and separating valid and invalid data...`
|
||||
);
|
||||
|
||||
// Validate data
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
let cardno = data[i].c_card_number;
|
||||
let uid = data[i].c_idm;
|
||||
// Check duplikat card number
|
||||
let checkCardNo = await model.checkCardProduct(cardno, uid);
|
||||
let dataObject = {
|
||||
c_card_number: cardno,
|
||||
c_idm: uid,
|
||||
};
|
||||
|
||||
if (!checkCardNo) {
|
||||
valid.push(dataObject);
|
||||
validCardNo.push(cardno);
|
||||
} else {
|
||||
invalid.push(dataObject);
|
||||
invalidCardNo.push(cardno);
|
||||
}
|
||||
}
|
||||
|
||||
winston.logger.debug(`[ PROCESSING VALIDATE-POOLING ]: inserting data...`);
|
||||
|
||||
if (valid.length > 0) {
|
||||
await model.insertDataPooling("valid", valid, validCardNo);
|
||||
}
|
||||
|
||||
if (invalid.length > 0) {
|
||||
await model.insertDataPooling("invalid", invalid, invalidCardNo);
|
||||
}
|
||||
|
||||
result = {
|
||||
code: "00",
|
||||
message: "Validate success",
|
||||
data: [],
|
||||
};
|
||||
|
||||
winston.logger.info(
|
||||
`[ RESPONSE VALIDATE-POOLING ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
} catch (error) {
|
||||
result = {
|
||||
code: "500",
|
||||
message:
|
||||
process.env.NODE_ENV != "production"
|
||||
? error.message
|
||||
: "500 internal server error - backend server.",
|
||||
data: {},
|
||||
};
|
||||
|
||||
winston.logger.error(
|
||||
`[ RESPONSE VALIDATE-POOLING ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
};
|
||||
|
||||
const insertCardProduct = async (req, res) => {
|
||||
let result = {};
|
||||
try {
|
||||
let data = await model.getDataValid();
|
||||
|
||||
if (data.length == 0) {
|
||||
result = {
|
||||
code: "409",
|
||||
message: "No data valid",
|
||||
data: [],
|
||||
};
|
||||
|
||||
winston.logger.info(
|
||||
`[ RESPONSE INSERT-CARD-PRODUCT ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
let dataInsert = [];
|
||||
let dataCardNumber = [];
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
let cardno = data[i].c_card_number;
|
||||
let uid = data[i].c_idm;
|
||||
let obj = {
|
||||
c_card_number: cardno,
|
||||
c_idm: uid,
|
||||
};
|
||||
dataCardNumber.push(cardno);
|
||||
dataInsert.push(obj);
|
||||
}
|
||||
|
||||
winston.logger.debug(
|
||||
`[ PROCESSING INSERT-CARD-PRODUCT ]: inserting data...`
|
||||
);
|
||||
|
||||
let insertCardNumber = await model.insertCardNumber(dataInsert);
|
||||
if (insertCardNumber == "success") {
|
||||
let flagValid = await model.updateDataValid(dataCardNumber);
|
||||
if (flagValid == "error") {
|
||||
await model.deleteCardNumber(dataCardNumber);
|
||||
}
|
||||
}
|
||||
|
||||
if (insertCardNumber == "error") {
|
||||
result = {
|
||||
code: "409",
|
||||
message: "Fail insert data card product",
|
||||
data: [],
|
||||
};
|
||||
|
||||
winston.logger.warn(
|
||||
`[ RESPONSE INSERT-CARD-PRODUCT ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
result = {
|
||||
code: "00",
|
||||
message: "Success",
|
||||
data: [],
|
||||
};
|
||||
|
||||
winston.logger.info(
|
||||
`[ RESPONSE INSERT-CARD-PRODUCT ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
} catch (error) {
|
||||
result = {
|
||||
code: "500",
|
||||
message:
|
||||
process.env.NODE_ENV != "production"
|
||||
? error.message
|
||||
: "500 internal server error - backend server.",
|
||||
data: [],
|
||||
};
|
||||
|
||||
winston.logger.error(
|
||||
`[ RESPONSE INSERT-POOLING ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
};
|
||||
|
||||
const insertPooling = async (req, res) => {
|
||||
let result = {};
|
||||
try {
|
||||
let { batch } = req.body;
|
||||
|
||||
let dataInsert = [];
|
||||
if (batch) {
|
||||
let { data } = req.body;
|
||||
|
||||
winston.logger.warn(
|
||||
`[ REQUEST INSERT-POOLING ]: ${JSON.stringify(req.body)}`
|
||||
);
|
||||
|
||||
if (!data) {
|
||||
result = {
|
||||
code: "409",
|
||||
message: "Data is required",
|
||||
data: [],
|
||||
};
|
||||
|
||||
winston.logger.warn(
|
||||
`[ RESPONSE INSERT-POOLING ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
let resObj = {
|
||||
c_card_number: data[i].card_number,
|
||||
c_idm: data[i].uid,
|
||||
};
|
||||
dataInsert.push(resObj);
|
||||
}
|
||||
|
||||
winston.logger.debug(`[ PROCESSING INSERT-POOLING ]: inserting data...`);
|
||||
|
||||
await model.insertDataPooling("raw", dataInsert);
|
||||
} else {
|
||||
let { card_number, uid } = req.body;
|
||||
|
||||
winston.logger.warn(
|
||||
`[ REQUEST INSERT-POOLING ]: ${JSON.stringify(req.body)}`
|
||||
);
|
||||
|
||||
if (!card_number) {
|
||||
result = {
|
||||
code: "409",
|
||||
message: "Card Number is required",
|
||||
data: [],
|
||||
};
|
||||
|
||||
winston.logger.warn(
|
||||
`[ RESPONSE INSERT-POOLING ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
if (!uid) {
|
||||
result = {
|
||||
code: "409",
|
||||
message: "uid is required",
|
||||
data: [],
|
||||
};
|
||||
|
||||
winston.logger.warn(
|
||||
`[ RESPONSE INSERT-POOLING ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
let obj = {
|
||||
c_card_number: card_number,
|
||||
c_idm: uid,
|
||||
};
|
||||
|
||||
winston.logger.debug(`[ PROCESSING INSERT-POOLING ]: inserting data...`);
|
||||
|
||||
await model.insertDataPooling("raw", obj);
|
||||
}
|
||||
|
||||
result = {
|
||||
code: "00",
|
||||
message: "Success insert data",
|
||||
data: [],
|
||||
};
|
||||
|
||||
winston.logger.info(
|
||||
`[ RESPONSE INSERT-POOLING ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
} catch (error) {
|
||||
result = {
|
||||
code: "500",
|
||||
message:
|
||||
process.env.NODE_ENV != "production"
|
||||
? error.message
|
||||
: "500 internal server error - backend server.",
|
||||
data: [],
|
||||
};
|
||||
|
||||
winston.logger.error(
|
||||
`[ RESPONSE INSERT-POOLING ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { pooling, validateData, insertCardProduct, insertPooling };
|
||||
@@ -0,0 +1,155 @@
|
||||
require("dotenv").config();
|
||||
let host = process.env.DB_HOST_POOLING;
|
||||
let user = process.env.DB_USER_POOLING;
|
||||
let name = process.env.DB_NAME_POOLING;
|
||||
let password = process.env.DB_PASSWORD_POOLING;
|
||||
const dbPooling = require("knex")({
|
||||
client: "pg",
|
||||
connection: {
|
||||
host: host,
|
||||
user: user,
|
||||
password: password,
|
||||
database: name,
|
||||
},
|
||||
});
|
||||
const knex = require("../../../infrastructure/database/knex");
|
||||
const moment = require("moment");
|
||||
moment.locale("id");
|
||||
|
||||
const insertData = (table, data) => {
|
||||
let result = knex(table).insert(data);
|
||||
return result;
|
||||
};
|
||||
|
||||
const insertDataPooling = async (table, data, cardno) => {
|
||||
if (table == "raw") {
|
||||
await dbPooling(table).insert(data);
|
||||
} else if (table == "valid") {
|
||||
await dbPooling.transaction(async (trx) => {
|
||||
try {
|
||||
await trx(table).insert(data);
|
||||
await trx("raw")
|
||||
.whereIn("c_card_number", cardno)
|
||||
.update({
|
||||
b_validate: true,
|
||||
d_validate: moment().format("YYYY-MM-DD HH:mm:ss"),
|
||||
});
|
||||
await trx.commit();
|
||||
} catch (error) {
|
||||
await trx.rollback();
|
||||
}
|
||||
});
|
||||
} else if (table == "invalid") {
|
||||
await dbPooling.transaction(async (trx) => {
|
||||
try {
|
||||
await trx(table).insert(data);
|
||||
await trx("raw")
|
||||
.whereIn("c_card_number", cardno)
|
||||
.update({
|
||||
b_validate: true,
|
||||
d_validate: moment().format("YYYY-MM-DD HH:mm:ss"),
|
||||
});
|
||||
await trx.commit();
|
||||
} catch (error) {
|
||||
await trx.rollback();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
await dbPooling(table).insert(data);
|
||||
}
|
||||
};
|
||||
|
||||
const checkCardProduct = (card_number, uid) => {
|
||||
let result = knex("t_m_card_product")
|
||||
.where("c_card_number", "=", card_number)
|
||||
.where("c_idm", "=", uid)
|
||||
.first();
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
const pooling = async (valid, invalid, dataDelete) => {
|
||||
let sts;
|
||||
await dbPooling.transaction(async (trx2) => {
|
||||
try {
|
||||
if (valid.length > 0) {
|
||||
await trx2("valid").insert(valid);
|
||||
}
|
||||
if (invalid.length > 0) {
|
||||
await trx2("invalid").insert(invalid);
|
||||
}
|
||||
await trx2("pooling").whereIn("c_card_number", dataDelete).del();
|
||||
|
||||
await trx2.commit();
|
||||
sts = "success";
|
||||
} catch (error) {
|
||||
sts = "error";
|
||||
await trx2.rollback();
|
||||
}
|
||||
});
|
||||
return sts;
|
||||
};
|
||||
|
||||
const insertCardNumber = async (data) => {
|
||||
let sts;
|
||||
await knex.transaction(async (trx) => {
|
||||
try {
|
||||
await trx("t_m_card_product").insert(data);
|
||||
await trx.commit();
|
||||
sts = "success";
|
||||
} catch (error) {
|
||||
sts = "error";
|
||||
await trx.rollback();
|
||||
}
|
||||
});
|
||||
return sts;
|
||||
};
|
||||
|
||||
const updateDataValid = async (data) => {
|
||||
let sts;
|
||||
await dbPooling.transaction(async (trx) => {
|
||||
try {
|
||||
await trx("valid")
|
||||
.whereIn("c_card_number", data)
|
||||
.update({
|
||||
b_sync: true,
|
||||
d_sync: moment().format("YYYY-MM-DD HH:mm:ss"),
|
||||
});
|
||||
await trx.commit();
|
||||
sts = "success";
|
||||
} catch (error) {
|
||||
await trx.rollback();
|
||||
sts = "error";
|
||||
}
|
||||
});
|
||||
return sts;
|
||||
};
|
||||
|
||||
const getDataPooling = () => {
|
||||
let result = dbPooling("raw").where("b_validate", "=", false);
|
||||
return result;
|
||||
};
|
||||
|
||||
const getDataValid = () => {
|
||||
let result = dbPooling("valid").where("b_sync", "=", false);
|
||||
return result;
|
||||
};
|
||||
|
||||
const deleteCardNumber = (data) => {
|
||||
let result = knex("t_m_card_product")
|
||||
.whereIn("c_card_number", "=", data)
|
||||
.del();
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
deleteCardNumber,
|
||||
updateDataValid,
|
||||
getDataValid,
|
||||
insertDataPooling,
|
||||
insertCardNumber,
|
||||
pooling,
|
||||
insertData,
|
||||
checkCardProduct,
|
||||
getDataPooling,
|
||||
};
|
||||
@@ -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')
|
||||
@@ -80,6 +85,11 @@ const validate = (method) => {
|
||||
.isEmpty()
|
||||
.withMessage('Cancel Reservation data is required'),
|
||||
];
|
||||
case 'getFeeSharing':
|
||||
return [
|
||||
body('mid').not().isEmpty().withMessage('MID is required'),
|
||||
body('tid').not().isEmpty().withMessage('TID is required'),
|
||||
];
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -622,7 +632,10 @@ const reservationValidate = async (req, res) => {
|
||||
result = {
|
||||
code: '00',
|
||||
message: 'validation successfully.',
|
||||
data: {},
|
||||
data: {
|
||||
issuer_fee: issuerFee,
|
||||
channel_fee: channelFee,
|
||||
},
|
||||
};
|
||||
|
||||
// log info
|
||||
@@ -965,16 +978,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 +1085,14 @@ 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,
|
||||
issuer_fee: issuerFee,
|
||||
channel_fee: channelFee,
|
||||
},
|
||||
reservation_pending: dataReservationPending,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1088,7 +1121,7 @@ const reservationValidateV2 = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
// ================================================================= RESERVATION =================================================================
|
||||
// ================================================================= RESERVATION V1 =================================================================
|
||||
// *Created By: Mohamad Ihsan*
|
||||
// *Description:*
|
||||
// proses insert data transaksi reservasi saldo. Proses ini dilakukan setelah melakukan reservation validate dengan response code 00. Output dari proses ini adalah kode reservation number dan informasi reservasi saldo yang dilakukan
|
||||
@@ -1101,7 +1134,8 @@ const reservation = async (req, res) => {
|
||||
let result = {};
|
||||
|
||||
// param
|
||||
let { mid, tid, card_number, amount, ref_no } = req.body;
|
||||
let { mid, tid, card_number, amount, ref_no, customer_name, phone_number } =
|
||||
req.body;
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
@@ -1543,6 +1577,19 @@ const reservation = async (req, res) => {
|
||||
|
||||
let expired = moment(now).add(time, measure).format('YYYY-MM-DD HH:mm:ss');
|
||||
|
||||
// -------------------------------- NOTES --------------------------------
|
||||
// for LRT JABO => customer_name diisi Device Name (versi penamaan LRT Jabo) dan phone_number diisi Device Code (versi kode LRT Jabo) sesuai MOM BI-WEEKLY MEETING (08/05/2023)
|
||||
let customerName = customer_name;
|
||||
let phoneNumber = phone_number;
|
||||
|
||||
if (!customerName || customerName == '' || customerName == '-') {
|
||||
customerName = getPartner ? getPartner.terminal_name : '';
|
||||
}
|
||||
|
||||
if (!phoneNumber || phoneNumber == '' || phoneNumber == '-') {
|
||||
phoneNumber = mid + '_' + tid;
|
||||
}
|
||||
|
||||
// binding data
|
||||
let data = {
|
||||
c_reservation_no: reservationNumber,
|
||||
@@ -1589,6 +1636,8 @@ const reservation = async (req, res) => {
|
||||
c_delete_username: null,
|
||||
c_delete_fullname: null,
|
||||
c_flag: '-1',
|
||||
c_customer_name: customerName,
|
||||
c_phone_number: phoneNumber,
|
||||
};
|
||||
|
||||
// log debug
|
||||
@@ -1611,7 +1660,7 @@ const reservation = async (req, res) => {
|
||||
await model.deleteReservationNumberValidate(reservationNumber);
|
||||
|
||||
result = {
|
||||
code: '432',
|
||||
code: '424',
|
||||
message: 'refno is duplicate',
|
||||
data: {},
|
||||
};
|
||||
@@ -1705,7 +1754,14 @@ const reservationV2 = async (req, res) => {
|
||||
let result = {};
|
||||
|
||||
// param
|
||||
let { reservation_data, ref_no } = req.body;
|
||||
let {
|
||||
reservation_data,
|
||||
ref_no,
|
||||
customer_name,
|
||||
phone_number,
|
||||
amount,
|
||||
card_number,
|
||||
} = req.body;
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
@@ -1780,11 +1836,47 @@ const reservationV2 = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
if (card_number) {
|
||||
if (reservationData.card_number != card_number) {
|
||||
result = {
|
||||
code: '441',
|
||||
message:
|
||||
'bad request. card number requested is different with reservation data.',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE RESERVATION-V2 ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
}
|
||||
|
||||
if (amount) {
|
||||
if (reservationData.amount != amount) {
|
||||
result = {
|
||||
code: '442',
|
||||
message:
|
||||
'bad request. amount requested is different with reservation data.',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE RESERVATION-V2 ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
}
|
||||
|
||||
// extract reseravtion data
|
||||
let mid = reservationData.mid;
|
||||
let tid = reservationData.tid;
|
||||
let card_number = reservationData.card_number;
|
||||
let amount = reservationData.amount;
|
||||
card_number = reservationData.card_number;
|
||||
amount = reservationData.amount;
|
||||
let transactionDate = reservationData.transaction_date;
|
||||
let securityCode = reservationData.security_code;
|
||||
|
||||
@@ -2113,16 +2205,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
|
||||
@@ -2264,6 +2371,19 @@ const reservationV2 = async (req, res) => {
|
||||
|
||||
let expired = moment(now).add(time, measure).format('YYYY-MM-DD HH:mm:ss');
|
||||
|
||||
// -------------------------------- NOTES --------------------------------
|
||||
// for LRT JABO => customer_name diisi Device Name (versi penamaan LRT Jabo) dan phone_number diisi Device Code (versi kode LRT Jabo) sesuai MOM BI-WEEKLY MEETING (08/05/2023)
|
||||
let customerName = customer_name;
|
||||
let phoneNumber = phone_number;
|
||||
|
||||
if (!customerName || customerName == '' || customerName == '-') {
|
||||
customerName = getPartner ? getPartner.terminal_name : '';
|
||||
}
|
||||
|
||||
if (!phoneNumber || phoneNumber == '' || phoneNumber == '-') {
|
||||
phoneNumber = mid + '_' + tid;
|
||||
}
|
||||
|
||||
// binding data
|
||||
let data = {
|
||||
c_reservation_no: reservationNumber,
|
||||
@@ -2310,6 +2430,8 @@ const reservationV2 = async (req, res) => {
|
||||
c_delete_username: null,
|
||||
c_delete_fullname: null,
|
||||
c_flag: '-1',
|
||||
c_customer_name: customerName,
|
||||
c_phone_number: phoneNumber,
|
||||
};
|
||||
|
||||
// log debug
|
||||
@@ -2332,7 +2454,7 @@ const reservationV2 = async (req, res) => {
|
||||
await model.deleteReservationNumberValidate(reservationNumber);
|
||||
|
||||
result = {
|
||||
code: '432',
|
||||
code: '424',
|
||||
message: 'refno is duplicate',
|
||||
data: {},
|
||||
};
|
||||
@@ -2950,7 +3072,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 +3092,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 +3104,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 +3119,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) {
|
||||
@@ -3042,6 +3175,18 @@ const inquiryListReservationByReservation = async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
// check date range max 1 month
|
||||
let diff = moment(end_date).diff(moment(start_date), 'months', true);
|
||||
|
||||
if (diff >= 1) {
|
||||
return res.status(200).json({
|
||||
code: '400',
|
||||
message:
|
||||
'bad request. We only allow data requests for 1 month. please change your date range parameter request!',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
// check reservation
|
||||
let listReservation = await model.inquiryListReservation(
|
||||
req.partner_id_token,
|
||||
@@ -3086,11 +3231,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 +3251,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 +3262,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,53 +3276,122 @@ 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
|
||||
if (!getGlobalParameter) {
|
||||
result = {
|
||||
code: '493',
|
||||
code: '439',
|
||||
message: 'HSM_CANCEL_RESERVATION_LEVEL in global parameter not found',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE ]: ${JSON.stringify(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE-V2 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
@@ -3194,7 +3408,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 +3425,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 +3442,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 +3466,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 +3487,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 +3503,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 +3520,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
|
||||
)}`
|
||||
);
|
||||
@@ -3319,13 +3533,13 @@ const cancelReservationValidateV2 = async (req, res) => {
|
||||
|
||||
// create security code yang isinya data reservasi yang akan di compare nantinya saat melakukan insert reservation
|
||||
let securityCode = await helper.createHMAC(
|
||||
mid + '|' + tid + '|' + reservation_number
|
||||
mid + '|' + tid + '|' + reservationNumber
|
||||
);
|
||||
|
||||
let reservationData = {
|
||||
mid: mid,
|
||||
tid: tid,
|
||||
reservation_number: reservation_number,
|
||||
reservation_number: reservationNumber,
|
||||
transaction_date: now,
|
||||
security_code: securityCode,
|
||||
};
|
||||
@@ -3333,7 +3547,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 +3560,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 +3579,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 +3880,368 @@ 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: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// ================================================================= GET FEE SHARING =================================================================
|
||||
// *Created By: Mohamad Ihsan*
|
||||
// *Description:*
|
||||
// proses fee sharing
|
||||
|
||||
const getFeeSharing = 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 { datetime, mid, tid } = req.body;
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ REQUEST GET-FEE-SHARING ]: ${JSON.stringify(req.body)}`
|
||||
);
|
||||
|
||||
// datetime
|
||||
if (!datetime) {
|
||||
datetime = moment().format('YYYY-MM-DD');
|
||||
}
|
||||
|
||||
// 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 GET-FEE-SHARING ] checking partner...`
|
||||
);
|
||||
|
||||
// get partner, merchant, terminal from tid
|
||||
let getPartner = await model.getPartner(mid, tid);
|
||||
|
||||
// jika partner (mid atau tid) tidak ditemukan atau tidak terdaftar di sistem CMS
|
||||
if (!getPartner) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'terminal id is not valid',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE GET-FEE-SHARING ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// set default issuer fee
|
||||
let issuerFee = 0;
|
||||
let channelFee = 0;
|
||||
|
||||
// get issuer fee dan channel fee dari table public.t_c_partner_fee
|
||||
let getIssuer = await model.getIssuer(getPartner.i_partner, datetime);
|
||||
if (getIssuer) {
|
||||
issuerFee =
|
||||
(getIssuer.i_issuer_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
channelFee =
|
||||
(getIssuer.i_channel_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
}
|
||||
|
||||
result = {
|
||||
code: '00',
|
||||
message: 'fee sharing has been found.',
|
||||
data: {
|
||||
issuer_fee: issuerFee,
|
||||
channel_fee: channelFee,
|
||||
},
|
||||
};
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ RESPONSE GET-FEE-SHARING ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
} catch (error) {
|
||||
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 +4256,6 @@ module.exports = {
|
||||
inquiryListReservationByReservation,
|
||||
cancelReservationValidateV2,
|
||||
cancelReservationV2,
|
||||
cancelReservationV2_1,
|
||||
getFeeSharing,
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
const express = require("express");
|
||||
const router = express.Router();
|
||||
const auth = require("../middlewares/jwt.middleware");
|
||||
const controller = require("../modules/pooling/pooling.controller");
|
||||
|
||||
router.post(
|
||||
"/validate-pooling",
|
||||
auth.authenticateToken,
|
||||
controller.validateData
|
||||
);
|
||||
|
||||
router.post(
|
||||
"/insert-pooling",
|
||||
auth.authenticateToken,
|
||||
controller.insertPooling
|
||||
);
|
||||
|
||||
router.post(
|
||||
"/insert-card-product",
|
||||
auth.authenticateToken,
|
||||
controller.insertCardProduct
|
||||
);
|
||||
|
||||
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,18 @@ router.post(
|
||||
controller.cancelReservationV2
|
||||
);
|
||||
|
||||
router.post(
|
||||
'/reservation/fee-sharing',
|
||||
auth.authenticateToken,
|
||||
controller.validate('getFeeSharing'),
|
||||
controller.getFeeSharing
|
||||
);
|
||||
|
||||
// router.post(
|
||||
// '/reservation/cancel/v2.1',
|
||||
// auth.authenticateToken,
|
||||
// controller.validate('cancelReservation'),
|
||||
// controller.cancelReservationV2_1
|
||||
// );
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -21,6 +21,19 @@ DB_PASSWORD_LOCAL=postgres
|
||||
REDIS_URL=redis://localhost:6379
|
||||
REDIS_PASSWORD=
|
||||
|
||||
# ==================================== DB POOLING =====================================
|
||||
DB_HOST_POOLING=10.20.14.14
|
||||
DB_NAME_POOLING=postgres
|
||||
DB_PORT_POOLING=5432
|
||||
DB_USER_POOLING=postgres
|
||||
DB_PASSWORD_POOLING=inhc0mmute_cms
|
||||
|
||||
# ==================================== LOKI =====================================
|
||||
LOKI_URL=http://10.20.14.30:3100
|
||||
|
||||
# ==================================== APP PROMETHEUS =====================================
|
||||
PROM_APP = topuponline
|
||||
|
||||
# ================================== SECRET KEY ==================================
|
||||
# FOR PRODUCTION
|
||||
#SECRET_KEY=U2FsdGVkX19keaNhiBfdNSWnKA2a8Z5deBu/KkU6BNg=
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
# ================================= ENVIRONMENT =================================
|
||||
#NODE_ENV=production
|
||||
NODE_ENV=development
|
||||
#NODE_ENV=testing
|
||||
PORT=3000
|
||||
VERSION=v1.3.7
|
||||
|
||||
# =========================== KONFIGURASI UNTUK SERVER ===========================
|
||||
# SERVER_FOR=development
|
||||
#SERVER_FOR=production
|
||||
SERVER_FOR=local
|
||||
|
||||
# =============================== DATABASE LOCAL =================================
|
||||
# DB_URL=postgresql://postgres:postgres@localhost:5432/CMS_DEV
|
||||
DB_HOST_LOCAL=localhost
|
||||
DB_NAME_LOCAL=CMS_DEV
|
||||
DB_PORT_LOCAL=5432
|
||||
DB_USER_LOCAL=postgres
|
||||
DB_PASSWORD_LOCAL=postgres
|
||||
|
||||
# ==================================== REDIS =====================================
|
||||
REDIS_URL=redis://localhost:6379
|
||||
REDIS_PASSWORD=
|
||||
|
||||
# ==================================== LOKI =====================================
|
||||
LOKI_URL=http://localhost:3100
|
||||
|
||||
# =============================== APP PROMETHEUS =================================
|
||||
PROM_APP = topuponline
|
||||
|
||||
# ================================== SECRET KEY ==================================
|
||||
# FOR PRODUCTION
|
||||
#SECRET_KEY=U2FsdGVkX19keaNhiBfdNSWnKA2a8Z5deBu/KkU6BNg=
|
||||
# FOR DEVELOPMENT
|
||||
SECRET_KEY=U2FsdGVkX18tPlf9nVJEx7KwTdFsGPO/RK6A0HRYDeg=
|
||||
|
||||
# ===================================== JWT =======================================
|
||||
JWT_EXPIRATION=30d
|
||||
JWT_REFRESH_EXPIRATION=40d
|
||||
# FOR PRODUCTION
|
||||
#TOKEN_SECRET=101001D00C2001D0483001D0
|
||||
#REFRESH_TOKEN_SECRET=101001D00C2001D0483001D0800082008300800081008200
|
||||
# FOR DEVELOPMENT
|
||||
TOKEN_SECRET=101001A00C2001A0483001A0883001A0
|
||||
REFRESH_TOKEN_SECRET=101001A00C2001A0483001A0883001A0800082008300800081008200
|
||||
|
||||
|
||||
# ===================== CHANGE TO DRC SERVER (YES or NO) ===========================
|
||||
CHANGE_TO_DRC=YES
|
||||
|
||||
# HIGH AVABILITY (1 = SERVER_HSM_1 ONLY RUNNING, 2 = SERVER_HSM_2 ONLY RUNNING, 12 = SERVER_HSM_1 && SERVER_HSM_2 RUNNING)
|
||||
NUMBER_SERVER_ACTIVE=1
|
||||
|
||||
# ================================ KONFIGURASI HSM =================================
|
||||
|
||||
# system code kci profile
|
||||
# FOR PRODUCTION & DEVELOPMENT
|
||||
SYSTEM_CODE=90B7
|
||||
|
||||
#SERVICE BLOCK
|
||||
# FOR PRODUCTION
|
||||
# SERVICEBLOCK_SERVICE_MUTUAL="101001D00C2001D0483001D0"
|
||||
# FOR DEVELOPMENT
|
||||
SERVICEBLOCK_SERVICE_MUTUAL="101001A00C2001A0483001A0883001A0"
|
||||
|
||||
SERVICEBLOCK_BLOCK_READ="800082008300"
|
||||
SERVICEBLOCK_BLOCK_WRITE="800081008200"
|
||||
|
||||
# HSM DC (DATA CENTER)
|
||||
# HSM SERVER
|
||||
# URL_HSM_SERVER_1="ws://182.253.34.129/feliqserver/v1/wsapi"
|
||||
# APIKEY_HSM_SERVER_1="bc391562-f880-3b57-9868-36dfa5cbf954-0TC"
|
||||
# SECRETKEY_HSM_SERVER_1="xWW2o+lpAqDLIN85uHZdfuDQhhd7jCXp4w1rXhCkYEk="
|
||||
# URL_HSM_SERVER_2="ws://182.253.34.129:88/feliqserver/v1/wsapi"
|
||||
# APIKEY_HSM_SERVER_2="bc391562-f880-3b57-9868-36dfa5cbf954-0TC"
|
||||
# SECRETKEY_HSM_SERVER_2="xWW2o+lpAqDLIN85uHZdfuDQhhd7jCXp4w1rXhCkYEk="
|
||||
|
||||
# # HSM DRC (DISASTER RECOVERY CENTER)
|
||||
# # HSM SERVER
|
||||
# URL_HSM_SERVER_BACKUP_1="ws://182.253.34.129/feliqserver/v1/wsapi"
|
||||
# APIKEY_HSM_SERVER_BACKUP_1="bc391562-f880-3b57-9868-36dfa5cbf954-0TC"
|
||||
# SECRETKEY_HSM_SERVER_BACKUP_1="xWW2o+lpAqDLIN85uHZdfuDQhhd7jCXp4w1rXhCkYEk="
|
||||
# URL_HSM_SERVER_BACKUP_2="ws://182.253.34.129:88/feliqserver/v1/wsapi"
|
||||
# APIKEY_HSM_SERVER_BACKUP_2="bc391562-f880-3b57-9868-36dfa5cbf954-0TC"
|
||||
# SECRETKEY_HSM_SERVER_BACKUP_2="xWW2o+lpAqDLIN85uHZdfuDQhhd7jCXp4w1rXhCkYEk="
|
||||
|
||||
# HSM DC (DATA CENTER)
|
||||
# HSM SERVER
|
||||
IP_HSM_SERVER_1="10.1.201.222"
|
||||
URL_HSM_SERVER_1="ws://10.1.201.222/feliqserver/v1/wsapi"
|
||||
APIKEY_HSM_SERVER_1="bc391562-f880-3b57-9868-36dfa5cbf954-0TC"
|
||||
SECRETKEY_HSM_SERVER_1="xWW2o+lpAqDLIN85uHZdfuDQhhd7jCXp4w1rXhCkYEk="
|
||||
IP_HSM_SERVER_2="10.1.201.215"
|
||||
URL_HSM_SERVER_2="ws://10.1.201.215:88/feliqserver/v1/wsapi"
|
||||
APIKEY_HSM_SERVER_2="bc391562-f880-3b57-9868-36dfa5cbf954-0TC"
|
||||
SECRETKEY_HSM_SERVER_2="xWW2o+lpAqDLIN85uHZdfuDQhhd7jCXp4w1rXhCkYEk="
|
||||
|
||||
# HSM DRC (DISASTER RECOVERY CENTER)
|
||||
# HSM SERVER
|
||||
IP_HSM_SERVER_BACKUP_1="10.1.201.222"
|
||||
URL_HSM_SERVER_BACKUP_1="ws://10.1.201.215/feliqserver/v1/wsapi"
|
||||
APIKEY_HSM_SERVER_BACKUP_1="bc391562-f880-3b57-9868-36dfa5cbf954-0TC"
|
||||
SECRETKEY_HSM_SERVER_BACKUP_1="xWW2o+lpAqDLIN85uHZdfuDQhhd7jCXp4w1rXhCkYEk="
|
||||
IP_HSM_SERVER_BACKUP_2="10.1.201.215"
|
||||
URL_HSM_SERVER_BACKUP_2="ws://10.1.201.215:88/feliqserver/v1/wsapi"
|
||||
APIKEY_HSM_SERVER_BACKUP_2="bc391562-f880-3b57-9868-36dfa5cbf954-0TC"
|
||||
SECRETKEY_HSM_SERVER_BACKUP_2="xWW2o+lpAqDLIN85uHZdfuDQhhd7jCXp4w1rXhCkYEk="
|
||||
|
||||
|
||||
# ============================= KONFIGURASI HSM NUTECH =============================
|
||||
|
||||
# SYSTEM CODE IN HEXA STRING
|
||||
# system code nutech profile
|
||||
# SYSTEM_CODE=939E
|
||||
|
||||
#SERVICE BLOCK
|
||||
# SERVICEBLOCK_SERVICE_MUTUAL="102001A04C2001A0882001A0"
|
||||
# SERVICEBLOCK_BLOCK_READ="80008200"
|
||||
# SERVICEBLOCK_BLOCK_WRITE="800081008200"
|
||||
|
||||
# HSM DC (DATA CENTER)
|
||||
# HSM SERVER
|
||||
# URL_HSM_SERVER_1="ws://10.1.201.215/feliqserver/v1/wsapi"
|
||||
# APIKEY_HSM_SERVER_1="d54ff5c4-9709-3bac-9a6e-04b2f4deebae-0TC"
|
||||
# SECRETKEY_HSM_SERVER_1="W8ZiN1o2tNkb1svNlj5Kl8PNohhujaTxeNaGEq2rOWY="
|
||||
# JEPANG
|
||||
# URL_HSM_SERVER_1="wss://gateway04.cyberware.co.jp/feliqserver/v1/wsapi"
|
||||
# APIKEY_HSM_SERVER_1="4c6dd075-dbcb-375f-81f7-62990a5d7000-0TC"
|
||||
# SECRETKEY_HSM_SERVER_1="U5xs7nVonhtbQ+XiYATRSg8Nk5sPu1IpVx7X40KyWiw="
|
||||
# URL_HSM_SERVER_2="wss://gateway04.cyberware.co.jp/feliqserver/v1/wsapi"
|
||||
# APIKEY_HSM_SERVER_2="4c6dd075-dbcb-375f-81f7-62990a5d7000-0TC"
|
||||
# SECRETKEY_HSM_SERVER_2="U5xs7nVonhtbQ+XiYATRSg8Nk5sPu1IpVx7X40KyWiw="
|
||||
|
||||
# HSM DRC (DISASTER RECOVERY CENTER)
|
||||
# HSM SERVER
|
||||
# URL_HSM_SERVER_BACKUP_1="ws://10.1.201.215/feliqserver/v1/wsapi"
|
||||
# APIKEY_HSM_SERVER_BACKUP_1="d54ff5c4-9709-3bac-9a6e-04b2f4deebae-0TC"
|
||||
# SECRETKEY_HSM_SERVER_BACKUP_1="W8ZiN1o2tNkb1svNlj5Kl8PNohhujaTxeNaGEq2rOWY="
|
||||
# JEPANG
|
||||
# URL_HSM_SERVER_BACKUP_2="wss://gateway04.cyberware.co.jp/feliqserver/v1/wsapi"
|
||||
# APIKEY_HSM_SERVER_BACKUP_2="4c6dd075-dbcb-375f-81f7-62990a5d7000-0TC"
|
||||
# SECRETKEY_HSM_SERVER_BACKUP_2="U5xs7nVonhtbQ+XiYATRSg8Nk5sPu1IpVx7X40KyWiw="
|
||||
|
||||
|
||||
|
||||
@@ -1,33 +1,60 @@
|
||||
require("dotenv").config();
|
||||
const winston = require("./application/helpers/winston.logger");
|
||||
const server = require("./server");
|
||||
require('dotenv').config();
|
||||
const cluster = require('node:cluster');
|
||||
const totalCPUs = require('node:os').cpus().length;
|
||||
const process = require('node:process');
|
||||
const winston = require('./application/helpers/winston.logger');
|
||||
const server = require('./server');
|
||||
|
||||
// set port, listen for requests
|
||||
const PORT = process.env.PORT || 3000;
|
||||
var serverHSMStatus = "HSM SERVER NOT CONNECTED";
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == "1") {
|
||||
var serverHSMStatus = 'HSM SERVER NOT CONNECTED';
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '1') {
|
||||
serverHSMStatus = `SERVER 1 CONNECTED on ip ${process.env.IP_HSM_SERVER_1}`;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == "2") {
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '2') {
|
||||
serverHSMStatus = `SERVER 2 CONNECTED on ip ${process.env.IP_HSM_SERVER_2}`;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == "12") {
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
serverHSMStatus = `SERVER 1 on ip ${process.env.IP_HSM_SERVER_1} AND SERVER 2 on ip ${process.env.IP_HSM_SERVER_2} CONNECTED`;
|
||||
}
|
||||
|
||||
var serverActive = "DC (DATA CENTER)";
|
||||
if (process.env.CHANGE_TO_DRC == "YES" || process.env.CHANGE_TO_DRC == "yes") {
|
||||
serverActive = "DRC (DISASTER RECOVERY CENTER)";
|
||||
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == "1") {
|
||||
var serverActive = 'DC (DATA CENTER)';
|
||||
if (process.env.CHANGE_TO_DRC == 'YES' || process.env.CHANGE_TO_DRC == 'yes') {
|
||||
serverActive = 'DRC (DISASTER RECOVERY CENTER)';
|
||||
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '1') {
|
||||
serverHSMStatus = `SERVER 1 CONNECTED on ip ${process.env.IP_HSM_SERVER_BACKUP_1}`;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == "2") {
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '2') {
|
||||
serverHSMStatus = `SERVER 2 CONNECTED on ip ${process.env.IP_HSM_SERVER_BACKUP_2}`;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == "12") {
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
serverHSMStatus = `SERVER 1 on ip ${process.env.IP_HSM_SERVER_BACKUP_1} AND SERVER 2 on ip ${process.env.IP_HSM_SERVER_BACKUP_2} CONNECTED`;
|
||||
}
|
||||
}
|
||||
|
||||
server.listen(PORT, () => {
|
||||
winston.logger.info(
|
||||
`Server is running on environment: ${process.env.NODE_ENV.toUpperCase()} port: ${PORT} on ${serverActive}. HSM STATUS : ${serverHSMStatus} `
|
||||
);
|
||||
});
|
||||
if (cluster.isMaster) {
|
||||
console.log(`Number of CPUs is ${totalCPUs}`);
|
||||
console.log(`Master ${process.pid} is running`);
|
||||
|
||||
// Fork workers.
|
||||
for (let i = 0; i < totalCPUs; i++) {
|
||||
cluster.fork();
|
||||
}
|
||||
|
||||
cluster.on('exit', (worker, code, signal) => {
|
||||
console.log(`worker ${worker.process.pid} died`);
|
||||
console.log("Let's fork another worker!");
|
||||
cluster.fork();
|
||||
});
|
||||
} else {
|
||||
startExpress();
|
||||
}
|
||||
|
||||
console.log(`worker pid=${process.pid}`);
|
||||
|
||||
function startExpress() {
|
||||
server.listen(PORT, () => {
|
||||
winston.logger.info(
|
||||
`Server is running on version ${
|
||||
process.env.VERSION
|
||||
} environment: ${process.env.NODE_ENV.toUpperCase()} port: ${PORT} on ${serverActive}. HSM STATUS : ${serverHSMStatus} `
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ module.exports = {
|
||||
// connection: process.env.DB_URL,
|
||||
pool: {
|
||||
min: 2,
|
||||
max: 10,
|
||||
max: 30,
|
||||
},
|
||||
migrations: {
|
||||
directory: './infrastructure/database/migrations',
|
||||
|
||||
+139
-146
@@ -12,6 +12,7 @@ const historyRoute = require('../application/routes/history.routes');
|
||||
const paymentReconRoute = require('../application/routes/paymentrecon.routes');
|
||||
const invoiceRoute = require('../application/routes/invoiceonline.routes');
|
||||
const cashinRoute = require('../application/routes/cahsin.routes');
|
||||
const pooling = require('../application/routes/pooling.routes');
|
||||
const cron = require('node-cron');
|
||||
const moment = require('moment');
|
||||
require('dotenv').config();
|
||||
@@ -22,13 +23,18 @@ const client = require('prom-client');
|
||||
const register = new client.Registry();
|
||||
const {
|
||||
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);
|
||||
@@ -55,23 +61,9 @@ app.use(responseTime());
|
||||
|
||||
// ============================== ROUTES API ==============================
|
||||
app.get('/', async (req, res) => {
|
||||
let data = {
|
||||
card_number: '1234567890',
|
||||
amount: 10000,
|
||||
};
|
||||
|
||||
let chipperData = helper.encryptText(JSON.stringify(data));
|
||||
let decrypData = JSON.parse(helper.decryptText(chipperData));
|
||||
res.json({
|
||||
message: 'Welcome to Topup Online Service.',
|
||||
data: {
|
||||
text: '0nlinet0pupkci',
|
||||
chiper_text: helper.encryptText('0nlinet0pupkci'),
|
||||
chipper_data: chipperData,
|
||||
decrypt_data: decrypData,
|
||||
date: moment().format('YYYYMMDDHHmm'),
|
||||
secret_key: helper.encryptText('0nlinetopupDev'),
|
||||
},
|
||||
data: {},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -87,6 +79,7 @@ app.use('/api/', paymentReconRoute);
|
||||
app.use('/api/', reservationRoute);
|
||||
app.use('/api/', invoiceRoute);
|
||||
app.use('/api/', cashinRoute);
|
||||
app.use('/api/', pooling);
|
||||
|
||||
// ============================== SAP SCHEDULLER =============================
|
||||
|
||||
@@ -96,150 +89,150 @@ app.use('/api/', cashinRoute);
|
||||
// SCHEDULER FOR GENERATE INVOICE
|
||||
// ===================================================
|
||||
|
||||
const {
|
||||
_generateInvoice,
|
||||
_postingInvoice,
|
||||
} = require('../application/modules/invoiceonline/invoice.controller');
|
||||
// const {
|
||||
// _generateInvoice,
|
||||
// _postingInvoice,
|
||||
// } = require('../application/modules/invoiceonline/invoice.controller');
|
||||
|
||||
// GENERATE + POSTING INVOICE
|
||||
cron.schedule('0 1 * * *', async () => {
|
||||
try {
|
||||
// let ivoiceDate = moment().add(1, 'days').format("YYYY-MM-DD");
|
||||
let ivoiceDate = moment().format('YYYY-MM-DD');
|
||||
let uniqueCode = helper.getUniqueCode();
|
||||
winston.logger.debug(
|
||||
`STARTING SCHEDULER-FB70 GENERATE INVOICE ${ivoiceDate} `
|
||||
);
|
||||
const generate = await _generateInvoice(ivoiceDate, uniqueCode, false);
|
||||
winston.logger.debug(
|
||||
`END SCHEDULER-FB70 GENERATE INVOICE ${ivoiceDate} : ${JSON.stringify(
|
||||
generate
|
||||
)}`
|
||||
);
|
||||
const reGenerate = await _generateInvoice(ivoiceDate, uniqueCode, true);
|
||||
winston.logger.debug(
|
||||
`END SCHEDULER-FB70 RE-GENERATE INVOICE THAT HAVE BEEN DELETED ${ivoiceDate} : ${JSON.stringify(
|
||||
generate
|
||||
)}`
|
||||
);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
}
|
||||
});
|
||||
// cron.schedule('0 1 * * *', async () => {
|
||||
// try {
|
||||
// // let ivoiceDate = moment().add(1, 'days').format("YYYY-MM-DD");
|
||||
// let ivoiceDate = moment().format('YYYY-MM-DD');
|
||||
// let uniqueCode = helper.getUniqueCode();
|
||||
// winston.logger.debug(
|
||||
// `STARTING SCHEDULER-FB70 GENERATE INVOICE ${ivoiceDate} `
|
||||
// );
|
||||
// const generate = await _generateInvoice(ivoiceDate, uniqueCode, false);
|
||||
// winston.logger.debug(
|
||||
// `END SCHEDULER-FB70 GENERATE INVOICE ${ivoiceDate} : ${JSON.stringify(
|
||||
// generate
|
||||
// )}`
|
||||
// );
|
||||
// const reGenerate = await _generateInvoice(ivoiceDate, uniqueCode, true);
|
||||
// winston.logger.debug(
|
||||
// `END SCHEDULER-FB70 RE-GENERATE INVOICE THAT HAVE BEEN DELETED ${ivoiceDate} : ${JSON.stringify(
|
||||
// generate
|
||||
// )}`
|
||||
// );
|
||||
// } catch (error) {
|
||||
// // create log
|
||||
// winston.logger.error(
|
||||
// `500 internal server error - backend server | ${error.message}`
|
||||
// );
|
||||
// }
|
||||
// });
|
||||
|
||||
// RE-TRY POSTING
|
||||
cron.schedule('0 7 * * *', async () => {
|
||||
try {
|
||||
let uniqueCode = helper.getUniqueCode();
|
||||
winston.logger.debug(`STARTING SCHEDULER-FB70 RE-TRY POSTING INVOICE`);
|
||||
const posting = await _postingInvoice(uniqueCode);
|
||||
winston.logger.debug(
|
||||
`END SCHEDULER-FB70 RE-TRY POSTING INVOICE : ${JSON.stringify(posting)}`
|
||||
);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
}
|
||||
});
|
||||
// cron.schedule('0 7 * * *', async () => {
|
||||
// try {
|
||||
// let uniqueCode = helper.getUniqueCode();
|
||||
// winston.logger.debug(`STARTING SCHEDULER-FB70 RE-TRY POSTING INVOICE`);
|
||||
// const posting = await _postingInvoice(uniqueCode);
|
||||
// winston.logger.debug(
|
||||
// `END SCHEDULER-FB70 RE-TRY POSTING INVOICE : ${JSON.stringify(posting)}`
|
||||
// );
|
||||
// } catch (error) {
|
||||
// // create log
|
||||
// winston.logger.error(
|
||||
// `500 internal server error - backend server | ${error.message}`
|
||||
// );
|
||||
// }
|
||||
// });
|
||||
|
||||
cron.schedule('0 12 * * *', async () => {
|
||||
try {
|
||||
let uniqueCode = helper.getUniqueCode();
|
||||
winston.logger.debug(`STARTING SCHEDULER-FB70 RE-TRY POSTING INVOICE`);
|
||||
const posting = await _postingInvoice(uniqueCode);
|
||||
winston.logger.debug(
|
||||
`END SCHEDULER-FB70 RE-TRY POSTING INVOICE : ${JSON.stringify(posting)}`
|
||||
);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
}
|
||||
});
|
||||
// cron.schedule('0 12 * * *', async () => {
|
||||
// try {
|
||||
// let uniqueCode = helper.getUniqueCode();
|
||||
// winston.logger.debug(`STARTING SCHEDULER-FB70 RE-TRY POSTING INVOICE`);
|
||||
// const posting = await _postingInvoice(uniqueCode);
|
||||
// winston.logger.debug(
|
||||
// `END SCHEDULER-FB70 RE-TRY POSTING INVOICE : ${JSON.stringify(posting)}`
|
||||
// );
|
||||
// } catch (error) {
|
||||
// // create log
|
||||
// winston.logger.error(
|
||||
// `500 internal server error - backend server | ${error.message}`
|
||||
// );
|
||||
// }
|
||||
// });
|
||||
|
||||
cron.schedule('0 17 * * *', async () => {
|
||||
try {
|
||||
let uniqueCode = helper.getUniqueCode();
|
||||
winston.logger.debug(`STARTING SCHEDULER-FB70 RE-TRY POSTING INVOICE`);
|
||||
const posting = await _postingInvoice(uniqueCode);
|
||||
winston.logger.debug(
|
||||
`END SCHEDULER-FB70 RE-TRY POSTING INVOICE : ${JSON.stringify(posting)}`
|
||||
);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
}
|
||||
});
|
||||
// cron.schedule('0 17 * * *', async () => {
|
||||
// try {
|
||||
// let uniqueCode = helper.getUniqueCode();
|
||||
// winston.logger.debug(`STARTING SCHEDULER-FB70 RE-TRY POSTING INVOICE`);
|
||||
// const posting = await _postingInvoice(uniqueCode);
|
||||
// winston.logger.debug(
|
||||
// `END SCHEDULER-FB70 RE-TRY POSTING INVOICE : ${JSON.stringify(posting)}`
|
||||
// );
|
||||
// } catch (error) {
|
||||
// // create log
|
||||
// winston.logger.error(
|
||||
// `500 internal server error - backend server | ${error.message}`
|
||||
// );
|
||||
// }
|
||||
// });
|
||||
|
||||
// ===================================================
|
||||
// SCHEDULER FOR GENERATE INVOICE
|
||||
// ===================================================
|
||||
// cash in
|
||||
const {
|
||||
_generateCashIn,
|
||||
} = require('../application/modules/cashin/cahsin.controller');
|
||||
// const {
|
||||
// _generateCashIn,
|
||||
// } = require('../application/modules/cashin/cahsin.controller');
|
||||
|
||||
cron.schedule('30 7 * * *', async () => {
|
||||
try {
|
||||
let uniqueCode = helper.getUniqueCode();
|
||||
winston.logger.info(
|
||||
`STARTING SCHEDULER-FB70 GENERATE CASH IN ${uniqueCode}`
|
||||
);
|
||||
const posting = await _generateCashIn(uniqueCode);
|
||||
winston.logger.info(
|
||||
`END SCHEDULER-FB70 GENERATE CASH IN : ${JSON.stringify(posting)}`
|
||||
);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`500 SCHEDULER-FB70 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
}
|
||||
});
|
||||
// cron.schedule('30 7 * * *', async () => {
|
||||
// try {
|
||||
// let uniqueCode = helper.getUniqueCode();
|
||||
// winston.logger.info(
|
||||
// `STARTING SCHEDULER-FB70 GENERATE CASH IN ${uniqueCode}`
|
||||
// );
|
||||
// const posting = await _generateCashIn(uniqueCode);
|
||||
// winston.logger.info(
|
||||
// `END SCHEDULER-FB70 GENERATE CASH IN : ${JSON.stringify(posting)}`
|
||||
// );
|
||||
// } catch (error) {
|
||||
// // create log
|
||||
// winston.logger.error(
|
||||
// `500 SCHEDULER-FB70 internal server error - backend server | ${error.message}`
|
||||
// );
|
||||
// }
|
||||
// });
|
||||
|
||||
cron.schedule('30 12 * * *', async () => {
|
||||
try {
|
||||
let uniqueCode = helper.getUniqueCode();
|
||||
winston.logger.info(
|
||||
`STARTING SCHEDULER-FB70 GENERATE CASH IN ${uniqueCode}`
|
||||
);
|
||||
const posting = await _generateCashIn(uniqueCode);
|
||||
winston.logger.info(
|
||||
`END SCHEDULER-FB70 GENERATE CASH IN : ${JSON.stringify(posting)}`
|
||||
);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`500 SCHEDULER-FB70 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
}
|
||||
});
|
||||
// cron.schedule('30 12 * * *', async () => {
|
||||
// try {
|
||||
// let uniqueCode = helper.getUniqueCode();
|
||||
// winston.logger.info(
|
||||
// `STARTING SCHEDULER-FB70 GENERATE CASH IN ${uniqueCode}`
|
||||
// );
|
||||
// const posting = await _generateCashIn(uniqueCode);
|
||||
// winston.logger.info(
|
||||
// `END SCHEDULER-FB70 GENERATE CASH IN : ${JSON.stringify(posting)}`
|
||||
// );
|
||||
// } catch (error) {
|
||||
// // create log
|
||||
// winston.logger.error(
|
||||
// `500 SCHEDULER-FB70 internal server error - backend server | ${error.message}`
|
||||
// );
|
||||
// }
|
||||
// });
|
||||
|
||||
cron.schedule('30 17 * * *', async () => {
|
||||
try {
|
||||
let uniqueCode = helper.getUniqueCode();
|
||||
winston.logger.info(
|
||||
`STARTING SCHEDULER-FB70 GENERATE CASH IN ${uniqueCode}`
|
||||
);
|
||||
const posting = await _generateCashIn(uniqueCode);
|
||||
winston.logger.info(
|
||||
`END SCHEDULER-FB70 GENERATE CASH IN : ${JSON.stringify(posting)}`
|
||||
);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`500 SCHEDULER-FB70 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
}
|
||||
});
|
||||
// cron.schedule('30 17 * * *', async () => {
|
||||
// try {
|
||||
// let uniqueCode = helper.getUniqueCode();
|
||||
// winston.logger.info(
|
||||
// `STARTING SCHEDULER-FB70 GENERATE CASH IN ${uniqueCode}`
|
||||
// );
|
||||
// const posting = await _generateCashIn(uniqueCode);
|
||||
// winston.logger.info(
|
||||
// `END SCHEDULER-FB70 GENERATE CASH IN : ${JSON.stringify(posting)}`
|
||||
// );
|
||||
// } catch (error) {
|
||||
// // create log
|
||||
// winston.logger.error(
|
||||
// `500 SCHEDULER-FB70 internal server error - backend server | ${error.message}`
|
||||
// );
|
||||
// }
|
||||
// });
|
||||
|
||||
// }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user