mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-05 14:46:27 +00:00
Compare commits
52 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1d2e92b85f | |||
| 51cb6c1212 | |||
| 6c93cff3bb | |||
| b24335043a | |||
| ac2ea55b5d | |||
| f3e9097bfa | |||
| 0dcec2a6ad | |||
| f8f974eb11 | |||
| 29981e9757 | |||
| a59a9090a7 | |||
| ca17c397c5 | |||
| ff1a80f3b5 | |||
| 4bda7458b4 | |||
| d4d61d1d79 | |||
| 80557a53e8 | |||
| 920a6d4ccd | |||
| ecd0cb12c4 | |||
| fe484b08af | |||
| f5a55392c9 | |||
| 2dc27ea57c | |||
| ecb78bfa29 | |||
| 74936dbe0d | |||
| b1814031b9 | |||
| b5061cf78e | |||
| a8e0376496 | |||
| 16a20faee6 | |||
| 0f34326da4 | |||
| 5d7852eff9 | |||
| 009e6caead | |||
| e61392d81a | |||
| 8c0b6f7e7c | |||
| cee0352271 | |||
| dfce874ce9 | |||
| 84de02de26 | |||
| 46e3cd689b | |||
| 31b581c85e | |||
| 50008e2006 | |||
| c30cdcf4ed | |||
| e77a975ccc | |||
| 728a9a92c9 | |||
| 24006105b9 | |||
| c2e95ee6a5 | |||
| da1912d05d | |||
| 7171d1e3f5 | |||
| 05098fa3ac | |||
| 131cac392b | |||
| cd3c29bee0 | |||
| 8436ea2071 | |||
| 032e12d9d0 | |||
| 5e91b9a147 | |||
| 9b8865233b | |||
| 3645bb2420 |
@@ -1,49 +1,58 @@
|
||||
const jwt = require("jsonwebtoken");
|
||||
const helper = require("../helpers/helper");
|
||||
const jwt = require('jsonwebtoken');
|
||||
const helper = require('../helpers/helper');
|
||||
const winston = require('../helpers/winston.logger');
|
||||
|
||||
const generateRefreshToken = (req) => {
|
||||
let expiresIn = process.env.JWT_REFRESH_EXPIRATION ? process.env.JWT_REFRESH_EXPIRATION : "7d";
|
||||
let expiresIn = process.env.JWT_REFRESH_EXPIRATION
|
||||
? process.env.JWT_REFRESH_EXPIRATION
|
||||
: '7d';
|
||||
let signOptions = {
|
||||
issuer: 'CMS Kereta Commuter Indonesia',
|
||||
expiresIn: expiresIn,
|
||||
}
|
||||
};
|
||||
return jwt.sign(req, process.env.REFRESH_TOKEN_SECRET, signOptions);
|
||||
};
|
||||
|
||||
const authenticateRefreshToken = (req, res, next) => {
|
||||
|
||||
let verifyOptions = {
|
||||
issuer: 'CMS Kereta Commuter Indonesia',
|
||||
}
|
||||
};
|
||||
|
||||
jwt.verify(req.header("refresh_token"), process.env.REFRESH_TOKEN_SECRET, verifyOptions, (err, data) => {
|
||||
if (err) {
|
||||
return res.json({
|
||||
code: "400",
|
||||
message: "Refresh Token is invalid. Please login!",
|
||||
data: {},
|
||||
});
|
||||
jwt.verify(
|
||||
req.header('refresh_token'),
|
||||
process.env.REFRESH_TOKEN_SECRET,
|
||||
verifyOptions,
|
||||
(err, data) => {
|
||||
if (err) {
|
||||
return res.json({
|
||||
code: '400',
|
||||
message: 'Refresh Token is invalid. Please login!',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
);
|
||||
};
|
||||
|
||||
const generateAccessToken = (req) => {
|
||||
let expiresIn = process.env.JWT_EXPIRATION ? process.env.JWT_EXPIRATION : "1d";
|
||||
let expiresIn = process.env.JWT_EXPIRATION
|
||||
? process.env.JWT_EXPIRATION
|
||||
: '1d';
|
||||
let signOptions = {
|
||||
issuer: 'CMS Kereta Commuter Indonesia',
|
||||
expiresIn: expiresIn,
|
||||
}
|
||||
};
|
||||
|
||||
if (req.user_group_id == "1") {
|
||||
if (req.user_group_id == '1') {
|
||||
expiresIn = parseInt(process.env.JWT_EXPIRATION_ADMIN_WEB);
|
||||
} else if (req.user_group_id == "2") {
|
||||
} else if (req.user_group_id == '2') {
|
||||
expiresIn = parseInt(process.env.JWT_EXPIRATION_MOBILE_PHONE);
|
||||
} else if (
|
||||
req.user_group_id == "3" ||
|
||||
req.user_group_id == "4" ||
|
||||
req.user_group_id == "5"
|
||||
req.user_group_id == '3' ||
|
||||
req.user_group_id == '4' ||
|
||||
req.user_group_id == '5'
|
||||
) {
|
||||
expiresIn = parseInt(process.env.JWT_EXPIRATION_TERMINAL);
|
||||
}
|
||||
@@ -52,43 +61,59 @@ const generateAccessToken = (req) => {
|
||||
};
|
||||
|
||||
const authenticateToken = async (req, res, next) => {
|
||||
let authHeader = req.headers["authorization"];
|
||||
let authHeader = req.headers['authorization'];
|
||||
|
||||
var ip = req.headers['x-real-ip'] || req.connection.remoteAddress;
|
||||
|
||||
console.log('INI LHO IP NYA....................: ' + ip);
|
||||
|
||||
if (authHeader) {
|
||||
let token = authHeader && authHeader.split(" ")[1];
|
||||
let token = authHeader && authHeader.split(' ')[1];
|
||||
|
||||
// winston.logger.info(
|
||||
// `000000000000 [ AUTHENTICATE TOKEN ]: ${JSON.stringify({
|
||||
// token: token,
|
||||
// ip: ip,
|
||||
// })}`
|
||||
// );
|
||||
|
||||
if (!token) {
|
||||
return res.json({
|
||||
code: "401",
|
||||
message: "Token is required",
|
||||
code: '401',
|
||||
message: 'Token is required',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
let verifyOptions = {
|
||||
issuer: 'CMS Kereta Commuter Indonesia',
|
||||
}
|
||||
};
|
||||
|
||||
await jwt.verify(token, process.env.TOKEN_SECRET, verifyOptions, (err, data) => {
|
||||
if (err) {
|
||||
return res.json({
|
||||
code: "402",
|
||||
message: "Invalid Token.",
|
||||
data: {},
|
||||
});
|
||||
await jwt.verify(
|
||||
token,
|
||||
process.env.TOKEN_SECRET,
|
||||
verifyOptions,
|
||||
(err, data) => {
|
||||
if (err) {
|
||||
return res.json({
|
||||
code: '402',
|
||||
message: 'Invalid Token.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
req.mid_token = helper.decryptText(data.mid);
|
||||
req.tid_token = helper.decryptText(data.tid);
|
||||
req.partner_id_token = helper.decryptText(data.partner_id);
|
||||
req.partner_user_id_token = helper.decryptText(data.partner_user_id);
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
req.mid_token = helper.decryptText(data.mid);
|
||||
req.tid_token = helper.decryptText(data.tid);
|
||||
req.partner_id_token = helper.decryptText(data.partner_id);
|
||||
req.partner_user_id_token = helper.decryptText(data.partner_user_id);
|
||||
|
||||
next();
|
||||
});
|
||||
);
|
||||
} else {
|
||||
return res.json({
|
||||
code: "400",
|
||||
message: "Header not found",
|
||||
code: '400',
|
||||
message: 'Header not found',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
const { default: axios } = require('axios');
|
||||
const helper = require('../../helpers/helper');
|
||||
const winston = require('../../helpers/winston.logger');
|
||||
const generate = require('./utils/utils');
|
||||
@@ -33,6 +34,7 @@ const controller = async (req, res) => {
|
||||
let uniqueCode = await helper.getUniqueCode();
|
||||
uniqueCode = uniqueCode + '' + counterDirect;
|
||||
let result = {};
|
||||
let usingHSMNumber = 1;
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
@@ -43,12 +45,14 @@ const controller = async (req, res) => {
|
||||
// winston.logger.error(`request to HSM server 2`);
|
||||
|
||||
if (client2.clientAuthenticated == false) {
|
||||
usingHSMNumber = 1;
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} ================================== REDIRECT USING HSM SERVER 1 ==================================}`
|
||||
);
|
||||
useClient = client;
|
||||
} else {
|
||||
usingHSMNumber = 2;
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} ================================== USING HSM SERVER 2 ==================================}`
|
||||
@@ -57,12 +61,14 @@ const controller = async (req, res) => {
|
||||
}
|
||||
} else {
|
||||
if (client.clientAuthenticated == false) {
|
||||
usingHSMNumber = 2;
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} ================================== REDIRECT USING HSM SERVER 2 ==================================}`
|
||||
);
|
||||
useClient = client2;
|
||||
} else {
|
||||
usingHSMNumber = 1;
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} ================================== USING HSM SERVER 1 ==================================}`
|
||||
@@ -137,20 +143,34 @@ const controller = async (req, res) => {
|
||||
await _sleep(10);
|
||||
}
|
||||
|
||||
// if (_timeOut) {
|
||||
// result = {
|
||||
// code: "5001",
|
||||
// message: "Timeout",
|
||||
// data: {},
|
||||
// };
|
||||
if (_timeOut) {
|
||||
let url = `http://${process.env.IP_HSM_SERVER_1}/feliqserver/v1/api/hsm/refresh`;
|
||||
if (usingHSMNumber == 2) {
|
||||
url = `http://${process.env.IP_HSM_SERVER_2}/feliqserver/v1/api/hsm/refresh`;
|
||||
}
|
||||
|
||||
// // log warn
|
||||
// winston.logger.warn(
|
||||
// `${uniqueCode} response HSM - auth1v2: ${JSON.stringify(result)}`
|
||||
// );
|
||||
let response = await axios({
|
||||
url: url,
|
||||
method: 'get',
|
||||
});
|
||||
|
||||
// return res.status(200).send(result);
|
||||
// }
|
||||
result = {
|
||||
code: '5001',
|
||||
message: 'Timeout',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE TOPUP-1 ]: ${JSON.stringify(
|
||||
result
|
||||
)} and refresh HSM ${usingHSMNumber} response status: ${
|
||||
response.status
|
||||
} | response text: ${response.statusText}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
}
|
||||
|
||||
_stopMessage = 0;
|
||||
|
||||
|
||||
@@ -659,7 +659,7 @@ const loadingBalanceRequest = async (req, res) => {
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE-REQUEST ]: ${JSON.stringify(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE-REQUEST updateFraudToReserve ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
@@ -795,7 +795,7 @@ const loadingBalanceRequest = async (req, res) => {
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE-REQUEST ]: ${JSON.stringify(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE-REQUEST getReservationPending ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
@@ -826,7 +826,7 @@ const loadingBalanceRequest = async (req, res) => {
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE-REQUEST ]: ${JSON.stringify(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE-REQUEST totalReservation ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
@@ -1474,18 +1474,18 @@ const loadingBalanceInsert = async (req, param) => {
|
||||
loadBalanceNoSequence
|
||||
);
|
||||
|
||||
if (loadBalanceNumber != 'XX') {
|
||||
// set sequence to redis
|
||||
// await setLoadBalanceNumberSequence(
|
||||
// req.partner_id_token,
|
||||
// loadBalanceNoSequence
|
||||
// );
|
||||
}
|
||||
// if (loadBalanceNumber != 'XX') {
|
||||
// set sequence to redis
|
||||
// await setLoadBalanceNumberSequence(
|
||||
// req.partner_id_token,
|
||||
// loadBalanceNoSequence
|
||||
// );
|
||||
// }
|
||||
|
||||
// log warn
|
||||
// winston.logger.warn(
|
||||
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: load balance number is ${loadBalanceNumber}.`
|
||||
// );
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: load balance number sequence is ${loadBalanceNoSequence}.`
|
||||
);
|
||||
|
||||
if (maxLoop > maxLoopParameter) {
|
||||
// create log
|
||||
|
||||
@@ -111,7 +111,11 @@ const checkReservation = async (req, res) => {
|
||||
let { mid, tid, card_number } = req.body;
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
// winston.logger.info(
|
||||
// `${uniqueCode} [ REQUEST RESERVATION-CHECK ]: ${JSON.stringify(req.body)}`
|
||||
// );
|
||||
|
||||
console.log(
|
||||
`${uniqueCode} [ REQUEST RESERVATION-CHECK ]: ${JSON.stringify(req.body)}`
|
||||
);
|
||||
|
||||
@@ -125,11 +129,11 @@ const checkReservation = async (req, res) => {
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE RESERVATION-CHECK ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
// winston.logger.warn(
|
||||
// `${uniqueCode} [ RESPONSE RESERVATION-CHECK ]: ${JSON.stringify(
|
||||
// result
|
||||
// )}`
|
||||
// );
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
@@ -153,11 +157,11 @@ const checkReservation = async (req, res) => {
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE RESERVATION-CHECK ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
// winston.logger.warn(
|
||||
// `${uniqueCode} [ RESPONSE RESERVATION-CHECK ]: ${JSON.stringify(
|
||||
// result
|
||||
// )}`
|
||||
// );
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
@@ -171,11 +175,11 @@ const checkReservation = async (req, res) => {
|
||||
data: {},
|
||||
};
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE RESERVATION-CHECK ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
// winston.logger.warn(
|
||||
// `${uniqueCode} [ RESPONSE RESERVATION-CHECK ]: ${JSON.stringify(
|
||||
// result
|
||||
// )}`
|
||||
// );
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
}
|
||||
@@ -196,11 +200,11 @@ const checkReservation = async (req, res) => {
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE RESERVATION-CHECK ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
// winston.logger.warn(
|
||||
// `${uniqueCode} [ RESPONSE RESERVATION-CHECK ]: ${JSON.stringify(
|
||||
// result
|
||||
// )}`
|
||||
// );
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
@@ -236,7 +240,11 @@ const checkReservation = async (req, res) => {
|
||||
}
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
// winston.logger.info(
|
||||
// `${uniqueCode} [ RESPONSE RESERVATION-CHECK ]: ${JSON.stringify(result)}`
|
||||
// );
|
||||
|
||||
console.log(
|
||||
`${uniqueCode} [ RESPONSE RESERVATION-CHECK ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
@@ -617,16 +625,22 @@ const reservationValidate = async (req, res) => {
|
||||
let getIssuer = await model.getIssuer(getPartner.i_partner, now);
|
||||
|
||||
if (getIssuer) {
|
||||
// ======================= KHUSUS LRT JABODEBEK =============================
|
||||
if (getPartner.partner_code == 'P05') {
|
||||
// per tanggal 1 November 2023 fee sharing mulai menggunakan amount nominal dan bukan persentase lagi
|
||||
if (today >= '2023-11-01') {
|
||||
issuerFee = getIssuer.i_issuer_fee_nominal;
|
||||
channelFee = getIssuer.i_channel_fee_nominal;
|
||||
} else {
|
||||
// SELAIN LRT JABODEBEK
|
||||
issuerFee =
|
||||
(getIssuer.i_issuer_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
channelFee =
|
||||
(getIssuer.i_channel_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
// ======================= KHUSUS LRT JABODEBEK =============================
|
||||
if (getPartner.partner_code == 'P05') {
|
||||
issuerFee = getIssuer.i_issuer_fee_nominal;
|
||||
channelFee = getIssuer.i_channel_fee_nominal;
|
||||
} else {
|
||||
// SELAIN LRT JABODEBEK
|
||||
issuerFee =
|
||||
(getIssuer.i_issuer_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
channelFee =
|
||||
(getIssuer.i_channel_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
// if (!getIssuer) {
|
||||
@@ -1046,16 +1060,22 @@ const reservationValidateV2 = async (req, res) => {
|
||||
let getIssuer = await model.getIssuer(getPartner.i_partner, now);
|
||||
|
||||
if (getIssuer) {
|
||||
// ======================= KHUSUS LRT JABODEBEK =============================
|
||||
if (getPartner.partner_code == 'P05') {
|
||||
// per tanggal 1 November 2023 fee sharing mulai menggunakan amount nominal dan bukan persentase lagi
|
||||
if (today >= '2023-11-01') {
|
||||
issuerFee = getIssuer.i_issuer_fee_nominal;
|
||||
channelFee = getIssuer.i_channel_fee_nominal;
|
||||
} else {
|
||||
// SELAIN LRT JABODEBEK
|
||||
issuerFee =
|
||||
(getIssuer.i_issuer_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
channelFee =
|
||||
(getIssuer.i_channel_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
// ======================= KHUSUS LRT JABODEBEK =============================
|
||||
if (getPartner.partner_code == 'P05') {
|
||||
issuerFee = getIssuer.i_issuer_fee_nominal;
|
||||
channelFee = getIssuer.i_channel_fee_nominal;
|
||||
} else {
|
||||
// SELAIN LRT JABODEBEK
|
||||
issuerFee =
|
||||
(getIssuer.i_issuer_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
channelFee =
|
||||
(getIssuer.i_channel_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1497,16 +1517,22 @@ const reservation = async (req, res) => {
|
||||
let getIssuer = await model.getIssuer(getPartner.i_partner, now);
|
||||
|
||||
if (getIssuer) {
|
||||
// ======================= KHUSUS LRT JABODEBEK =============================
|
||||
if (getPartner.partner_code == 'P05') {
|
||||
// per tanggal 1 November 2023 fee sharing mulai menggunakan amount nominal dan bukan persentase lagi
|
||||
if (today >= '2023-11-01') {
|
||||
issuerFee = getIssuer.i_issuer_fee_nominal;
|
||||
channelFee = getIssuer.i_channel_fee_nominal;
|
||||
} else {
|
||||
// SELAIN LRT JABODEBEK
|
||||
issuerFee =
|
||||
(getIssuer.i_issuer_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
channelFee =
|
||||
(getIssuer.i_channel_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
// ======================= KHUSUS LRT JABODEBEK =============================
|
||||
if (getPartner.partner_code == 'P05') {
|
||||
issuerFee = getIssuer.i_issuer_fee_nominal;
|
||||
channelFee = getIssuer.i_channel_fee_nominal;
|
||||
} else {
|
||||
// SELAIN LRT JABODEBEK
|
||||
issuerFee =
|
||||
(getIssuer.i_issuer_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
channelFee =
|
||||
(getIssuer.i_channel_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2298,16 +2324,22 @@ const reservationV2 = async (req, res) => {
|
||||
let getIssuer = await model.getIssuer(getPartner.i_partner, now);
|
||||
|
||||
if (getIssuer) {
|
||||
// ======================= KHUSUS LRT JABODEBEK =============================
|
||||
if (getPartner.partner_code == 'P05') {
|
||||
// per tanggal 1 November 2023 fee sharing mulai menggunakan amount nominal dan bukan persentase lagi
|
||||
if (today >= '2023-11-01') {
|
||||
issuerFee = getIssuer.i_issuer_fee_nominal;
|
||||
channelFee = getIssuer.i_channel_fee_nominal;
|
||||
} else {
|
||||
// SELAIN LRT JABODEBEK
|
||||
issuerFee =
|
||||
(getIssuer.i_issuer_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
channelFee =
|
||||
(getIssuer.i_channel_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
// ======================= KHUSUS LRT JABODEBEK =============================
|
||||
if (getPartner.partner_code == 'P05') {
|
||||
issuerFee = getIssuer.i_issuer_fee_nominal;
|
||||
channelFee = getIssuer.i_channel_fee_nominal;
|
||||
} else {
|
||||
// SELAIN LRT JABODEBEK
|
||||
issuerFee =
|
||||
(getIssuer.i_issuer_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
channelFee =
|
||||
(getIssuer.i_channel_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4218,6 +4250,8 @@ const getFeeSharing = async (req, res) => {
|
||||
// datetime
|
||||
if (!datetime) {
|
||||
datetime = moment().format('YYYY-MM-DD');
|
||||
} else {
|
||||
datetime = moment(datetime).format('YYYY-MM-DD');
|
||||
}
|
||||
|
||||
// log debug
|
||||
@@ -4253,16 +4287,22 @@ const getFeeSharing = async (req, res) => {
|
||||
let getIssuer = await model.getIssuer(getPartner.i_partner, datetime);
|
||||
|
||||
if (getIssuer) {
|
||||
// ======================= KHUSUS LRT JABODEBEK =============================
|
||||
if (getPartner.partner_code == 'P05') {
|
||||
// per tanggal 1 November 2023 fee sharing mulai menggunakan amount nominal dan bukan persentase lagi
|
||||
if (datetime >= '2023-11-01') {
|
||||
issuerFee = getIssuer.i_issuer_fee_nominal;
|
||||
channelFee = getIssuer.i_channel_fee_nominal;
|
||||
} else {
|
||||
// SELAIN LRT JABODEBEK
|
||||
issuerFee =
|
||||
(getIssuer.i_issuer_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
channelFee =
|
||||
(getIssuer.i_channel_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
// ======================= KHUSUS LRT JABODEBEK =============================
|
||||
if (getPartner.partner_code == 'P05') {
|
||||
issuerFee = getIssuer.i_issuer_fee_nominal;
|
||||
channelFee = getIssuer.i_channel_fee_nominal;
|
||||
} else {
|
||||
// SELAIN LRT JABODEBEK
|
||||
issuerFee =
|
||||
(getIssuer.i_issuer_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
channelFee =
|
||||
(getIssuer.i_channel_fee_perc / 100) * parseInt(getIssuer.i_amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,22 @@
|
||||
# ================================= ENVIRONMENT =================================
|
||||
#NODE_ENV=production
|
||||
NODE_ENV=development
|
||||
CUSTOM_MODE_NODE_ENV=devprod
|
||||
#NODE_ENV=testing
|
||||
PORT=3000
|
||||
VERSION=v1.4.6
|
||||
|
||||
# ===================== CLUSTER NODE (YES or NO) ===========================
|
||||
CLUSTER_NODE=NO
|
||||
|
||||
# ===================== CLUSTER WITH RUNNING ON MULTIPLE PORT (YES or NO) ===========================
|
||||
RUNNING_ON_MULTIPLE_PORT=NO
|
||||
|
||||
# PISAHKAN DENGAN MENGGUNAKAN SEPARATOR KOMA TANPA SPASI
|
||||
PORTS=3001,3002,3003,3004
|
||||
|
||||
# ===================== CLUSTER NODE STICKY SESSION(YES or NO) ===========================
|
||||
CLUSTER_NODE_STICKY_SESSION=YES
|
||||
|
||||
# =========================== KONFIGURASI UNTUK SERVER ===========================
|
||||
# SERVER_FOR=development
|
||||
@@ -29,9 +43,9 @@ DB_USER_POOLING=postgres
|
||||
DB_PASSWORD_POOLING=inhc0mmute_cms
|
||||
|
||||
# ==================================== LOKI =====================================
|
||||
LOKI_URL=http://10.20.14.30:3100
|
||||
LOKI_URL=http://localhost:3100
|
||||
|
||||
# ==================================== APP PROMETHEUS =====================================
|
||||
# =============================== APP PROMETHEUS =================================
|
||||
PROM_APP = topuponline
|
||||
|
||||
# ================================== SECRET KEY ==================================
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
require('dotenv').config();
|
||||
// var http = require('http');
|
||||
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');
|
||||
const app = require('./server');
|
||||
const sticky = require('sticky-session');
|
||||
|
||||
// set port, listen for requests
|
||||
const PORT = process.env.PORT || 3000;
|
||||
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}`;
|
||||
@@ -29,32 +29,122 @@ if (process.env.CHANGE_TO_DRC == 'YES' || process.env.CHANGE_TO_DRC == 'yes') {
|
||||
}
|
||||
}
|
||||
|
||||
// if (cluster.isMaster) {
|
||||
// console.log(`Number of CPUs is ${totalCPUs}`);
|
||||
// console.log(`Master ${process.pid} is running`);
|
||||
// jika mau di cluster gunakan script berikut:
|
||||
if (process.env.CLUSTER_NODE.toUpperCase() == 'YES') {
|
||||
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();
|
||||
// }
|
||||
// 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();
|
||||
// }
|
||||
cluster.on('exit', (worker, code, signal) => {
|
||||
console.log(`worker ${worker.process.pid} died`);
|
||||
console.log("Let's fork another worker!");
|
||||
console.log('with code: ' + code);
|
||||
cluster.fork();
|
||||
});
|
||||
|
||||
// console.log(`worker pid=${process.pid}`);
|
||||
// console.log(`worker pid=${process.pid}`);
|
||||
} else {
|
||||
startExpress();
|
||||
}
|
||||
} else {
|
||||
// jika tidak mau di cluster langsung call function startExpress
|
||||
startExpress();
|
||||
}
|
||||
|
||||
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} `
|
||||
// set port, listen for requests
|
||||
const PORT = process.env.PORT || 3000;
|
||||
|
||||
// jika settingan running on multiple
|
||||
if (
|
||||
process.env.RUNNING_ON_MULTIPLE_PORT.toUpperCase() == 'YES' &&
|
||||
process.env.CLUSTER_NODE.toUpperCase() == 'NO'
|
||||
) {
|
||||
const PORTS = process.env.PORTS;
|
||||
|
||||
if (!PORTS) {
|
||||
winston.logger.warn(
|
||||
`Running on multiple port is active but the ports not yet set in .env`
|
||||
);
|
||||
} else {
|
||||
let ports = PORTS.split(',');
|
||||
|
||||
for (let index = 0; index < ports.length; index++) {
|
||||
const port = ports[index];
|
||||
|
||||
app.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} `
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if (
|
||||
process.env.RUNNING_ON_MULTIPLE_PORT.toUpperCase() == 'YES' &&
|
||||
process.env.CLUSTER_NODE.toUpperCase() == 'YES'
|
||||
) {
|
||||
winston.logger.warn(
|
||||
`If you want running the service on multiple port, please set CLUSTER_NODE = NO in .env file `
|
||||
);
|
||||
});
|
||||
} else if (
|
||||
process.env.CLUSTER_NODE_STICKY_SESSION.toUpperCase() == 'YES' &&
|
||||
process.env.CLUSTER_NODE.toUpperCase() == 'YES'
|
||||
) {
|
||||
winston.logger.warn(
|
||||
`If you want running the service with sticky session, please set CLUSTER_NODE = NO in .env file `
|
||||
);
|
||||
}
|
||||
|
||||
let message = `Server is running on version ${
|
||||
process.env.VERSION
|
||||
} environment: ${process.env.NODE_ENV.toUpperCase()} port: ${PORT} on ${serverActive}. HSM STATUS : ${serverHSMStatus} `;
|
||||
|
||||
if (process.env.CLUSTER_NODE.toUpperCase() == 'YES') {
|
||||
message = `Server is running with cluster node on version ${
|
||||
process.env.VERSION
|
||||
} environment: ${process.env.NODE_ENV.toUpperCase()} port: ${PORT} on ${serverActive}. HSM STATUS : ${serverHSMStatus} `;
|
||||
} else if (process.env.CLUSTER_NODE_STICKY_SESSION.toUpperCase() == 'YES') {
|
||||
message = `Server is running with sticky session on version ${
|
||||
process.env.VERSION
|
||||
} environment: ${process.env.NODE_ENV.toUpperCase()} port: ${PORT} on ${serverActive}. HSM STATUS : ${serverHSMStatus} `;
|
||||
}
|
||||
|
||||
if (process.env.CLUSTER_NODE_STICKY_SESSION.toUpperCase() == 'YES') {
|
||||
const server = app.listen(PORT, () => {
|
||||
console.log(
|
||||
`Worker ${process.pid} started. Listening on port ${
|
||||
server.address().port
|
||||
}`
|
||||
);
|
||||
winston.logger.info(message);
|
||||
});
|
||||
|
||||
// Use sticky-session with the server instance
|
||||
sticky.listen(server);
|
||||
} else {
|
||||
app.listen(PORT, () => {
|
||||
winston.logger.info(message);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Use sticky-session to handle sticky sessions
|
||||
// if (!sticky.listen(cluster, port)) {
|
||||
// // This is the master process, and it should not be listening to the port
|
||||
// cluster.on('listening', (worker, address) => {
|
||||
// console.log(
|
||||
// `Worker ${worker.id} is now connected to ${address.address}:${address.port}`
|
||||
// );
|
||||
// });
|
||||
|
||||
// cluster.on('exit', (worker) => {
|
||||
// console.log(`Worker ${worker.id} has exited`);
|
||||
// });
|
||||
// }
|
||||
|
||||
Generated
+22
@@ -28,6 +28,7 @@
|
||||
"prom-client": "^14.2.0",
|
||||
"redis": "^4.6.5",
|
||||
"response-time": "^2.3.2",
|
||||
"sticky-session": "^1.1.2",
|
||||
"winston": "^3.7.2",
|
||||
"winston-daily-rotate-file": "^4.7.1",
|
||||
"winston-loki": "^6.0.6",
|
||||
@@ -8301,6 +8302,18 @@
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/sticky-session": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/sticky-session/-/sticky-session-1.1.2.tgz",
|
||||
"integrity": "sha512-1PPeJYu5SqjYcBNp93On4cQJuN7q+M+RbVjmYW1KSCKSv/rN1cVVyBBB0kCexsg0qJpQXgfHOt6bCneJTYRafQ==",
|
||||
"dependencies": {
|
||||
"debug": "^2.2.0",
|
||||
"ip": "^1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.12.0"
|
||||
}
|
||||
},
|
||||
"node_modules/string_decoder": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
|
||||
@@ -15338,6 +15351,15 @@
|
||||
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz",
|
||||
"integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ=="
|
||||
},
|
||||
"sticky-session": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/sticky-session/-/sticky-session-1.1.2.tgz",
|
||||
"integrity": "sha512-1PPeJYu5SqjYcBNp93On4cQJuN7q+M+RbVjmYW1KSCKSv/rN1cVVyBBB0kCexsg0qJpQXgfHOt6bCneJTYRafQ==",
|
||||
"requires": {
|
||||
"debug": "^2.2.0",
|
||||
"ip": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"string_decoder": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
"prom-client": "^14.2.0",
|
||||
"redis": "^4.6.5",
|
||||
"response-time": "^2.3.2",
|
||||
"sticky-session": "^1.1.2",
|
||||
"winston": "^3.7.2",
|
||||
"winston-daily-rotate-file": "^4.7.1",
|
||||
"winston-loki": "^6.0.6",
|
||||
|
||||
Reference in New Issue
Block a user