mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-05 17:26:28 +00:00
Compare commits
232 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f5574250d7 | |||
| 3a85e63c01 | |||
| 301696661d | |||
| 9fa469fc67 | |||
| 02fa5cb909 | |||
| 3dfd2a50d4 | |||
| d51325cd81 | |||
| 99ebab8591 | |||
| 92b72dbe7a | |||
| d2e1ff2274 | |||
| 5c67284a51 | |||
| b4d700e27d | |||
| d18b91edda | |||
| 3b97844c64 | |||
| 1ce4424494 | |||
| 6c5e472c4b | |||
| 57d7f260d0 | |||
| 2834265206 | |||
| 40ddf02c51 | |||
| ba20dce4d1 | |||
| aec06cb481 | |||
| 7434464106 | |||
| 01d95ae783 | |||
| d690cb2c0b | |||
| 88f82281dc | |||
| 2e5d76d97d | |||
| fc9c1a4b73 | |||
| 7d4ff6c8b3 | |||
| 8bda43d2b2 | |||
| 36139073d4 | |||
| 3c8fc4d81d | |||
| 22ce0b611a | |||
| 785e1f2542 | |||
| a6c6146933 | |||
| 0113e6dbb1 | |||
| 8d2f4bcda2 | |||
| 9aa3428620 | |||
| e8c73abf2e | |||
| 6275d8cf86 | |||
| 8af96b9a5f | |||
| d9f3516d56 | |||
| b7dec2613f | |||
| d540308d2d | |||
| 9708f81242 | |||
| 35c9fe205c | |||
| b206b50968 | |||
| 007690bcc8 | |||
| 3248d76cd6 | |||
| 1c72e98b81 | |||
| 490bc5f68a | |||
| 2480dc6ba9 | |||
| 733a39b22b | |||
| c6dffc09d9 | |||
| f4dbacd8b4 | |||
| 9dacea3399 | |||
| fdd303cb9e | |||
| 1891b551fa | |||
| 543d733820 | |||
| 9478cd4a31 | |||
| 0d2bd65350 | |||
| 8eaf79bfd1 | |||
| 9d5a0153f9 | |||
| 817832d925 | |||
| 63f4407804 | |||
| 9e876fee67 | |||
| a953df2f0f | |||
| 3e5d29e8d5 | |||
| 9cf4a717a6 | |||
| c8682214e4 | |||
| 9c8a553c30 | |||
| 388e2fc22c | |||
| f7828bccaa | |||
| adee7c1522 | |||
| 807f7f0f2e | |||
| 79e82f4581 | |||
| 503b683c16 | |||
| 944cd372a9 | |||
| 950a93ed0f | |||
| d53439f948 | |||
| a32d834a62 | |||
| 43d839ddbf | |||
| fccb28c608 | |||
| f72153d463 | |||
| 899569221c | |||
| 893a243c80 | |||
| 9e5c6ba41d | |||
| 4bd4230627 | |||
| 2e8e2586e2 | |||
| 503ecdfd6e | |||
| 79d4269b70 | |||
| 603a74a5b7 | |||
| c9a08d6832 | |||
| 308fef3ecd | |||
| 31d007dd67 | |||
| 6fe3ecc89f | |||
| b6b043b0a2 | |||
| bbdb4c2963 | |||
| 33f3b64d17 | |||
| 5ff0cae4d6 | |||
| c80b12ba53 | |||
| e3673f738c | |||
| f7d7d0efce | |||
| 30c32ca293 | |||
| 4d47090994 | |||
| 3fefaed395 | |||
| b1be54d5ba | |||
| 536d1a5c94 | |||
| 5d8369edd8 | |||
| 3c26dd6e23 | |||
| 0baf1332b6 | |||
| 5aca4559c2 | |||
| 21a45058f0 | |||
| edc70c3e6b | |||
| 4bb2facddb | |||
| 466c18fe21 | |||
| ed11c6ccc4 | |||
| 3515b5459f | |||
| e4cf444b83 | |||
| ddf01d2246 | |||
| 1fb0913eb5 | |||
| 293602bed2 | |||
| 87461a4a14 | |||
| fbcae2e596 | |||
| c7f816a449 | |||
| eeab7627ae | |||
| 9052668cbc | |||
| f615e9207f | |||
| 1ba983e745 | |||
| 8f254758dd | |||
| e7c4388956 | |||
| 3d31e6f6a5 | |||
| 1b3991c82f | |||
| 38edd07d65 | |||
| fff4915078 | |||
| 820f833844 | |||
| 1bd85ba888 | |||
| cab77e8872 | |||
| 7b52cebeb7 | |||
| 4c3496e9f2 | |||
| 529d6d7ffc | |||
| 5ca30fbfc4 | |||
| d3729ab906 | |||
| 95bfc120c5 | |||
| 9e98533ffb | |||
| 0ab80c0ac4 | |||
| ef274a483c | |||
| d129ad7a2f | |||
| 1f127807d3 | |||
| e30c78beb7 | |||
| 1014e4374a | |||
| 1d2e92b85f | |||
| 88c3b9bc4a | |||
| 51cb6c1212 | |||
| ffa6830734 | |||
| 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 | |||
| 5a63ca6ea1 | |||
| 5d7852eff9 | |||
| 009e6caead | |||
| e61392d81a | |||
| 8c0b6f7e7c | |||
| cee0352271 | |||
| dfce874ce9 | |||
| b942d114ad | |||
| 7c66ebe702 | |||
| 84de02de26 | |||
| 46e3cd689b | |||
| 6b0d67ee60 | |||
| 7805bc902b | |||
| 95f4a03e81 | |||
| 4c7230ba6b | |||
| 1b2eff69b4 | |||
| e3ab361b24 | |||
| 14026e8bf0 | |||
| 3c1fc92d59 | |||
| a333ddb58f | |||
| f2c5d65ec0 | |||
| bcb9225466 | |||
| 90dfdc8857 | |||
| 476235440c | |||
| 04885f22d6 | |||
| 3b68ab9ab3 | |||
| 31b581c85e | |||
| a3a4772f77 | |||
| 50008e2006 | |||
| 6ef43923e1 | |||
| c30cdcf4ed | |||
| e77a975ccc | |||
| 728a9a92c9 | |||
| 47af9992be | |||
| ede3aacef3 | |||
| a6b17139bf | |||
| 7a7f18701d | |||
| 24006105b9 | |||
| e34434f96c | |||
| c2e95ee6a5 | |||
| da1912d05d | |||
| 9cbc467904 | |||
| 0a5e82dbbb | |||
| 7171d1e3f5 | |||
| 6c7131c944 | |||
| 05098fa3ac | |||
| 131cac392b | |||
| cd3c29bee0 | |||
| 8436ea2071 | |||
| 032e12d9d0 | |||
| 5e91b9a147 | |||
| 9b8865233b | |||
| 3645bb2420 |
+16
-16
@@ -1,8 +1,8 @@
|
||||
const moment = require("moment");
|
||||
const winston = require("winston");
|
||||
const loki = require("winston-loki");
|
||||
require("winston-daily-rotate-file");
|
||||
require("dotenv").config();
|
||||
const moment = require('moment');
|
||||
const winston = require('winston');
|
||||
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;
|
||||
|
||||
@@ -18,32 +18,32 @@ var log;
|
||||
|
||||
const fileRotateTransport = new winston.transports.DailyRotateFile({
|
||||
filename: `./lokiLog/%DATE%-onlinetopup.log`,
|
||||
datePattern: "YYYY-MM-DD",
|
||||
maxFiles: "1d",
|
||||
datePattern: 'YYYY-MM-DD',
|
||||
maxFiles: '1d',
|
||||
});
|
||||
|
||||
if (
|
||||
process.env.NODE_ENV == "production" ||
|
||||
process.env.NODE_ENV == "PRODUCTION"
|
||||
process.env.NODE_ENV == 'production' ||
|
||||
process.env.NODE_ENV == 'PRODUCTION'
|
||||
) {
|
||||
log = winston.createLogger({
|
||||
levels: logLevels,
|
||||
level: process.env.LOG_LEVEL || "info",
|
||||
level: process.env.LOG_LEVEL || 'info',
|
||||
exitOnError: false,
|
||||
// format: combine(timestamp(), json()),
|
||||
format: combine(
|
||||
// colorize({ all: true }),
|
||||
timestamp({
|
||||
format: "YYYY-MM-DD HH:mm:ss.SSS",
|
||||
format: 'YYYY-MM-DD HH:mm:ss.SSS',
|
||||
}),
|
||||
align(),
|
||||
printf((info) => `[${info.timestamp}] ${info.level}: ${info.message}`)
|
||||
),
|
||||
defaultMeta: { service: "topuponline" },
|
||||
defaultMeta: { service: 'topuponline' },
|
||||
transports: [
|
||||
new loki({
|
||||
host: lokiUrl,
|
||||
labels: { app: "topuponline" },
|
||||
labels: { app: 'topuponline' },
|
||||
json: true,
|
||||
format: json(),
|
||||
replaceTimestamp: true,
|
||||
@@ -59,7 +59,7 @@ if (
|
||||
transports: [
|
||||
new loki({
|
||||
host: lokiUrl,
|
||||
labels: { app: "topuponline" },
|
||||
labels: { app: 'topuponline' },
|
||||
handleExceptions: true,
|
||||
handleRejections: true,
|
||||
clearOnError: true,
|
||||
@@ -75,14 +75,14 @@ if (
|
||||
});
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV != "testing" && process.env.NODE_ENV != "TESTING") {
|
||||
if (process.env.NODE_ENV != 'testing' && process.env.NODE_ENV != 'TESTING') {
|
||||
log.add(
|
||||
new winston.transports.Console({
|
||||
// format: winston.format.cli(),
|
||||
format: combine(
|
||||
colorize({ all: true }),
|
||||
timestamp({
|
||||
format: "YYYY-MM-DD HH:mm:ss.SSS",
|
||||
format: 'YYYY-MM-DD HH:mm:ss.SSS',
|
||||
}),
|
||||
align(),
|
||||
printf((info) => `[${info.timestamp}] ${info.level}: ${info.message}`)
|
||||
|
||||
@@ -27,7 +27,13 @@ var logger;
|
||||
const fileRotateTransport = new winston.transports.DailyRotateFile({
|
||||
filename: `application/logs/%DATE%-onlinetopup.log`,
|
||||
datePattern: "YYYY-MM-DD",
|
||||
maxFiles: "90d",
|
||||
maxFiles: "60d",
|
||||
});
|
||||
|
||||
const fileRotateTransportDebug = new winston.transports.DailyRotateFile({
|
||||
filename: `application/logs/debug/%DATE%-onlinetopup.log`,
|
||||
datePattern: "YYYY-MM-DD",
|
||||
maxFiles: "30d",
|
||||
});
|
||||
//
|
||||
// If we're not in production then log to the `console` with the format:
|
||||
@@ -54,6 +60,7 @@ if (
|
||||
defaultMeta: { service: "topuponline-service" },
|
||||
transports: [
|
||||
fileRotateTransport,
|
||||
fileRotateTransportDebug,
|
||||
//
|
||||
// - Write all logs with importance level of `error` or less to `error.log`
|
||||
// - Write all logs with importance level of `info` or less to `onlinetopup.log`
|
||||
@@ -84,6 +91,7 @@ if (
|
||||
defaultMeta: { service: "topuponline-service" },
|
||||
transports: [
|
||||
fileRotateTransport,
|
||||
fileRotateTransportDebug,
|
||||
//
|
||||
// - Write all logs with importance level of `error` or less to `error.log`
|
||||
// - Write all logs with importance level of `info` or less to `onlinetopup.log`
|
||||
|
||||
@@ -1,49 +1,59 @@
|
||||
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.headers['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 +62,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: {},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -161,6 +161,47 @@ const getLoadBalanceNumberSequence = async (req, res, next) => {
|
||||
}
|
||||
next();
|
||||
};
|
||||
const getLoadBalanceNumberSequence2 = async (req) => {
|
||||
// set default load_balance_number_sequence dari partner apapun is null
|
||||
let load_balance_number_sequence = null;
|
||||
|
||||
// cek jika redis is connect
|
||||
let isRedisReady = await redisClient.isReady;
|
||||
// jika tidak connect
|
||||
if (isRedisReady) {
|
||||
// jika connect maka cari sequence dari reservation number sesuai partner yg merequest
|
||||
// format value nya harusnya seperti ini = { date: '2023-01-01', sequence: 1 }
|
||||
// data req.partner_id_token di dapat dari authenticateToken di jwt middleware
|
||||
let getValue = await redisClient.GET(
|
||||
'load_balance_number_sequence_' + req.partner_id_token
|
||||
);
|
||||
|
||||
if (getValue) {
|
||||
// parsing data menjadi json format
|
||||
let parsedValue = JSON.parse(getValue);
|
||||
|
||||
// cek apakah tanggal sequence yang di redis sama dengan hari ini atau bukan
|
||||
if (parsedValue.date == moment().format('YYYY-MM-DD')) {
|
||||
// jika tanggal nya sama dengan hari ini maka ambil sequence untuk reservation number yang di generate dari redis
|
||||
load_balance_number_sequence = parseInt(parsedValue.sequence);
|
||||
|
||||
// langsung update sequence walaupun transaksi insert nya belum selesai
|
||||
// impact menggunakan redis, untuk nomor sequence bisa saja ada yg loncat karena bisa saja ada transaksi insert reservation yang gagal
|
||||
let setValue = {
|
||||
date: moment().format('YYYY-MM-DD'),
|
||||
sequence: parseInt(parsedValue.sequence) + 1,
|
||||
};
|
||||
|
||||
await redisClient.SET(
|
||||
`load_balance_number_sequence_${req.partner_id_token}`,
|
||||
JSON.stringify(setValue)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return load_balance_number_sequence;
|
||||
// next();
|
||||
};
|
||||
|
||||
const setLoadBalanceNumberSequence = async (partner_id, sequence) => {
|
||||
// cek jika redis is connect
|
||||
@@ -188,4 +229,5 @@ module.exports = {
|
||||
setReservationNumberSequence,
|
||||
getLoadBalanceNumberSequence,
|
||||
setLoadBalanceNumberSequence,
|
||||
getLoadBalanceNumberSequence2,
|
||||
};
|
||||
|
||||
@@ -75,10 +75,14 @@ const loginPartnerUser = async (req, res, next) => {
|
||||
let { email, password } = req.body;
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ REQUEST LOGIN-PARTNER-USER ]: ${JSON.stringify({
|
||||
email: email,
|
||||
})}`
|
||||
// winston.logger.info(
|
||||
// `${uniqueCode} [ REQUEST LOGIN-PARTNER-USER ]: ${JSON.stringify({
|
||||
// email: email,
|
||||
// })}`
|
||||
// );
|
||||
|
||||
console.log(
|
||||
`${uniqueCode} [ REQUEST LOGIN-PARTNER-USER ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
// validate
|
||||
@@ -201,9 +205,9 @@ const loginPartnerUser = async (req, res, next) => {
|
||||
};
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ RESPONSE LOGIN-PARTNER-USER ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
// winston.logger.info(
|
||||
// `${uniqueCode} [ RESPONSE LOGIN-PARTNER-USER ]: ${JSON.stringify(result)}`
|
||||
// );
|
||||
|
||||
return res.status(200).json(result);
|
||||
} catch (error) {
|
||||
@@ -556,7 +560,7 @@ const refreshTokenTerminal = async (req, res) => {
|
||||
let result = {};
|
||||
|
||||
let { mid, tid } = req.body;
|
||||
let refresh_token = req.header('refresh_token');
|
||||
let refresh_token = req.headers['refresh-token'];
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
@@ -702,14 +706,14 @@ const refreshTokenPartnerUser = async (req, res) => {
|
||||
let result = {};
|
||||
|
||||
let { email } = req.body;
|
||||
let refresh_token = req.header('refresh_token');
|
||||
let refresh_token = req.headers['refresh-token'];
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ REQUEST REFRESH-TOKEN-PARTNER-USER ]: ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
// winston.logger.info(
|
||||
// `${uniqueCode} [ REQUEST REFRESH-TOKEN-PARTNER-USER ]: ${JSON.stringify(
|
||||
// req.body
|
||||
// )}`
|
||||
// );
|
||||
|
||||
// validate
|
||||
let err = validationResult(req);
|
||||
@@ -837,11 +841,11 @@ const refreshTokenPartnerUser = async (req, res) => {
|
||||
};
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ RESPONSE REFRESH-TOKEN-PARTNER-USER ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
// winston.logger.info(
|
||||
// `${uniqueCode} [ RESPONSE REFRESH-TOKEN-PARTNER-USER ]: ${JSON.stringify(
|
||||
// result
|
||||
// )}`
|
||||
// );
|
||||
|
||||
return res.status(200).json(result);
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
const { param, body, validationResult } = require("express-validator");
|
||||
const helper = require("../../helpers/helper");
|
||||
const winston = require("../../helpers/winston.logger");
|
||||
const model = require("./cahsin.model");
|
||||
const moment = require("moment");
|
||||
const knex = require("../../../infrastructure/database/knex");
|
||||
const { param, body, validationResult } = require('express-validator');
|
||||
const helper = require('../../helpers/helper');
|
||||
const winston = require('../../helpers/winston.logger');
|
||||
const model = require('./cahsin.model');
|
||||
const moment = require('moment');
|
||||
const knex = require('../../../infrastructure/database/knex');
|
||||
|
||||
moment.locale("id");
|
||||
moment.locale('id');
|
||||
|
||||
var result = {};
|
||||
var uniqueCode;
|
||||
@@ -13,14 +13,32 @@ var uniqueCode;
|
||||
// VALIDATION
|
||||
const validate = (method) => {
|
||||
switch (method) {
|
||||
case "generateInvoice":
|
||||
case 'generateInvoice':
|
||||
return [
|
||||
body('trx_date').notEmpty().withMessage('trx_date is required!').isISO8601().withMessage('invalid trx_date format YYYY-MM-DD !').escape().trim(),
|
||||
body('repost').notEmpty().withMessage('repost is required!').isBoolean().withMessage('repost must boolean!').escape().trim(),
|
||||
body('trx_date')
|
||||
.notEmpty()
|
||||
.withMessage('trx_date is required!')
|
||||
.isISO8601()
|
||||
.withMessage('invalid trx_date format YYYY-MM-DD !')
|
||||
.escape()
|
||||
.trim(),
|
||||
body('repost')
|
||||
.notEmpty()
|
||||
.withMessage('repost is required!')
|
||||
.isBoolean()
|
||||
.withMessage('repost must boolean!')
|
||||
.escape()
|
||||
.trim(),
|
||||
];
|
||||
case "postingInvoice":
|
||||
case 'postingInvoice':
|
||||
return [
|
||||
body('trx_date').notEmpty().withMessage('trx_date is required!').isISO8601().withMessage('invalid trx_date format YYYY-MM-DD !').escape().trim(),
|
||||
body('trx_date')
|
||||
.notEmpty()
|
||||
.withMessage('trx_date is required!')
|
||||
.isISO8601()
|
||||
.withMessage('invalid trx_date format YYYY-MM-DD !')
|
||||
.escape()
|
||||
.trim(),
|
||||
];
|
||||
default:
|
||||
break;
|
||||
@@ -29,7 +47,6 @@ const validate = (method) => {
|
||||
|
||||
// POSTING INVOICE
|
||||
const apiGenerateCahsIn = async (req, res) => {
|
||||
|
||||
try {
|
||||
// generate unique code
|
||||
uniqueCode = helper.getUniqueCode();
|
||||
@@ -44,7 +61,7 @@ const apiGenerateCahsIn = async (req, res) => {
|
||||
const err = validationResult(req, res);
|
||||
if (!err.isEmpty()) {
|
||||
result = {
|
||||
code: "400",
|
||||
code: '400',
|
||||
message: err.errors[0].msg,
|
||||
data: {},
|
||||
};
|
||||
@@ -57,40 +74,92 @@ const apiGenerateCahsIn = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
const cashIn = await _generateCashIn(uniqueCode)
|
||||
const cashIn = await _generateCashIn(uniqueCode);
|
||||
|
||||
result = {
|
||||
code: "200",
|
||||
message: "Succes posting",
|
||||
data: cashIn
|
||||
code: '200',
|
||||
message: 'Succes posting',
|
||||
data: cashIn,
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`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: {},
|
||||
});
|
||||
}
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`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: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const apiGenerateCashInSales = async (req, res) => {
|
||||
try {
|
||||
// generate unique code
|
||||
uniqueCode = helper.getUniqueCode();
|
||||
// return uniqueCode
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} REQUEST generate cashin: ${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 generate cashin: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
const cashIn = await _generateCashInSales(uniqueCode);
|
||||
|
||||
result = {
|
||||
code: '200',
|
||||
message: 'Success generate cash-in',
|
||||
data: cashIn,
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`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: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// RETRY POSTING INVOICE
|
||||
const apiPostingCahsIn = async (req, res) => {
|
||||
try {
|
||||
// generate unique code
|
||||
uniqueCode = helper.getUniqueCode()
|
||||
let { body } = req
|
||||
uniqueCode = helper.getUniqueCode();
|
||||
let { body } = req;
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} REQUEST posting cash in : ${JSON.stringify(req.body)}`
|
||||
@@ -100,184 +169,418 @@ const apiPostingCahsIn = async (req, res) => {
|
||||
const err = validationResult(req, res);
|
||||
if (!err.isEmpty()) {
|
||||
result = {
|
||||
code: "400",
|
||||
code: '400',
|
||||
message: err.errors[0].msg,
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE generate posting cash in : ${JSON.stringify(result)}`
|
||||
`${uniqueCode} RESPONSE generate posting cash in : ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// return uniqueCode
|
||||
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} RE-TRY POSTING CAHS IN`)
|
||||
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} RE-TRY POSTING CAHS IN`);
|
||||
|
||||
const invoice = await _postingCashIn(uniqueCode)
|
||||
const invoice = await _postingCashIn(uniqueCode);
|
||||
|
||||
result = {
|
||||
code: "200",
|
||||
message: "Succes",
|
||||
code: '200',
|
||||
message: 'Succes',
|
||||
data: invoice,
|
||||
}
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`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: {},
|
||||
});
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`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: {},
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const _generateCashIn = async (uniqueCode) => {
|
||||
|
||||
let partnerRecon = await model.getPartnerRecon(knex)
|
||||
let partnerRecon = await model.getPartnerRecon(knex);
|
||||
// return partnerRecon
|
||||
winston.logger.info(`SCHEDULER-FB70-${uniqueCode} getPartner Recon cash in : ${JSON.stringify(partnerRecon)}`)
|
||||
winston.logger.info(
|
||||
`SCHEDULER-FB70-${uniqueCode} getPartner Recon cash in : ${JSON.stringify(
|
||||
partnerRecon
|
||||
)}`
|
||||
);
|
||||
|
||||
for (const item of partnerRecon) {
|
||||
let reserve = []
|
||||
let code = ""
|
||||
await knex.transaction(async trx => {
|
||||
code = await model.generateCode(trx, item.c_partner_code, moment().format("YYMMDD"))
|
||||
winston.logger.info(`SCHEDULER-FB70-${uniqueCode} generate cash in : ${code}`)
|
||||
|
||||
// Insert cahs in
|
||||
const dataCahsIn = {
|
||||
c_partner_code : item.c_partner_code,
|
||||
c_partner_name : item.c_partner_name,
|
||||
c_cash_in_no : code,
|
||||
c_in_period : item.c_in_period,
|
||||
d_credit : item.d_payment,
|
||||
c_invoice_no : item.c_invoice_no,
|
||||
i_amount : item.amount
|
||||
}
|
||||
|
||||
winston.logger.info(`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN ${code} DATA : ${JSON.stringify(dataCahsIn)}`)
|
||||
const cashIn = await model.insertCashIn(trx, dataCahsIn)
|
||||
let reserve = [];
|
||||
let code = '';
|
||||
await knex.transaction(async (trx) => {
|
||||
try {
|
||||
code = await model.generateCode(
|
||||
trx,
|
||||
item.c_partner_code,
|
||||
moment().format('YYMMDD')
|
||||
);
|
||||
winston.logger.info(
|
||||
`SCHEDULER-FB70-${uniqueCode} generate cash in : ${code}`
|
||||
);
|
||||
|
||||
winston.logger.info(`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN HISTORY ${code} DATA : ${JSON.stringify(dataCahsIn)}`)
|
||||
const paymentyHistory = await model.writePaynentHistory(dataCahsIn, "SUCCESSFULLY", 0, trx)
|
||||
// Cash-in
|
||||
let dataCahsIn = {
|
||||
c_partner_code: item.c_partner_code,
|
||||
c_partner_name: item.c_partner_name,
|
||||
c_cash_in_no: code,
|
||||
c_in_period: item.c_in_period,
|
||||
d_credit: item.d_payment,
|
||||
c_invoice_no: item.c_invoice_no,
|
||||
i_amount: item.amount,
|
||||
};
|
||||
|
||||
// Insert cahs in detail
|
||||
let data = []
|
||||
const reserv = await model.getReserve(trx, item.c_partner_code, item.d_payment, item.c_invoice_no)
|
||||
for (const detail of reserv) {
|
||||
data.push({
|
||||
i_cash_in : cashIn.i_cash_in,
|
||||
c_reservation_no : detail.c_reservation_no,
|
||||
m_amount : detail.i_reservation_amount,
|
||||
c_payment_recon_no : detail.c_payment_recon_no,
|
||||
d_payment : detail.d_payment,
|
||||
d_payment_recon : detail.d_payment_recon,
|
||||
c_load_balance_no : detail.c_load_balance_no
|
||||
})
|
||||
winston.logger.info(
|
||||
`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN ${code} DATA : ${JSON.stringify(
|
||||
dataCahsIn
|
||||
)}`
|
||||
);
|
||||
|
||||
let reserveNo = detail.c_reservation_no
|
||||
// CASH-IN DETAIL
|
||||
let data = [];
|
||||
const reserv = await model.getReserve(
|
||||
trx,
|
||||
item.c_partner_code,
|
||||
item.d_payment,
|
||||
item.c_invoice_no
|
||||
);
|
||||
|
||||
let dataReserve = {
|
||||
c_cash_in_no : cashIn.c_cash_in_no,
|
||||
d_credit : cashIn.d_credit,
|
||||
c_in_period : cashIn.c_in_period,
|
||||
winston.logger.info(
|
||||
`SCHEDULER-FB70-${uniqueCode} cashIn reserv ${code} DATA : ${JSON.stringify(
|
||||
reserv
|
||||
)}`
|
||||
);
|
||||
|
||||
//TOTAL AMOUNT CASH-IN
|
||||
let cashInAmount = 0;
|
||||
for (const itemCI of reserv) {
|
||||
cashInAmount += parseInt(itemCI.i_reservation_amount);
|
||||
}
|
||||
dataCahsIn.i_amount = cashInAmount;
|
||||
|
||||
await model.updateIntoReserve(trx, dataReserve, reserveNo)
|
||||
|
||||
winston.logger.info(
|
||||
`SCHEDULER-FB70-${uniqueCode} cashInAmount ${code} DATA : ${JSON.stringify(
|
||||
cashInAmount
|
||||
)}`
|
||||
);
|
||||
|
||||
if(cashInAmount > 0) {
|
||||
//INSERT CASH-IN
|
||||
const cashIn = await model.insertCashIn(trx, dataCahsIn);
|
||||
winston.logger.info(
|
||||
`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN HISTORY ${code} DATA : ${JSON.stringify(
|
||||
dataCahsIn
|
||||
)}`
|
||||
);
|
||||
const paymentyHistory = await model.writePaynentHistory(
|
||||
dataCahsIn,
|
||||
'SUCCESSFULLY',
|
||||
0,
|
||||
trx
|
||||
);
|
||||
|
||||
let m_amount = 0;
|
||||
for (const detail of reserv) {
|
||||
// data.push({
|
||||
// i_cash_in: cashIn.i_cash_in,
|
||||
// c_reservation_no: detail.c_reservation_no,
|
||||
// m_amount: detail.i_reservation_amount,
|
||||
// c_payment_recon_no: detail.c_payment_recon_no,
|
||||
// d_payment: detail.d_payment,
|
||||
// d_payment_recon: detail.d_payment_recon,
|
||||
// c_load_balance_no: detail.c_load_balance_no,
|
||||
// });
|
||||
let temp = {
|
||||
i_cash_in: cashIn.i_cash_in,
|
||||
c_reservation_no: detail.c_reservation_no,
|
||||
m_amount: detail.i_reservation_amount,
|
||||
c_payment_recon_no: detail.c_payment_recon_no,
|
||||
d_payment: detail.d_payment,
|
||||
d_payment_recon: detail.d_payment_recon,
|
||||
c_load_balance_no: detail.c_load_balance_no,
|
||||
};
|
||||
|
||||
let reserveNo = detail.c_reservation_no;
|
||||
let dataReserve = {
|
||||
c_cash_in_no: cashIn.c_cash_in_no,
|
||||
d_credit: cashIn.d_credit,
|
||||
c_in_period: cashIn.c_in_period,
|
||||
};
|
||||
m_amount += parseInt(detail.i_reservation_amount);
|
||||
|
||||
if(m_amount <= detail.invoice_amount) {
|
||||
await model.updateIntoReserve(trx, dataReserve, reserveNo);
|
||||
winston.logger.info(
|
||||
`SCHEDULER-FB70-${uniqueCode} CASH-IN UPDATE RESERVE BALANCE ${reserveNo} DATA : ${JSON.stringify(
|
||||
dataReserve
|
||||
)}`
|
||||
);
|
||||
await model.insertCashInDetail(trx, temp);
|
||||
winston.logger.info(
|
||||
`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN DETAIL, ID CASH-IN ${cashIn.i_cash_in} : ${JSON.stringify(
|
||||
temp
|
||||
)}`
|
||||
);
|
||||
} else {
|
||||
await trx.rollback();
|
||||
winston.logger.info(
|
||||
`${uniqueCode} ROLLBACK CASH-IN: AMOUNT CASH-IN > TOTAL INVOICE. AMOUNT ${m_amount} > INVOICE AMOUNT (${detail.invoice_amount}) : ${JSON.stringify(
|
||||
dataCahsIn
|
||||
)}`
|
||||
);
|
||||
}
|
||||
}
|
||||
await wait(10000);
|
||||
winston.logger.info(
|
||||
`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN TO RESERVE ${code} DATA : ${JSON.stringify(
|
||||
dataCahsIn
|
||||
)}`
|
||||
);
|
||||
}
|
||||
await trx.commit();
|
||||
|
||||
} catch (error) {
|
||||
sts = "error";
|
||||
await trx.rollback();
|
||||
}
|
||||
await wait(5000)
|
||||
winston.logger.info(`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN TO RESERVE ${code} DATA : ${JSON.stringify(dataCahsIn)}`)
|
||||
await model.insertCashInDetail(trx, data)
|
||||
// await model.insertPostingEt(code, item, trx)
|
||||
|
||||
})
|
||||
|
||||
});
|
||||
}
|
||||
return partnerRecon;
|
||||
};
|
||||
|
||||
return partnerRecon
|
||||
const _generateCashInSales = async (uniqueCode) => {
|
||||
let partnerRecon = await model.getPartnerReconSales(knex);
|
||||
|
||||
}
|
||||
// return partnerRecon
|
||||
winston.logger.info(
|
||||
`SCHEDULER-FB70-${uniqueCode} getPartner Recon cash in : ${JSON.stringify(
|
||||
partnerRecon
|
||||
)}`
|
||||
);
|
||||
|
||||
for (const item of partnerRecon) {
|
||||
let reserve = [];
|
||||
let code = '';
|
||||
await knex.transaction(async (trx) => {
|
||||
try {
|
||||
code = await model.generateCode(
|
||||
trx,
|
||||
item.c_partner_code,
|
||||
moment().format('YYMMDD')
|
||||
);
|
||||
winston.logger.info(
|
||||
`SCHEDULER-FB70-${uniqueCode} generate cash in : ${code}`
|
||||
);
|
||||
|
||||
// Cash-in
|
||||
let dataCahsIn = {
|
||||
c_partner_code: item.c_partner_code,
|
||||
c_partner_name: item.c_partner_name,
|
||||
c_cash_in_no: code,
|
||||
c_in_period: item.c_in_period,
|
||||
d_credit: item.d_payment,
|
||||
c_invoice_no: item.c_invoice_no,
|
||||
i_amount: item.amount,
|
||||
c_source: 'S'
|
||||
};
|
||||
|
||||
winston.logger.info(
|
||||
`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN SALES ${code} DATA : ${JSON.stringify(
|
||||
dataCahsIn
|
||||
)}`
|
||||
);
|
||||
|
||||
// CASH-IN DETAIL
|
||||
const sales = await model.getSalesKMT(
|
||||
trx,
|
||||
item.c_partner_code,
|
||||
item.d_payment,
|
||||
item.c_invoice_no
|
||||
);
|
||||
|
||||
winston.logger.info(
|
||||
`SCHEDULER-FB70-${uniqueCode} DATA SALES ${code} : ${JSON.stringify( sales )}`
|
||||
);
|
||||
|
||||
//TOTAL AMOUNT CASH-IN
|
||||
let cashInAmount = 0;
|
||||
for (const itemCI of sales) {
|
||||
cashInAmount += parseInt(itemCI.i_total_billing);
|
||||
}
|
||||
dataCahsIn.i_amount = cashInAmount;
|
||||
|
||||
if(cashInAmount > 0) {
|
||||
//INSERT CASH-IN
|
||||
const cashIn = await model.insertCashIn(trx, dataCahsIn);
|
||||
winston.logger.info(
|
||||
`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN HISTORY ${code} DATA : ${JSON.stringify(
|
||||
dataCahsIn
|
||||
)}`
|
||||
);
|
||||
const paymentyHistory = await model.writePaynentHistory(
|
||||
dataCahsIn, 'SUCCESSFULLY', 0, trx
|
||||
);
|
||||
|
||||
let m_amount = 0;
|
||||
for (const detail of sales) {
|
||||
let temp = {
|
||||
i_cash_in: cashIn.i_cash_in,
|
||||
c_reservation_no: detail.c_sales_no,
|
||||
m_amount: detail.i_total_billing,
|
||||
c_payment_recon_no: detail.c_payment_recon_no,
|
||||
d_payment: detail.d_payment,
|
||||
d_payment_recon: detail.d_payment_recon,
|
||||
};
|
||||
|
||||
let salesNo = detail.c_sales_no;
|
||||
let dataSales = {
|
||||
c_cash_in_no: cashIn.c_cash_in_no,
|
||||
d_credit: cashIn.d_credit,
|
||||
c_in_period: cashIn.c_in_period,
|
||||
};
|
||||
m_amount += parseInt(detail.i_total_billing);
|
||||
|
||||
if(m_amount <= detail.invoice_amount) {
|
||||
await model.updateIntoSalesKMT(trx, dataSales, salesNo);
|
||||
winston.logger.info(
|
||||
`SCHEDULER-FB70-${uniqueCode} CASH-IN UPDATE SALES KMT MOBILE ${salesNo} DATA : ${JSON.stringify(
|
||||
dataSales
|
||||
)}`
|
||||
);
|
||||
await model.insertCashInDetail(trx, temp);
|
||||
winston.logger.info(
|
||||
`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN DETAIL, ID CASH-IN ${cashIn.i_cash_in} : ${JSON.stringify(
|
||||
temp
|
||||
)}`
|
||||
);
|
||||
} else {
|
||||
await trx.rollback();
|
||||
winston.logger.info(
|
||||
`${uniqueCode} ROLLBACK CASH-IN: AMOUNT CASH-IN > TOTAL INVOICE. AMOUNT ${m_amount} > INVOICE AMOUNT (${detail.invoice_amount}) : ${JSON.stringify(
|
||||
dataCahsIn
|
||||
)}`
|
||||
);
|
||||
}
|
||||
}
|
||||
await wait(10000);
|
||||
winston.logger.info();
|
||||
}
|
||||
await trx.commit();
|
||||
|
||||
} catch (error) {
|
||||
sts = "error";
|
||||
await trx.rollback();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
return partnerRecon;
|
||||
};
|
||||
|
||||
const _postingCashIn = async (uniqueCode) => {
|
||||
let data = []
|
||||
let postingEt = await model.getPostingEt(knex)
|
||||
let data = [];
|
||||
let postingEt = await model.getPostingEt(knex);
|
||||
|
||||
for (const item of postingEt) {
|
||||
await knex.transaction(async trx => {
|
||||
|
||||
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} GET POSTING ET : ${JSON.stringify(item)}`)
|
||||
|
||||
let xmlHeader = {
|
||||
doc_header_text : item.doc_header_text ? item.doc_header_text : "",
|
||||
ba: item.ba ? item.ba : "",
|
||||
doc_date : item.doc_date ? item.doc_date : "",
|
||||
posting_date : item.posting_date ? item.posting_date : "",
|
||||
fisc_year : item.fiscal_year ? item.fiscal_year : "",
|
||||
fisc_period : item.fis_period ? item.fis_period: "",
|
||||
doc_type: item.doc_type ? item.doc_type : "",
|
||||
c_invoice_no : item.reference ? item.reference : ""
|
||||
}
|
||||
await knex.transaction(async (trx) => {
|
||||
winston.logger.info(
|
||||
`SCHEDULER-RETRY-${uniqueCode} GET POSTING ET : ${JSON.stringify(item)}`
|
||||
);
|
||||
|
||||
let xmlItem = ['S', 'H'].map(key => {
|
||||
let xmlHeader = {
|
||||
doc_header_text: item.doc_header_text ? item.doc_header_text : '',
|
||||
ba: item.ba ? item.ba : '',
|
||||
doc_date: item.doc_date ? item.doc_date : '',
|
||||
posting_date: item.posting_date ? item.posting_date : '',
|
||||
fisc_year: item.fiscal_year ? item.fiscal_year : '',
|
||||
fisc_period: item.fis_period ? item.fis_period : '',
|
||||
doc_type: item.doc_type ? item.doc_type : '',
|
||||
c_invoice_no: item.reference ? item.reference : '',
|
||||
};
|
||||
|
||||
let xmlItem = ['S', 'H'].map((key) => {
|
||||
return {
|
||||
c_account_code_topup : key == 'S' ? item.customer : "",
|
||||
c_account_topup : key == 'H' ? item.account : "",
|
||||
ba : item.ba,
|
||||
amount : item.amount,
|
||||
posting_date : item.posting_date,
|
||||
c_invoice_no : item.reference,
|
||||
item_text :key == 'S' ? item.text1 : item.text2,
|
||||
de_cre : key
|
||||
}
|
||||
c_account_code_topup: key == 'S' ? item.customer : '',
|
||||
c_account_topup: key == 'H' ? item.account : '',
|
||||
ba: item.ba,
|
||||
amount: item.amount,
|
||||
posting_date: item.posting_date,
|
||||
c_invoice_no: item.reference,
|
||||
item_text: key == 'S' ? item.text1 : item.text2,
|
||||
de_cre: key,
|
||||
};
|
||||
});
|
||||
|
||||
let xmlRequest = helper.generateXMLRequest('ZFMCMS_FI_001', xmlHeader, xmlItem)
|
||||
console.log(xmlRequest)
|
||||
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} REQUEST posting ${item.reference} to SAP : ${xmlRequest}`);
|
||||
|
||||
const url = 'http://piqas.kereta-api.co.id:51500/XISOAPAdapter/MessageServlet?senderParty=&senderService=KCI_ETICKETING_2&receiverParty=&receiverService=&interface=SI_KCI_CMS_FI01&interfaceNamespace=urn:Posting_ETicketing_2'
|
||||
let xmlRequest = helper.generateXMLRequest(
|
||||
'ZFMCMS_FI_001',
|
||||
xmlHeader,
|
||||
xmlItem
|
||||
);
|
||||
console.log(xmlRequest);
|
||||
winston.logger.info(
|
||||
`SCHEDULER-RETRY-${uniqueCode} REQUEST posting ${item.reference} to SAP : ${xmlRequest}`
|
||||
);
|
||||
|
||||
const response = await helper.postingSAP(url, xmlRequest)
|
||||
const url =
|
||||
'http://piqas.kereta-api.co.id:51500/XISOAPAdapter/MessageServlet?senderParty=&senderService=KCI_ETICKETING_2&receiverParty=&receiverService=&interface=SI_KCI_CMS_FI01&interfaceNamespace=urn:Posting_ETicketing_2';
|
||||
|
||||
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} RESPONSE posting ${item.reference} to SAP : ${JSON.stringify(response)}`);
|
||||
const response = await helper.postingSAP(url, xmlRequest);
|
||||
|
||||
const resSAP = helper.getXMLData(response)
|
||||
winston.logger.info(
|
||||
`SCHEDULER-RETRY-${uniqueCode} RESPONSE posting ${
|
||||
item.reference
|
||||
} to SAP : ${JSON.stringify(response)}`
|
||||
);
|
||||
|
||||
const resSAP = helper.getXMLData(response);
|
||||
|
||||
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} TRANSACTION 2`);
|
||||
// UPDATE CMS
|
||||
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} SET resposn FB70 to CMS : ${JSON.stringify(resSAP)}`)
|
||||
winston.logger.info(
|
||||
`SCHEDULER-RETRY-${uniqueCode} SET resposn FB70 to CMS : ${JSON.stringify(
|
||||
resSAP
|
||||
)}`
|
||||
);
|
||||
|
||||
const cms = await model.setReturnSAP(item.no_dok, resSAP, trx)
|
||||
|
||||
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} RESULT CMS : ${JSON.stringify(cms)}`)
|
||||
const cms = await model.setReturnSAP(item.no_dok, resSAP, trx);
|
||||
|
||||
})
|
||||
winston.logger.info(
|
||||
`SCHEDULER-RETRY-${uniqueCode} RESULT CMS : ${JSON.stringify(cms)}`
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
return postingEt
|
||||
|
||||
}
|
||||
return postingEt;
|
||||
};
|
||||
|
||||
function wait(milliseconds) {
|
||||
return new Promise(resolve => setTimeout(resolve, milliseconds));
|
||||
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
validate,
|
||||
apiGenerateCahsIn,
|
||||
apiGenerateCashInSales,
|
||||
apiPostingCahsIn,
|
||||
_postingCashIn,
|
||||
_generateCashIn
|
||||
};
|
||||
_generateCashIn,
|
||||
_generateCashInSales
|
||||
};
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
|
||||
// GET PARTNER, MERCHANT, TERMINAL FROM TID
|
||||
const generateInvoice = async (invoiceDate, repost, trx) => {
|
||||
let result = await trx.select(
|
||||
trx.raw(
|
||||
`* FROM payment.sp_payment_req_topup_online('${invoiceDate}', ${repost})`
|
||||
)
|
||||
);
|
||||
|
||||
let result = await trx.select(trx.raw(`* FROM payment.sp_payment_req_topup_online('${invoiceDate}', ${repost})`))
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
const insertPostingEt = async (code, dataCashIn, trx) => {
|
||||
let type = ['S', 'H']
|
||||
let et = []
|
||||
let posting_et = []
|
||||
let type = ['S', 'H'];
|
||||
let et = [];
|
||||
let posting_et = [];
|
||||
type.forEach((item, index) => {
|
||||
let data = {
|
||||
file_name: code,
|
||||
@@ -25,137 +26,193 @@ const insertPostingEt = async (code, dataCashIn, trx) => {
|
||||
reference: code,
|
||||
amount: dataCashIn.amount,
|
||||
ba: dataCashIn.ba,
|
||||
indeks: (index+1),
|
||||
indeks: index + 1,
|
||||
totalidx: type.length,
|
||||
doc_header_text: code,
|
||||
pos_status : 4
|
||||
}
|
||||
|
||||
if(item == 'H'){
|
||||
data = {...data, ...{
|
||||
text: `Cash-in CMS ${code}`,
|
||||
debit_kredit: item,
|
||||
account: dataCashIn.c_account_topup,
|
||||
customer: null
|
||||
}}
|
||||
}else{
|
||||
data = {...data, ...{
|
||||
text: `Cash-in CMS ${code}`,
|
||||
debit_kredit: item,
|
||||
account: null,
|
||||
customer: dataCashIn.c_account_code_topup
|
||||
}}
|
||||
pos_status: 4,
|
||||
};
|
||||
|
||||
if (item == 'H') {
|
||||
data = {
|
||||
...data,
|
||||
...{
|
||||
text: `Cash-in CMS ${code}`,
|
||||
debit_kredit: item,
|
||||
account: dataCashIn.c_account_topup,
|
||||
customer: null,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
data = {
|
||||
...data,
|
||||
...{
|
||||
text: `Cash-in CMS ${code}`,
|
||||
debit_kredit: item,
|
||||
account: null,
|
||||
customer: dataCashIn.c_account_code_topup,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
et.push(data)
|
||||
et.push(data);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
posting_et = await trx('public.posting_et').insert(et, ['indeks', 'customer', 'account', 'ba', 'fiscal_year', 'amount', 'no_dok', 'text', 'debit_kredit'])
|
||||
|
||||
return posting_et[0]
|
||||
|
||||
}
|
||||
|
||||
const getPostingEt = async(trx) => {
|
||||
|
||||
const result = await trx('public.posting_et AS pe').select([
|
||||
'doc_header_text',
|
||||
posting_et = await trx('public.posting_et').insert(et, [
|
||||
'indeks',
|
||||
'customer',
|
||||
'account',
|
||||
'ba',
|
||||
'doc_date',
|
||||
'posting_date',
|
||||
'fiscal_year',
|
||||
trx.raw(`TO_CHAR(doc_date::DATE, 'MM') AS fis_period`),
|
||||
'doc_type',
|
||||
'reference',
|
||||
'no_dok',
|
||||
'tcode',
|
||||
'amount',
|
||||
trx.raw(`'IDR' AS currency`),
|
||||
trx.raw(`(SELECT customer FROM public.posting_et where reference = pe.reference and debit_kredit = 'S') as customer`),
|
||||
trx.raw(`(SELECT account FROM public.posting_et where reference = pe.reference and debit_kredit = 'H') as account `),
|
||||
trx.raw(`(SELECT text FROM public.posting_et where reference = pe.reference and debit_kredit = 'S') as text1`),
|
||||
trx.raw(`(SELECT text FROM public.posting_et where reference = pe.reference and debit_kredit = 'H') as text2`)
|
||||
])
|
||||
.where('tcode', '=', "FB70")
|
||||
// .where('reference', '=', reference)
|
||||
.whereIn('pos_status', ["4"])
|
||||
'no_dok',
|
||||
'text',
|
||||
'debit_kredit',
|
||||
]);
|
||||
|
||||
.groupBy(['doc_header_text', 'ba', 'doc_header_text', 'tcode', 'ba', 'amount', 'posting_date', 'doc_date', 'doc_type', 'fiscal_year', 'reference', 'no_dok'])
|
||||
|
||||
return result
|
||||
|
||||
}
|
||||
return posting_et[0];
|
||||
};
|
||||
|
||||
const setReturnSAP = async (code, resSAP, trx) => {
|
||||
let t_cash_in = []
|
||||
let reserveBalance = []
|
||||
const getPostingEt = async (trx) => {
|
||||
const result = await trx('public.posting_et AS pe')
|
||||
.select([
|
||||
'doc_header_text',
|
||||
'ba',
|
||||
'doc_date',
|
||||
'posting_date',
|
||||
'fiscal_year',
|
||||
trx.raw(`TO_CHAR(doc_date::DATE, 'MM') AS fis_period`),
|
||||
'doc_type',
|
||||
'reference',
|
||||
'no_dok',
|
||||
'tcode',
|
||||
'amount',
|
||||
trx.raw(`'IDR' AS currency`),
|
||||
trx.raw(
|
||||
`(SELECT customer FROM public.posting_et where reference = pe.reference and debit_kredit = 'S') as customer`
|
||||
),
|
||||
trx.raw(
|
||||
`(SELECT account FROM public.posting_et where reference = pe.reference and debit_kredit = 'H') as account `
|
||||
),
|
||||
trx.raw(
|
||||
`(SELECT text FROM public.posting_et where reference = pe.reference and debit_kredit = 'S') as text1`
|
||||
),
|
||||
trx.raw(
|
||||
`(SELECT text FROM public.posting_et where reference = pe.reference and debit_kredit = 'H') as text2`
|
||||
),
|
||||
])
|
||||
.where('tcode', '=', 'FB70')
|
||||
// .where('reference', '=', reference)
|
||||
.whereIn('pos_status', ['4'])
|
||||
|
||||
if(resSAP.type == 'S'){
|
||||
.groupBy([
|
||||
'doc_header_text',
|
||||
'ba',
|
||||
'doc_header_text',
|
||||
'tcode',
|
||||
'ba',
|
||||
'amount',
|
||||
'posting_date',
|
||||
'doc_date',
|
||||
'doc_type',
|
||||
'fiscal_year',
|
||||
'reference',
|
||||
'no_dok',
|
||||
]);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
const setReturnSAP = async (code, resSAP, trx) => {
|
||||
let t_cash_in = [];
|
||||
let reserveBalance = [];
|
||||
|
||||
if (resSAP.type == 'S') {
|
||||
// update invoice
|
||||
t_cash_in = await trx('payment.t_d_cash_in').update({
|
||||
c_return_sap: resSAP.data.E_DOCUMENTNUMBER,
|
||||
c_return_year_sap: resSAP.data.E_DOCUMENTYEAR
|
||||
}, ['c_cash_in_no','c_return_sap'])
|
||||
.where({
|
||||
c_cash_in_no: code
|
||||
});
|
||||
|
||||
// update load balance
|
||||
reserveBalance = await trx('trx.t_d_reservation_balance').update({
|
||||
c_return_cash_in_sap: resSAP.data.E_DOCUMENTNUMBER,
|
||||
c_cash_in_no: code
|
||||
}, ['c_cash_in_no', 'c_return_sap'])
|
||||
.whereRaw(`c_reservation_no IN (SELECT c_reservation_no FROM payment.t_d_cash_in_detail tdcid LEFT JOIN payment.t_d_cash_in tdci ON tdcid.i_cash_in = tdci.i_cash_in WHERE tdci.c_cash_in_no = '${code}')`)
|
||||
t_cash_in = await trx('payment.t_d_cash_in')
|
||||
.update(
|
||||
{
|
||||
c_return_sap: resSAP.data.E_DOCUMENTNUMBER,
|
||||
c_return_year_sap: resSAP.data.E_DOCUMENTYEAR,
|
||||
},
|
||||
['c_cash_in_no', 'c_return_sap']
|
||||
)
|
||||
.where({
|
||||
c_cash_in_no: code,
|
||||
});
|
||||
|
||||
}else {
|
||||
// update load balance
|
||||
reserveBalance = await trx('trx.t_d_reservation_balance')
|
||||
.update(
|
||||
{
|
||||
c_return_cash_in_sap: resSAP.data.E_DOCUMENTNUMBER,
|
||||
c_cash_in_no: code,
|
||||
},
|
||||
['c_cash_in_no', 'c_return_sap']
|
||||
)
|
||||
.whereRaw(
|
||||
`c_reservation_no IN (SELECT c_reservation_no FROM payment.t_d_cash_in_detail tdcid LEFT JOIN payment.t_d_cash_in tdci ON tdcid.i_cash_in = tdci.i_cash_in WHERE tdci.c_cash_in_no = '${code}')`
|
||||
);
|
||||
} else {
|
||||
let text = resSAP.message;
|
||||
let result = text.toUpperCase();
|
||||
if(result.includes("ALREADY")){
|
||||
if (result.includes('ALREADY')) {
|
||||
let result = text.toUpperCase().split('-');
|
||||
let doc_number = result[1].trim().split(" ")[0]
|
||||
let doc_number = result[1].trim().split(' ')[0];
|
||||
// update invoice
|
||||
const d = new Date();
|
||||
let year = d.getFullYear();
|
||||
t_cash_in = await trx('payment.t_d_cash_in').update({
|
||||
c_return_sap: doc_number,
|
||||
c_return_year_sap: year
|
||||
}, ['c_cash_in_no','c_return_sap'])
|
||||
.where({
|
||||
c_cash_in_no: code
|
||||
});
|
||||
t_cash_in = await trx('payment.t_d_cash_in')
|
||||
.update(
|
||||
{
|
||||
c_return_sap: doc_number,
|
||||
c_return_year_sap: year,
|
||||
},
|
||||
['c_cash_in_no', 'c_return_sap']
|
||||
)
|
||||
.where({
|
||||
c_cash_in_no: code,
|
||||
});
|
||||
|
||||
// update load balance
|
||||
reserveBalance = await trx('trx.t_d_reservation_balance').update({
|
||||
c_return_cash_in_sap: resSAP.data.E_DOCUMENTNUMBER,
|
||||
c_cash_in_no: code
|
||||
}, ['c_cash_in_no', 'c_return_sap'])
|
||||
.whereRaw(`c_reservation_no IN (SELECT c_reservation_no FROM payment.t_d_cash_in_detail tdcid LEFT JOIN payment.t_d_cash_in tdci ON tdcid.i_cash_in = tdci.i_cash_in WHERE tdci.c_cash_in_no = '${code}')`)
|
||||
|
||||
reserveBalance = await trx('trx.t_d_reservation_balance')
|
||||
.update(
|
||||
{
|
||||
c_return_cash_in_sap: resSAP.data.E_DOCUMENTNUMBER,
|
||||
c_cash_in_no: code,
|
||||
},
|
||||
['c_cash_in_no', 'c_return_sap']
|
||||
)
|
||||
.whereRaw(
|
||||
`c_reservation_no IN (SELECT c_reservation_no FROM payment.t_d_cash_in_detail tdcid LEFT JOIN payment.t_d_cash_in tdci ON tdcid.i_cash_in = tdci.i_cash_in WHERE tdci.c_cash_in_no = '${code}')`
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// update posting et
|
||||
const posting_et = await trx('public.posting_et').update({
|
||||
pos_status : resSAP.type == 'S' ? 0 : 4,
|
||||
status0 : resSAP.type,
|
||||
no_doksap : resSAP.data.E_DOCUMENTNUMBER ? resSAP.data.E_DOCUMENTNUMBER : null,
|
||||
status1 : resSAP.message ? resSAP.message : null
|
||||
}, ['file_name','status0']).where({
|
||||
no_dok: code
|
||||
})
|
||||
const posting_et = await trx('public.posting_et')
|
||||
.update(
|
||||
{
|
||||
pos_status: resSAP.type == 'S' ? 0 : 4,
|
||||
status0: resSAP.type,
|
||||
no_doksap: resSAP.data.E_DOCUMENTNUMBER
|
||||
? resSAP.data.E_DOCUMENTNUMBER
|
||||
: null,
|
||||
status1: resSAP.message ? resSAP.message : null,
|
||||
},
|
||||
['file_name', 'status0']
|
||||
)
|
||||
.where({
|
||||
no_dok: code,
|
||||
});
|
||||
|
||||
return {
|
||||
cash_in : t_cash_in[0],
|
||||
reserveBalance : reserveBalance[0],
|
||||
posting_et : posting_et[0]
|
||||
}
|
||||
|
||||
}
|
||||
cash_in: t_cash_in[0],
|
||||
reserveBalance: reserveBalance[0],
|
||||
posting_et: posting_et[0],
|
||||
};
|
||||
};
|
||||
|
||||
const getRecon = async (trx) => {
|
||||
|
||||
let sql = `SELECT
|
||||
tdi.c_invoice_no,
|
||||
'FB70' AS tcode,
|
||||
@@ -200,160 +257,337 @@ const getRecon = async (trx) => {
|
||||
SELECT c_reservation_no FROM payment.t_d_payment_recon tdpr WHERE tdpr.c_status = 'S'
|
||||
)
|
||||
GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17, tdpr.d_payment, b_past_month
|
||||
ORDER BY tdpr.d_payment`
|
||||
let result = await trx.raw(sql)
|
||||
ORDER BY tdpr.d_payment`;
|
||||
let result = await trx.raw(sql);
|
||||
|
||||
return result.rows
|
||||
}
|
||||
return result.rows;
|
||||
};
|
||||
|
||||
const getReserve = async(trx, code, date, invoice) => {
|
||||
const getReserve = async (trx, code, date, invoice) => {
|
||||
const res = await trx
|
||||
.select([
|
||||
'tdrb.c_reservation_no',
|
||||
'tdrb.i_reservation_amount',
|
||||
'tdpr.c_payment_recon_no',
|
||||
'tdpr.d_payment',
|
||||
'tdpr.d_payment_recon',
|
||||
'tdrb.c_partner_code',
|
||||
'tdrb.c_partner_name',
|
||||
'tdrb.c_load_balance_no',
|
||||
'tdi.c_invoice_no',
|
||||
'tdi.m_amount as invoice_amount'
|
||||
])
|
||||
.from('trx.t_d_reservation_balance AS tdrb')
|
||||
.leftJoin('trx.t_d_load_balance as tdlb', function () {
|
||||
this.on('tdrb.c_load_balance_no', '=', 'tdlb.c_load_balance_no');
|
||||
})
|
||||
.leftJoin('payment.t_d_invoice as tdi', function () {
|
||||
this.on('tdi.c_invoice_no', '=', 'tdlb.c_invoice_no').orOn(
|
||||
'tdi.c_invoice_no',
|
||||
'=',
|
||||
'tdrb.c_invoice_no'
|
||||
);
|
||||
})
|
||||
.leftJoin('payment.t_d_payment_recon as tdpr', function () {
|
||||
this.on('tdpr.c_reservation_no', '=', 'tdrb.c_reservation_no');
|
||||
})
|
||||
.where('tdrb.c_status', '=', 'A')
|
||||
.where('tdi.c_status', '!=', 'X')
|
||||
.where('tdrb.c_partner_code', '=', code)
|
||||
.where('tdpr.d_payment', '=', date)
|
||||
.where('tdi.c_invoice_no', '=', invoice)
|
||||
.where('tdpr.c_status', '=', 'S')
|
||||
.whereNotNull('tdi.c_return_sap')
|
||||
.whereNotNull('tdrb.c_load_balance_no')
|
||||
.whereNull('tdrb.c_cash_in_no')
|
||||
// .whereRaw(
|
||||
// `tdrb.c_reservation_no in (SELECT c_reservation_no FROM payment.t_d_payment_recon where c_status = 'S' ) AND tdrb.c_reservation_no NOT IN (SELECT c_reservation_no FROM payment.t_d_cash_in_detail WHERE b_reversal IS NOT TRUE)`
|
||||
// );
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
const res = await trx.select([
|
||||
"tdrb.c_reservation_no",
|
||||
"tdrb.i_reservation_amount",
|
||||
"tdpr.c_payment_recon_no",
|
||||
"tdpr.d_payment",
|
||||
"tdpr.d_payment_recon",
|
||||
"tdrb.c_partner_code",
|
||||
"tdrb.c_partner_name",
|
||||
"tdrb.c_load_balance_no",
|
||||
"tdi.c_invoice_no"
|
||||
])
|
||||
.from("trx.t_d_reservation_balance AS tdrb")
|
||||
.leftJoin('trx.t_d_load_balance as tdlb', function () {
|
||||
this.on('tdrb.c_load_balance_no', '=', 'tdlb.c_load_balance_no')
|
||||
})
|
||||
.leftJoin('payment.t_d_invoice as tdi', function () {
|
||||
this.on('tdi.c_invoice_no', '=', 'tdlb.c_invoice_no')
|
||||
.orOn('tdi.c_invoice_no', '=', 'tdrb.c_invoice_no')
|
||||
})
|
||||
.leftJoin('payment.t_d_payment_recon as tdpr', function () {
|
||||
this.on('tdpr.c_reservation_no', '=', 'tdrb.c_reservation_no')
|
||||
})
|
||||
.where("tdrb.c_status", "=", "A")
|
||||
.where("tdi.c_status", "!=", "X")
|
||||
.where("tdrb.c_partner_code", "=", code)
|
||||
.where("tdpr.d_payment", "=", date)
|
||||
.where("tdi.c_invoice_no", "=", invoice)
|
||||
.where("tdpr.c_status", "=", "S")
|
||||
.whereNotNull("tdi.c_return_sap")
|
||||
.whereNotNull("tdrb.c_load_balance_no")
|
||||
.whereRaw(`tdrb.c_reservation_no in (SELECT c_reservation_no FROM payment.t_d_payment_recon where c_status = 'S' ) AND tdrb.c_reservation_no NOT IN (SELECT c_reservation_no FROM payment.t_d_cash_in_detail WHERE b_reversal IS NOT TRUE)`)
|
||||
return res
|
||||
}
|
||||
|
||||
const getPartnerRecon = async(trx) => {
|
||||
|
||||
const res = await trx.select([
|
||||
"tdpr.c_partner_code",
|
||||
"tdrb.c_partner_name",
|
||||
"tdi.c_invoice_no",
|
||||
"tdi.d_invoice_date",
|
||||
trx.raw("to_char(tdpr.d_payment, 'YYYY-MM-DD') AS d_payment"),
|
||||
trx.raw("SUM(tdrb.i_reservation_amount) AS amount"),
|
||||
"tmp.c_account_topup",
|
||||
"tmp.c_account_code_topup",
|
||||
"i_company",
|
||||
"i_holding",
|
||||
trx.raw(`CASE
|
||||
WHEN to_char(tdpr.d_payment, 'MM') = to_char(tdi.d_invoice_date, 'MM')
|
||||
const getSalesKMT = async (trx, code, date, invoice) => {
|
||||
const res = await trx
|
||||
.select([
|
||||
'tdskm.c_sales_no',
|
||||
'tdskm.i_total_billing',
|
||||
'tdpr.c_payment_recon_no',
|
||||
'tdpr.d_payment',
|
||||
'tdpr.d_payment_recon',
|
||||
'tdskm.c_partner_code',
|
||||
'tdskm.c_partner_name',
|
||||
'tdsi.c_invoice_no',
|
||||
'tdsi.m_total_billing as invoice_amount'
|
||||
])
|
||||
.from('kmt_mobile.t_d_sales_kmt_mobile AS tdskm')
|
||||
.leftJoin('payment.t_d_payment_recon_sales_kmt_mobile as tdpr', 'tdpr.c_sales_no', 'tdskm.c_sales_no')
|
||||
.leftJoin('payment.t_d_sales_invoice as tdsi', 'tdsi.i_sales_invoice', 'tdskm.i_sales_invoice')
|
||||
|
||||
.where('tdskm.c_sales_status', '=', 'A')
|
||||
.where('tdsi.c_status', '!=', 'X')
|
||||
.where('tdskm.c_partner_code', '=', code)
|
||||
.where('tdpr.d_payment', '=', date)
|
||||
.where('tdsi.c_invoice_no', '=', invoice)
|
||||
.where('tdpr.c_status', '=', 'S')
|
||||
.whereNotNull('tdsi.c_return_sap')
|
||||
.whereRaw(
|
||||
`tdskm.c_sales_no NOT IN (SELECT c_reservation_no FROM payment.t_d_cash_in_detail WHERE b_reversal IS NOT TRUE)`
|
||||
);
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
const getPartnerRecon = async (trx) => {
|
||||
// const res = await trx
|
||||
// .select([
|
||||
// 'tdpr.c_partner_code',
|
||||
// 'tdrb.c_partner_name',
|
||||
// 'tdi.c_invoice_no',
|
||||
// 'tdi.d_invoice_date',
|
||||
// trx.raw("to_char(tdpr.d_payment, 'YYYY-MM-DD') AS d_payment"),
|
||||
// trx.raw('SUM(tdrb.i_reservation_amount) AS amount'),
|
||||
// 'tmp.c_account_topup',
|
||||
// 'tmp.c_account_code_topup',
|
||||
// 'i_company',
|
||||
// 'i_holding',
|
||||
// trx.raw(`CASE
|
||||
// WHEN to_char(tdpr.d_payment, 'MM') >= to_char(tdi.d_invoice_date, 'MM')
|
||||
// THEN 'IP'
|
||||
// ELSE
|
||||
// 'OP'
|
||||
// END c_in_period`),
|
||||
// ])
|
||||
// .from('trx.t_d_reservation_balance AS tdrb')
|
||||
// .leftJoin('trx.t_d_load_balance as tdlb', function () {
|
||||
// this.on('tdrb.c_load_balance_no', '=', 'tdlb.c_load_balance_no');
|
||||
// })
|
||||
// .leftJoin('payment.t_d_invoice as tdi', function () {
|
||||
// this.on('tdi.c_invoice_no', '=', 'tdlb.c_invoice_no').orOn(
|
||||
// 'tdi.c_invoice_no',
|
||||
// '=',
|
||||
// 'tdrb.c_invoice_no'
|
||||
// );
|
||||
// })
|
||||
// .leftJoin('payment.t_d_payment_recon as tdpr', function () {
|
||||
// this.on('tdpr.c_reservation_no', '=', 'tdrb.c_reservation_no');
|
||||
// })
|
||||
// .leftJoin('public.t_m_partner as tmp', function () {
|
||||
// this.on('tmp.i_partner', '=', 'tdrb.i_partner');
|
||||
// })
|
||||
|
||||
// .where('tdrb.c_status', '=', 'A')
|
||||
// .where('tdi.c_status', '!=', 'X')
|
||||
// .where('tdpr.c_status', '=', 'S')
|
||||
// .whereNotNull('tdi.c_return_sap')
|
||||
// .whereNotNull('tdrb.c_load_balance_no')
|
||||
// .whereRaw(
|
||||
// `tdrb.c_reservation_no in (SELECT c_reservation_no FROM payment.t_d_payment_recon where c_status = 'S' ) AND tdrb.c_reservation_no NOT IN (SELECT c_reservation_no FROM payment.t_d_cash_in_detail WHERE b_reversal IS NOT TRUE)`
|
||||
// )
|
||||
// .groupBy([
|
||||
// 'tdpr.c_partner_code',
|
||||
// 'tdrb.c_partner_name',
|
||||
// 'tdi.c_invoice_no',
|
||||
// 'tdi.d_invoice_date',
|
||||
// 'tdpr.d_payment',
|
||||
// 'tmp.c_account_topup',
|
||||
// 'tmp.c_account_code_topup',
|
||||
// 'tdi.i_company',
|
||||
// 'i_holding',
|
||||
// ])
|
||||
// .limit(1);
|
||||
// .toSql()
|
||||
|
||||
const res = await trx
|
||||
.select([
|
||||
'tdpr.c_partner_code',
|
||||
'tdrb.c_partner_name',
|
||||
'tdi.c_invoice_no',
|
||||
'tdi.d_invoice_date',
|
||||
trx.raw("to_char(tdpr.d_payment, 'YYYY-MM-DD') AS d_payment"),
|
||||
trx.raw('coalesce(SUM(tdrb.i_reservation_amount),0) AS amount'),
|
||||
// trx.raw('coalesce(SUM(tdcid.m_amount),0) AS amount_cash_in'),
|
||||
'tmp.c_account_topup',
|
||||
'tmp.c_account_code_topup',
|
||||
'i_company',
|
||||
'i_holding',
|
||||
trx.raw(`CASE
|
||||
WHEN to_char(tdpr.d_payment, 'YYYYMM') >= to_char(tdi.d_invoice_date, 'YYYYMM')
|
||||
THEN 'IP'
|
||||
ELSE
|
||||
'OP'
|
||||
END c_in_period`),
|
||||
])
|
||||
.from("trx.t_d_reservation_balance AS tdrb")
|
||||
.leftJoin('trx.t_d_load_balance as tdlb', function () {
|
||||
this.on('tdrb.c_load_balance_no', '=', 'tdlb.c_load_balance_no')
|
||||
})
|
||||
.leftJoin('payment.t_d_invoice as tdi', function () {
|
||||
this
|
||||
.on('tdi.c_invoice_no', '=', 'tdlb.c_invoice_no')
|
||||
.orOn('tdi.c_invoice_no', '=', 'tdrb.c_invoice_no')
|
||||
})
|
||||
.leftJoin('payment.t_d_payment_recon as tdpr', function () {
|
||||
this.on('tdpr.c_reservation_no', '=', 'tdrb.c_reservation_no')
|
||||
})
|
||||
.leftJoin('public.t_m_partner as tmp', function () {
|
||||
this.on('tmp.i_partner', '=', 'tdrb.i_partner')
|
||||
})
|
||||
|
||||
.where("tdrb.c_status", "=", "A")
|
||||
.where("tdi.c_status", "!=", "X")
|
||||
.where("tdpr.c_status", "=", "S")
|
||||
.whereNotNull("tdi.c_return_sap")
|
||||
.whereNotNull("tdrb.c_load_balance_no")
|
||||
.whereRaw(`tdrb.c_reservation_no in (SELECT c_reservation_no FROM payment.t_d_payment_recon where c_status = 'S' ) AND tdrb.c_reservation_no NOT IN (SELECT c_reservation_no FROM payment.t_d_cash_in_detail WHERE b_reversal IS NOT TRUE)`)
|
||||
.groupBy(["tdpr.c_partner_code","tdrb.c_partner_name","tdi.c_invoice_no","tdi.d_invoice_date", "tdpr.d_payment", "tmp.c_account_topup", "tmp.c_account_code_topup", "tdi.i_company", "i_holding"])
|
||||
// .toSql()
|
||||
])
|
||||
.from('trx.t_d_reservation_balance AS tdrb')
|
||||
.leftJoin('trx.t_d_load_balance as tdlb', function () {
|
||||
this.on('tdrb.c_load_balance_no', '=', 'tdlb.c_load_balance_no');
|
||||
})
|
||||
.leftJoin('payment.t_d_invoice as tdi', function () {
|
||||
this.on('tdi.c_invoice_no', '=', 'tdlb.c_invoice_no').orOn(
|
||||
'tdi.c_invoice_no',
|
||||
'=',
|
||||
'tdrb.c_invoice_no'
|
||||
);
|
||||
})
|
||||
.leftJoin('payment.t_d_payment_recon as tdpr', function () {
|
||||
this.on('tdpr.c_reservation_no', '=', 'tdrb.c_reservation_no');
|
||||
})
|
||||
.leftJoin('public.t_m_partner as tmp', function () {
|
||||
this.on('tmp.i_partner', '=', 'tdrb.i_partner');
|
||||
})
|
||||
// .leftJoin('payment.t_d_cash_in_detail as tdcid', function () {
|
||||
// this.on('tdcid.c_reservation_no', '=', 'tdrb.c_reservation_no');
|
||||
// })
|
||||
|
||||
return res
|
||||
.where('tdrb.c_status', '=', 'A')
|
||||
.where('tdi.c_status', '!=', 'X')
|
||||
.where('tdpr.c_status', '=', 'S')
|
||||
.whereNotNull('tdi.c_return_sap')
|
||||
.whereNotNull('tdrb.c_load_balance_no')
|
||||
.whereNull('tdrb.c_cash_in_no')
|
||||
.groupBy([
|
||||
'tdpr.c_partner_code',
|
||||
'tdrb.c_partner_name',
|
||||
'tdi.c_invoice_no',
|
||||
'tdi.d_invoice_date',
|
||||
'tdpr.d_payment',
|
||||
'tmp.c_account_topup',
|
||||
'tmp.c_account_code_topup',
|
||||
'tdi.i_company',
|
||||
'i_holding',
|
||||
]);
|
||||
// .havingRaw(
|
||||
// 'coalesce(SUM(tdrb.i_reservation_amount),0) > coalesce(SUM(tdcid.m_amount),0)'
|
||||
// );
|
||||
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
const getPartnerReconSales = async (trx) => {
|
||||
|
||||
const res = await trx
|
||||
.select([
|
||||
'tdsi.c_partner_code',
|
||||
'tdsi.c_partner_name',
|
||||
'tdsi.c_invoice_no',
|
||||
'tdsi.d_invoice_date',
|
||||
trx.raw("to_char(tdpr.d_payment, 'YYYY-MM-DD') AS d_payment"),
|
||||
trx.raw('coalesce(SUM(tdskm.i_total_billing),0) AS amount'),
|
||||
'tmp.c_account_topup',
|
||||
'tmp.c_account_code_topup',
|
||||
trx.raw(`CASE WHEN to_char(tdpr.d_payment, 'YYYYMM') >= to_char(tdsi.d_invoice_date, 'YYYYMM')
|
||||
THEN 'IP' ELSE 'OP'
|
||||
END c_in_period`),
|
||||
])
|
||||
.from('kmt_mobile.t_d_sales_kmt_mobile AS tdskm')
|
||||
|
||||
.leftJoin('payment.t_d_sales_invoice as tdsi', function () {
|
||||
this.on('tdsi.i_sales_invoice', '=', 'tdskm.i_sales_invoice');
|
||||
})
|
||||
.leftJoin('payment.t_d_payment_recon_sales_kmt_mobile as tdpr', function () {
|
||||
this.on('tdpr.c_sales_no', '=', 'tdskm.c_sales_no');
|
||||
})
|
||||
.leftJoin('public.t_m_partner as tmp', function () {
|
||||
this.on('tmp.i_partner', '=', 'tdskm.i_partner');
|
||||
})
|
||||
.where('tdskm.c_sales_status', '=', 'A')
|
||||
.where('tdsi.c_status', '!=', 'X')
|
||||
.where('tdpr.c_status', '=', 'S')
|
||||
.whereNotNull('tdsi.c_return_sap')
|
||||
.whereNull('tdskm.c_cash_in_no')
|
||||
.groupBy([
|
||||
'tdsi.c_partner_code',
|
||||
'tdsi.c_partner_name',
|
||||
'tdsi.c_invoice_no',
|
||||
'tdsi.d_invoice_date',
|
||||
'tdpr.d_payment',
|
||||
'tmp.c_account_topup',
|
||||
'tmp.c_account_code_topup'
|
||||
]);
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
const generateCode = async (trx, c_partner_code, d_payment_recon) => {
|
||||
let code = ""
|
||||
let prefix = `CIN${c_partner_code}${d_payment_recon}`
|
||||
let code = '';
|
||||
let prefix = `CIN${c_partner_code}${d_payment_recon}`;
|
||||
|
||||
let result =await trx.select([trx.raw(`substring(c_cash_in_no, 13, 3) AS code`)])
|
||||
.from("payment.t_d_cash_in")
|
||||
.whereRaw(`substring(c_cash_in_no, 1, 12) = '${prefix}'`)
|
||||
// .where("d_project_date", projectDate)
|
||||
.orderBy('c_cash_in_no', 'DESC')
|
||||
.first()
|
||||
let result = await trx
|
||||
.select([trx.raw(`substring(c_cash_in_no, 13, 3) AS code`)])
|
||||
.from('payment.t_d_cash_in')
|
||||
.whereRaw(`substring(c_cash_in_no, 1, 12) = '${prefix}'`)
|
||||
// .where("d_project_date", projectDate)
|
||||
.orderBy('c_cash_in_no', 'DESC')
|
||||
.first();
|
||||
|
||||
if(result){
|
||||
let counter = parseInt(result.code)+1
|
||||
if (result) {
|
||||
let counter = parseInt(result.code) + 1;
|
||||
counter = String(counter).padStart(3, '0');
|
||||
code = `${prefix}${counter}`
|
||||
|
||||
}else{
|
||||
code = `${prefix}001`
|
||||
code = `${prefix}${counter}`;
|
||||
} else {
|
||||
code = `${prefix}001`;
|
||||
}
|
||||
|
||||
return code
|
||||
}
|
||||
return code;
|
||||
};
|
||||
|
||||
const insertCashInDetail = async (trx, data) => {
|
||||
let result = []
|
||||
if(data.length > 0){
|
||||
result = await trx('payment.t_d_cash_in_detail').insert(data,["*"])
|
||||
let result = [];
|
||||
// if (data.length > 0) {
|
||||
// result = await trx('payment.t_d_cash_in_detail').insert(data, ['*']);
|
||||
// }
|
||||
|
||||
if (data) {
|
||||
result = await trx('payment.t_d_cash_in_detail').insert(data, ['*']);
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
const updateIntoReserve = async (trx, dataReserve, reserveNo) => {
|
||||
let result = await trx('trx.t_d_reservation_balance').update(dataReserve, ["*"]).where({c_reservation_no: reserveNo})
|
||||
return result
|
||||
}
|
||||
let result = await trx('trx.t_d_reservation_balance')
|
||||
.update(dataReserve, ['*'])
|
||||
.where({ c_reservation_no: reserveNo });
|
||||
return result;
|
||||
};
|
||||
|
||||
const updateIntoSalesKMT = async (trx, dataSales, salesNo) => {
|
||||
let result = await trx('kmt_mobile.t_d_sales_kmt_mobile')
|
||||
.update(dataSales, ['*'])
|
||||
.where({ c_sales_no: salesNo });
|
||||
return result;
|
||||
};
|
||||
|
||||
const insertCashIn = async (trx, data) => {
|
||||
let result = await trx('payment.t_d_cash_in').insert(data,["*"])
|
||||
return result[0]
|
||||
}
|
||||
let result = await trx('payment.t_d_cash_in').insert(data, ['*']);
|
||||
return result[0];
|
||||
};
|
||||
|
||||
const writePaynentHistory = async (data, message, i_log_name, trx) => {
|
||||
console.log(data)
|
||||
const result = await trx('log.t_log_invoice').insert({
|
||||
// i_log_name : 102,
|
||||
i_log_name : 119,
|
||||
d_log : trx.raw('NOW()'),
|
||||
c_invoice_no : data.c_cash_in_no,
|
||||
c_partner_name : data.c_partner_name,
|
||||
j_new_data : JSON.stringify(data),
|
||||
d_payment_date: trx.raw('NOW()'),
|
||||
c_note : message,
|
||||
c_status : 'S',
|
||||
d_created : trx.raw('NOW()'),
|
||||
m_amount : data.amount,
|
||||
m_mdr_amount : 0,
|
||||
m_mdr_net : data.amount
|
||||
|
||||
}, ['i_log_name', 'c_note'])
|
||||
|
||||
return result
|
||||
|
||||
}
|
||||
console.log(data);
|
||||
const result = await trx('log.t_log_invoice').insert(
|
||||
{
|
||||
// i_log_name : 102,
|
||||
i_log_name: 119,
|
||||
d_log: trx.raw('NOW()'),
|
||||
c_invoice_no: data.c_cash_in_no,
|
||||
c_partner_name: data.c_partner_name,
|
||||
j_new_data: JSON.stringify(data),
|
||||
d_payment_date: trx.raw('NOW()'),
|
||||
c_note: message,
|
||||
c_status: 'S',
|
||||
d_created: trx.raw('NOW()'),
|
||||
m_amount: data.amount,
|
||||
m_mdr_amount: 0,
|
||||
m_mdr_net: data.amount,
|
||||
},
|
||||
['i_log_name', 'c_note']
|
||||
);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
generateInvoice,
|
||||
@@ -361,12 +595,14 @@ module.exports = {
|
||||
setReturnSAP,
|
||||
getPostingEt,
|
||||
writePaynentHistory,
|
||||
|
||||
getRecon,
|
||||
generateCode,
|
||||
insertCashInDetail,
|
||||
getReserve,
|
||||
getPartnerRecon,
|
||||
getPartnerReconSales,
|
||||
getReserve,
|
||||
getSalesKMT,
|
||||
insertCashIn,
|
||||
updateIntoReserve
|
||||
};
|
||||
updateIntoReserve,
|
||||
updateIntoSalesKMT
|
||||
};
|
||||
|
||||
@@ -91,8 +91,8 @@ const cardHistory = async (req, res) => {
|
||||
new Date((parseInt(element.slice(0, 8), 16) + 946684800) * 1000)
|
||||
).format('YYYY-MM-DD HH:mm:ss');
|
||||
nominal = parseInt(element.slice(8, 16), 16);
|
||||
mid = element.slice(16, 20);
|
||||
tid = element.slice(20, 24);
|
||||
mid = element.slice(16, 20).toUpperCase();
|
||||
tid = element.slice(20, 24).toUpperCase();
|
||||
|
||||
// blok yang menandakan konten untuk reska
|
||||
checkReskaFormat = element.slice(14, 20);
|
||||
@@ -198,6 +198,14 @@ const history = async (req, res) => {
|
||||
// param
|
||||
let { mid, tid, card_number, start_date, end_date } = req.body;
|
||||
|
||||
if (mid) {
|
||||
mid = mid.toUpperCase();
|
||||
}
|
||||
|
||||
if (tid) {
|
||||
tid = tid.toUpperCase();
|
||||
}
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ REQUEST CARD-HISTORY-FROM-CMS ]: ${JSON.stringify(
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -0,0 +1,233 @@
|
||||
const { default: axios } = require('axios');
|
||||
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();
|
||||
|
||||
let useClient;
|
||||
var counterDirect = 0;
|
||||
|
||||
// set connection HSM server
|
||||
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');
|
||||
|
||||
useClient = client2;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
var { client } = require('../services/webSocket');
|
||||
var { client2 } = require('../services/webSocket2');
|
||||
}
|
||||
|
||||
const controller = async (req, res) => {
|
||||
try {
|
||||
if (counterDirect > 1 || counterDirect < 0) {
|
||||
counterDirect = 0;
|
||||
}
|
||||
counterDirect++;
|
||||
|
||||
let { body } = req;
|
||||
// uniqueCode = body.unique_code;
|
||||
let uniqueCode = await helper.getUniqueCode();
|
||||
uniqueCode = uniqueCode + '' + counterDirect;
|
||||
let result = {};
|
||||
let usingHSMNumber = 1;
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
// set request to HSM server 2
|
||||
if (uniqueCode) {
|
||||
if (parseInt(uniqueCode) % 2 == 0) {
|
||||
// create log
|
||||
// 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 ==================================}`
|
||||
);
|
||||
useClient = client2;
|
||||
}
|
||||
} 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 ==================================}`
|
||||
);
|
||||
useClient = client;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ REQUEST CLEAR CARD KATEGORI PEGAWAI-1 ]: STARTING CLEAR...`
|
||||
);
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING CLEAR CARD KATEGORI PEGAWAI-1 ]: ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
|
||||
let felicaPollingResponse = Buffer.from(
|
||||
generate.hexToBytes(body.requestData)
|
||||
);
|
||||
let _stopMessage = 1;
|
||||
let _timeOut = false;
|
||||
|
||||
let _validasi = body.requestData.slice(4, 20);
|
||||
|
||||
let transactionId = Buffer.from([0x00, 0x00]);
|
||||
let apiId = Buffer.from([0x01]);
|
||||
reqData = generate.makeRequestData(
|
||||
transactionId,
|
||||
apiId,
|
||||
felicaPollingResponse
|
||||
);
|
||||
|
||||
useClient.sendData(reqData);
|
||||
|
||||
let respData = null;
|
||||
let respData1 = null;
|
||||
|
||||
setInterval(function () {
|
||||
respData = Buffer.from([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
|
||||
_timeOut = true;
|
||||
}, 10000);
|
||||
|
||||
useClient.ws.on('message', (message) => {
|
||||
let __validasi = generate.buf2hex(message).slice(14, 30);
|
||||
while (
|
||||
message[2] == 1 &&
|
||||
_stopMessage == 1 &&
|
||||
_validasi.toLowerCase() == __validasi.toLowerCase()
|
||||
) {
|
||||
respData = null;
|
||||
// console.log('*WS MESSAGE Auth1v2: ' + generate.buf2hex(message));
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING CLEAR CARD KATEGORI PEGAWAI-1 ]: message from HSM ${generate.buf2hex(
|
||||
message
|
||||
)}`
|
||||
);
|
||||
|
||||
respData = message;
|
||||
_stopMessage = 2;
|
||||
}
|
||||
});
|
||||
|
||||
while (respData == null) {
|
||||
await _sleep(10);
|
||||
}
|
||||
|
||||
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`;
|
||||
}
|
||||
|
||||
let response = await axios({
|
||||
url: url,
|
||||
method: 'get',
|
||||
});
|
||||
|
||||
result = {
|
||||
code: '5001',
|
||||
message: 'Timeout',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CLEAR CARD KATEGORI PEGAWAI-1 ]: ${JSON.stringify(
|
||||
result
|
||||
)} and refresh HSM ${usingHSMNumber} response status: ${
|
||||
response.status
|
||||
} | response text: ${response.statusText}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
}
|
||||
|
||||
_stopMessage = 0;
|
||||
|
||||
transactionId[0] = respData[0];
|
||||
transactionId[1] = respData[1];
|
||||
respCode = generate.getResponseCode(respData);
|
||||
respData1 = generate.getResponseData(respData);
|
||||
|
||||
if (respData1) {
|
||||
result = {
|
||||
code: '00',
|
||||
message: 'Request Authenticate 1 Success',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respCode,
|
||||
responseData: respData1,
|
||||
responseLength: respData1.length / 2,
|
||||
unique_code: uniqueCode,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
result = {
|
||||
code: '5004',
|
||||
message: 'Empty Data from HSM',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respCode,
|
||||
responseData: respData1,
|
||||
responseLength: respData1.length / 2,
|
||||
unique_code: uniqueCode,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ RESPONSE CLEAR CARD KATEGORI PEGAWAI-1 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`[ RESPONSE CLEAR CARD KATEGORI PEGAWAI-1 ]: 500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
code: '5001',
|
||||
message:
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = controller;
|
||||
@@ -0,0 +1,184 @@
|
||||
const winston = require('../../../helpers/winston.logger');
|
||||
const generate = require('../utils/utils');
|
||||
const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
require('dotenv').config();
|
||||
|
||||
let useClient;
|
||||
|
||||
// set connection HSM server
|
||||
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');
|
||||
|
||||
useClient = client2;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
var { client } = require('../services/webSocket');
|
||||
var { client2 } = require('../services/webSocket2');
|
||||
}
|
||||
|
||||
const controller = async (req, res) => {
|
||||
try {
|
||||
let { body } = req;
|
||||
let uniqueCode = body.unique_code;
|
||||
let result = {};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ REQUEST CLEAR CARD KATEGORI PEGAWAI-2 ]: ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
// set request to HSM server 2
|
||||
if (uniqueCode) {
|
||||
if (parseInt(uniqueCode) % 2 == 0) {
|
||||
// create log
|
||||
// winston.logger.error(`request to HSM server 2`);
|
||||
|
||||
if (client2.clientAuthenticated == false) {
|
||||
useClient = client;
|
||||
} else {
|
||||
useClient = client2;
|
||||
}
|
||||
} else {
|
||||
if (client.clientAuthenticated == false) {
|
||||
useClient = client2;
|
||||
} else {
|
||||
useClient = client;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let transactionId = Buffer.from(generate.hexToBytes(body.trxID));
|
||||
let _validationTrxID = Buffer.from(generate.hexToBytes(body.trxID));
|
||||
let auth2v2requestData = Buffer.from(generate.hexToBytes(body.requestData));
|
||||
let _stopMessage = 1;
|
||||
let _timeOut = false;
|
||||
|
||||
if (auth2v2requestData[0] != 0x41) {
|
||||
result = {
|
||||
code: '5003',
|
||||
message: 'Wrong Respone from Card',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CLEAR CARD KATEGORI PEGAWAI-2 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
}
|
||||
|
||||
let apiId = Buffer.from([0x02]);
|
||||
let reqData = generate.makeRequestData(
|
||||
transactionId,
|
||||
apiId,
|
||||
auth2v2requestData
|
||||
);
|
||||
|
||||
useClient.sendData(reqData);
|
||||
|
||||
let respData = null;
|
||||
let respData1 = null;
|
||||
|
||||
setInterval(function () {
|
||||
respData = Buffer.from([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
|
||||
_timeOut = true;
|
||||
}, 10000);
|
||||
|
||||
useClient.ws.on('message', (message) => {
|
||||
while (
|
||||
message[2] == 2 &&
|
||||
message[0] == _validationTrxID[0] &&
|
||||
message[1] == _validationTrxID[1] &&
|
||||
_stopMessage == 1
|
||||
) {
|
||||
respData = null;
|
||||
// console.log("*WS MESSAGE Auth2v2: " + generate.buf2hex(message));
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING CLEAR CARD KATEGORI PEGAWAI-2 ]: message from HSM ${generate.buf2hex(
|
||||
message
|
||||
)}`
|
||||
);
|
||||
|
||||
respData = message;
|
||||
_stopMessage = 2;
|
||||
}
|
||||
});
|
||||
|
||||
while (respData == null) {
|
||||
await _sleep(10);
|
||||
}
|
||||
|
||||
if (_timeOut) {
|
||||
result = {
|
||||
code: '5001',
|
||||
message: 'Timeout',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ PROCESSING CLEAR CARD KATEGORI PEGAWAI-2 ]: message from HSM ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
}
|
||||
|
||||
_stopMessage = 0;
|
||||
|
||||
transactionId[0] = respData[0];
|
||||
transactionId[1] = respData[1];
|
||||
respCode = generate.getResponseCode(respData);
|
||||
respData1 = generate.getResponseData(respData);
|
||||
|
||||
result = {
|
||||
code: '00',
|
||||
message: 'Request Authenticate 2 Success',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respCode,
|
||||
responseData: respData1,
|
||||
responseLength: respData1.length / 2,
|
||||
},
|
||||
};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ RESPONSE CLEAR CARD KATEGORI PEGAWAI-2 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`[ RESPONSE CLEAR CARD KATEGORI PEGAWAI-2 ]: 500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
code: '5001',
|
||||
message:
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = controller;
|
||||
@@ -0,0 +1,163 @@
|
||||
const winston = require('../../../helpers/winston.logger');
|
||||
const generate = require('../utils/utils');
|
||||
const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
require('dotenv').config();
|
||||
|
||||
let useClient;
|
||||
|
||||
// set connection HSM server
|
||||
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');
|
||||
|
||||
useClient = client2;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
var { client } = require('../services/webSocket');
|
||||
var { client2 } = require('../services/webSocket2');
|
||||
}
|
||||
|
||||
const controller = async (req, res) => {
|
||||
try {
|
||||
let { body } = req;
|
||||
let uniqueCode = body.unique_code;
|
||||
let result = {};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ REQUEST CLEAR CARD KATEGORI PEGAWAI-3 ]: request to HSM ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
// set request to HSM server 2
|
||||
if (uniqueCode) {
|
||||
if (parseInt(uniqueCode) % 2 == 0) {
|
||||
// create log
|
||||
// winston.logger.error(`request to HSM server 2`);
|
||||
|
||||
if (client2.clientAuthenticated == false) {
|
||||
useClient = client;
|
||||
} else {
|
||||
useClient = client2;
|
||||
}
|
||||
} else {
|
||||
if (client.clientAuthenticated == false) {
|
||||
useClient = client2;
|
||||
} else {
|
||||
useClient = client;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let transactionId = Buffer.from(generate.hexToBytes(body.trxID));
|
||||
let auth2v2responseSetData = Buffer.from(
|
||||
generate.hexToBytes(body.requestData)
|
||||
);
|
||||
let _stopMessage = 1;
|
||||
// console.log("Req Auth Resp: " + body.requestData);
|
||||
|
||||
if (auth2v2responseSetData[0] != 0x43) {
|
||||
result = {
|
||||
code: '5003',
|
||||
message: 'Wrong Respone from Card',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CLEAR CARD KATEGORI PEGAWAI-3 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
}
|
||||
|
||||
let apiId = Buffer.from([0x03]);
|
||||
let reqData = generate.makeRequestData(
|
||||
transactionId,
|
||||
apiId,
|
||||
auth2v2responseSetData
|
||||
);
|
||||
|
||||
useClient.sendData(reqData);
|
||||
|
||||
let respData = null;
|
||||
let respData1 = null;
|
||||
|
||||
useClient.ws.on('message', (message) => {
|
||||
while (
|
||||
message[2] == 3 &&
|
||||
message[0] == transactionId[0] &&
|
||||
message[1] == transactionId[1] &&
|
||||
_stopMessage == 1
|
||||
) {
|
||||
respData = null;
|
||||
// console.log("*WS MESSAGE auth2v2 Resp: " + generate.buf2hex(message));
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING CLEAR CARD KATEGORI PEGAWAI-3 ]: message from HSM ${generate.buf2hex(
|
||||
message
|
||||
)}`
|
||||
);
|
||||
|
||||
respData = message;
|
||||
_stopMessage = 2;
|
||||
}
|
||||
});
|
||||
|
||||
while (respData == null) {
|
||||
await _sleep(10);
|
||||
}
|
||||
|
||||
_stopMessage = 0;
|
||||
|
||||
transactionId[0] = respData[0];
|
||||
transactionId[1] = respData[1];
|
||||
respCode = generate.getResponseCode(respData);
|
||||
respData1 = generate.getResponseData(respData);
|
||||
|
||||
result = {
|
||||
code: '00',
|
||||
message: 'Request Authenticate Resp Success',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respCode,
|
||||
responseData: respData1,
|
||||
responseLength: respData1.length / 2,
|
||||
},
|
||||
};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ RESPONSE CLEAR CARD KATEGORI PEGAWAI-3 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`[ RESPONSE CLEAR CARD KATEGORI PEGAWAI-3 ]: 500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
code: '5001',
|
||||
message:
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = controller;
|
||||
@@ -0,0 +1,146 @@
|
||||
const winston = require('../../../helpers/winston.logger');
|
||||
const generate = require('../utils/utils');
|
||||
const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
require('dotenv').config();
|
||||
|
||||
let useClient;
|
||||
|
||||
// set connection HSM server
|
||||
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');
|
||||
|
||||
useClient = client2;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
var { client } = require('../services/webSocket');
|
||||
var { client2 } = require('../services/webSocket2');
|
||||
}
|
||||
|
||||
const controller = async (req, res) => {
|
||||
try {
|
||||
let { body } = req;
|
||||
let uniqueCode = body.unique_code;
|
||||
let result = {};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ REQUEST CLEAR CARD KATEGORI PEGAWAI-4 ]: ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
// set request to HSM server 2
|
||||
if (uniqueCode) {
|
||||
if (parseInt(uniqueCode) % 2 == 0) {
|
||||
// create log
|
||||
// winston.logger.error(`request to HSM server 2`);
|
||||
|
||||
if (client2.clientAuthenticated == false) {
|
||||
useClient = client;
|
||||
} else {
|
||||
useClient = client2;
|
||||
}
|
||||
} else {
|
||||
if (client.clientAuthenticated == false) {
|
||||
useClient = client2;
|
||||
} else {
|
||||
useClient = client;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let transactionId = Buffer.from(generate.hexToBytes(body.trxID));
|
||||
let trxrequestData = Buffer.from(generate.hexToBytes(body.requestData));
|
||||
let _stopMessage = 1;
|
||||
|
||||
let apiId = Buffer.from([0x04]);
|
||||
let reqData = generate.makeRequestData(
|
||||
transactionId,
|
||||
apiId,
|
||||
trxrequestData
|
||||
);
|
||||
|
||||
useClient.sendData(reqData);
|
||||
|
||||
let respCode = null;
|
||||
let respData = null;
|
||||
let respData1 = null;
|
||||
|
||||
useClient.ws.on('message', (message) => {
|
||||
while (
|
||||
message[2] == 4 &&
|
||||
message[0] == transactionId[0] &&
|
||||
message[1] == transactionId[1] &&
|
||||
_stopMessage == 1
|
||||
) {
|
||||
respData = null;
|
||||
// console.log(
|
||||
// "*WS MESSAGE Transmit Packet: " + generate.buf2hex(message)
|
||||
// );
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING CLEAR CARD KATEGORI PEGAWAI-4 ]: message from HSM ${generate.buf2hex(
|
||||
message
|
||||
)}`
|
||||
);
|
||||
|
||||
respData = message;
|
||||
_stopMessage = 2;
|
||||
}
|
||||
});
|
||||
|
||||
while (respData == null) {
|
||||
await _sleep(10);
|
||||
}
|
||||
|
||||
_stopMessage = 0;
|
||||
|
||||
transactionId[0] = respData[0];
|
||||
transactionId[1] = respData[1];
|
||||
respCode = generate.getResponseCode(respData);
|
||||
respData1 = generate.getResponseData(respData);
|
||||
|
||||
result = {
|
||||
code: '00',
|
||||
message: 'Read Succeess',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respCode,
|
||||
responseData: respData1,
|
||||
responseLength: respData1.length / 2,
|
||||
},
|
||||
};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ RESPONSE CLEAR CARD KATEGORI PEGAWAI-4 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`[ RESPONSE CLEAR CARD KATEGORI PEGAWAI-4 ]: 500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
code: '5001',
|
||||
message:
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = controller;
|
||||
@@ -0,0 +1,157 @@
|
||||
const winston = require('../../../helpers/winston.logger');
|
||||
const generate = require('../utils/utils');
|
||||
const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
require('dotenv').config();
|
||||
|
||||
let useClient;
|
||||
|
||||
// set connection HSM server
|
||||
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');
|
||||
|
||||
useClient = client2;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
var { client } = require('../services/webSocket');
|
||||
var { client2 } = require('../services/webSocket2');
|
||||
}
|
||||
|
||||
const controller = async (req, res) => {
|
||||
try {
|
||||
let { body } = req;
|
||||
let uniqueCode = body.unique_code;
|
||||
let result = {};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ REQUEST CLEAR CARD KATEGORI PEGAWAI-5 ]: ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
// set request to HSM server 2
|
||||
if (uniqueCode) {
|
||||
if (parseInt(uniqueCode) % 2 == 0) {
|
||||
// create log
|
||||
// winston.logger.error(`request to HSM server 2`);
|
||||
|
||||
if (client2.clientAuthenticated == false) {
|
||||
useClient = client;
|
||||
} else {
|
||||
useClient = client2;
|
||||
}
|
||||
} else {
|
||||
if (client.clientAuthenticated == false) {
|
||||
useClient = client2;
|
||||
} else {
|
||||
useClient = client;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let transactionId = Buffer.from(generate.hexToBytes(body.trxID));
|
||||
let packet = Buffer.from(generate.hexToBytes(body.requestData));
|
||||
let _stopMessage = 1;
|
||||
if (packet[0] != 0x45) {
|
||||
result = {
|
||||
code: '03',
|
||||
message: 'Respone Card Wrong',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CLEAR CARD KATEGORI PEGAWAI-5 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
}
|
||||
|
||||
let apiId = Buffer.from([0x05]);
|
||||
let reqData = generate.makeRequestData(transactionId, apiId, packet);
|
||||
useClient.sendData(reqData);
|
||||
|
||||
let respCode = null;
|
||||
let respData = null;
|
||||
let respData1 = null;
|
||||
|
||||
useClient.ws.on('message', (message) => {
|
||||
while (
|
||||
message[2] == 5 &&
|
||||
message[0] == transactionId[0] &&
|
||||
message[1] == transactionId[1] &&
|
||||
_stopMessage == 1
|
||||
) {
|
||||
respData = null;
|
||||
// console.log(
|
||||
// "*WS MESSAGE Received Packet: " + generate.buf2hex(message)
|
||||
// );
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING CLEAR CARD KATEGORI PEGAWAI-5 ]: message from HSM ${generate.buf2hex(
|
||||
message
|
||||
)}`
|
||||
);
|
||||
|
||||
respData = message;
|
||||
_stopMessage = 2;
|
||||
}
|
||||
});
|
||||
|
||||
while (respData == null) {
|
||||
await _sleep(10);
|
||||
}
|
||||
|
||||
_stopMessage = 0;
|
||||
|
||||
transactionId[0] = respData[0];
|
||||
transactionId[1] = respData[1];
|
||||
respCode = generate.getResponseCode(respData);
|
||||
respData1 = generate.getResponseData(respData);
|
||||
|
||||
result = {
|
||||
code: '00',
|
||||
message: 'Read Succeess',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respCode,
|
||||
responseData: respData1,
|
||||
responseLength: respData1.length / 2,
|
||||
},
|
||||
};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ RESPONSE CLEAR CARD KATEGORI PEGAWAI-5 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`[ RESPONSE CLEAR CARD KATEGORI PEGAWAI-5 ]: 500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
code: '5001',
|
||||
message:
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = controller;
|
||||
@@ -0,0 +1,184 @@
|
||||
const { param, body, validationResult } = require('express-validator');
|
||||
const winston = require('../../../helpers/winston.logger');
|
||||
const generate = require('../utils/utils');
|
||||
const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
require('dotenv').config();
|
||||
|
||||
let useClient;
|
||||
|
||||
// set connection HSM server
|
||||
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');
|
||||
|
||||
useClient = client2;
|
||||
} 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 'clear':
|
||||
return [
|
||||
body('mid').not().isEmpty().withMessage('MID is required'),
|
||||
body('tid').not().isEmpty().withMessage('TID is required'),
|
||||
];
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
const controller = async (req, res) => {
|
||||
try {
|
||||
// param
|
||||
let { mid, tid, unique_code, trxID, requestData } = req.body;
|
||||
|
||||
let uniqueCode = unique_code;
|
||||
let result = {};
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
// set request to HSM server 2
|
||||
if (uniqueCode) {
|
||||
if (parseInt(uniqueCode) % 2 == 0) {
|
||||
// create log
|
||||
// winston.logger.error(`request to HSM server 2`);
|
||||
|
||||
if (client2.clientAuthenticated == false) {
|
||||
useClient = client;
|
||||
} else {
|
||||
useClient = client2;
|
||||
}
|
||||
} else {
|
||||
if (client.clientAuthenticated == false) {
|
||||
useClient = client2;
|
||||
} else {
|
||||
useClient = client;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ REQUEST CLEAR CARD KATEGORI PEGAWAI-6 ]: ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
|
||||
// check validator
|
||||
let err = validationResult(req, res);
|
||||
if (!err.isEmpty()) {
|
||||
result = {
|
||||
code: '400',
|
||||
message: err.errors[0].msg,
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CLEAR CARD KATEGORI PEGAWAI-6 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
let transactionId = Buffer.from(generate.hexToBytes(trxID));
|
||||
let trxrequestData = Buffer.from(generate.hexToBytes(requestData));
|
||||
let _stopMessage = 1;
|
||||
|
||||
let apiId = Buffer.from([0x04]);
|
||||
let reqData = generate.makeRequestData(
|
||||
transactionId,
|
||||
apiId,
|
||||
trxrequestData
|
||||
);
|
||||
|
||||
useClient.sendData(reqData);
|
||||
|
||||
let respCode = null;
|
||||
let respData = null;
|
||||
let respData1 = null;
|
||||
|
||||
useClient.ws.on('message', (message) => {
|
||||
while (
|
||||
message[2] == 4 &&
|
||||
message[0] == transactionId[0] &&
|
||||
message[1] == transactionId[1] &&
|
||||
_stopMessage == 1
|
||||
) {
|
||||
respData = null;
|
||||
// console.log(
|
||||
// "*WS MESSAGE Transmit Packet: " + generate.buf2hex(message)
|
||||
// );
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING CLEAR CARD KATEGORI PEGAWAI-6 ]: message from HSM ${generate.buf2hex(
|
||||
message
|
||||
)}`
|
||||
);
|
||||
|
||||
respData = message;
|
||||
_stopMessage = 2;
|
||||
}
|
||||
});
|
||||
|
||||
while (respData == null) {
|
||||
await _sleep(10);
|
||||
}
|
||||
|
||||
_stopMessage = 0;
|
||||
|
||||
transactionId[0] = respData[0];
|
||||
transactionId[1] = respData[1];
|
||||
respCode = generate.getResponseCode(respData);
|
||||
respData1 = generate.getResponseData(respData);
|
||||
|
||||
result = {
|
||||
code: '00',
|
||||
message: 'Cleared Succeess',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respCode,
|
||||
responseData: respData1,
|
||||
responseLength: respData1.length / 2,
|
||||
},
|
||||
};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ RESPONSE CLEAR CARD KATEGORI PEGAWAI-6 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`[ RESPONSE CLEAR CARD KATEGORI PEGAWAI-6 ]: 500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
code: '5001',
|
||||
message:
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
validate,
|
||||
controller,
|
||||
};
|
||||
@@ -0,0 +1,210 @@
|
||||
const { param, body, validationResult } = require('express-validator');
|
||||
const winston = require('../../../helpers/winston.logger');
|
||||
const generate = require('../utils/utils');
|
||||
const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
require('dotenv').config();
|
||||
|
||||
let useClient;
|
||||
|
||||
// set connection HSM server
|
||||
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');
|
||||
|
||||
useClient = client2;
|
||||
} 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 'clearResponse':
|
||||
return [
|
||||
body('mid').not().isEmpty().withMessage('MID is required'),
|
||||
body('tid').not().isEmpty().withMessage('TID is required'),
|
||||
];
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
const controller = async (req, res) => {
|
||||
try {
|
||||
// param
|
||||
let { mid, tid, unique_code, trxID, requestData } = req.body;
|
||||
|
||||
let uniqueCode = unique_code;
|
||||
let result = {};
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
// set request to HSM server 2
|
||||
if (uniqueCode) {
|
||||
if (parseInt(uniqueCode) % 2 == 0) {
|
||||
// create log
|
||||
// winston.logger.error(`request to HSM server 2`);
|
||||
|
||||
if (client2.clientAuthenticated == false) {
|
||||
useClient = client;
|
||||
} else {
|
||||
useClient = client2;
|
||||
}
|
||||
} else {
|
||||
if (client.clientAuthenticated == false) {
|
||||
useClient = client2;
|
||||
} else {
|
||||
useClient = client;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// case success write to the card but loss contact with device
|
||||
// result = {
|
||||
// code: "100",
|
||||
// message: "failed clear",
|
||||
// data: {},
|
||||
// };
|
||||
// return res.status(200).send(result);
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ REQUEST CLEAR CARD KATEGORI PEGAWAI-7 ]: ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
|
||||
let transactionId = Buffer.from(generate.hexToBytes(trxID));
|
||||
let packet = Buffer.from(generate.hexToBytes(requestData));
|
||||
let _stopMessage = 1;
|
||||
if (packet[0] != 0x47) {
|
||||
result = {
|
||||
code: '03',
|
||||
message: 'Respone Card Wrong',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CLEAR CARD KATEGORI PEGAWAI-7 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
}
|
||||
|
||||
let apiId = Buffer.from([0x05]);
|
||||
let reqData = generate.makeRequestData(transactionId, apiId, packet);
|
||||
useClient.sendData(reqData);
|
||||
|
||||
let respCode = null;
|
||||
let respData = null;
|
||||
let respData1 = null;
|
||||
|
||||
useClient.ws.on('message', (message) => {
|
||||
while (
|
||||
message[2] == 5 &&
|
||||
message[0] == transactionId[0] &&
|
||||
message[1] == transactionId[1] &&
|
||||
_stopMessage == 1
|
||||
) {
|
||||
respData = null;
|
||||
// console.log(
|
||||
// "*WS MESSAGE Received Packet: " + generate.buf2hex(message)
|
||||
// );
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING CLEAR CARD KATEGORI PEGAWAI-7 ]: message from HSM ${generate.buf2hex(
|
||||
message
|
||||
)}`
|
||||
);
|
||||
|
||||
respData = message;
|
||||
_stopMessage = 2;
|
||||
}
|
||||
});
|
||||
|
||||
while (respData == null) {
|
||||
await _sleep(10);
|
||||
}
|
||||
|
||||
_stopMessage = 0;
|
||||
|
||||
transactionId[0] = respData[0];
|
||||
transactionId[1] = respData[1];
|
||||
respCode = generate.getResponseCode(respData);
|
||||
respData1 = generate.getResponseData(respData);
|
||||
|
||||
let data = {};
|
||||
|
||||
if (
|
||||
respData[6] != 0x47 ||
|
||||
(respData1[9] != 0x00 && respData1[10] != 0x00)
|
||||
) {
|
||||
data = {
|
||||
mid: mid,
|
||||
tid: tid,
|
||||
unique_code: unique_code,
|
||||
};
|
||||
|
||||
result = {
|
||||
code: '5002',
|
||||
message: 'failed from HSM',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respData1.slice(6, 10),
|
||||
transcode: null,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
data = {
|
||||
mid: mid,
|
||||
tid: tid,
|
||||
unique_code: unique_code,
|
||||
};
|
||||
|
||||
result = {
|
||||
code: '00',
|
||||
message: 'Cleared Response Succeess',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respCode,
|
||||
responseData: respData1,
|
||||
responseLength: respData1.length / 2,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ RESPONSE CLEAR CARD KATEGORI PEGAWAI-7 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`[ RESPONSE CLEAR CARD KATEGORI PEGAWAI-7 ]: 500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
code: '5001',
|
||||
message:
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { validate, controller };
|
||||
@@ -0,0 +1,142 @@
|
||||
const winston = require('../../../helpers/winston.logger');
|
||||
const generate = require('../utils/utils');
|
||||
const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
require('dotenv').config();
|
||||
|
||||
let useClient;
|
||||
|
||||
// set connection HSM server
|
||||
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');
|
||||
|
||||
useClient = client2;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
var { client } = require('../services/webSocket');
|
||||
var { client2 } = require('../services/webSocket2');
|
||||
}
|
||||
|
||||
const controller = async (req, res) => {
|
||||
try {
|
||||
let { body } = req;
|
||||
let uniqueCode = body.unique_code;
|
||||
let result = {};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ REQUEST CLEAR CARD KATEGORI PEGAWAI-8 ]: ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
// set request to HSM server 2
|
||||
if (uniqueCode) {
|
||||
if (parseInt(uniqueCode) % 2 == 0) {
|
||||
// create log
|
||||
// winston.logger.error(`request to HSM server 2`);
|
||||
|
||||
if (client2.clientAuthenticated == false) {
|
||||
useClient = client;
|
||||
} else {
|
||||
useClient = client2;
|
||||
}
|
||||
} else {
|
||||
if (client.clientAuthenticated == false) {
|
||||
useClient = client2;
|
||||
} else {
|
||||
useClient = client;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let transactionId = Buffer.from(generate.hexToBytes(body.trxID));
|
||||
|
||||
let transactionEnd = Buffer.from([]);
|
||||
let apiId = Buffer.from([0x06]);
|
||||
let reqData = generate.makeRequestData(
|
||||
transactionId,
|
||||
apiId,
|
||||
transactionEnd
|
||||
);
|
||||
let _stopMessage = 1;
|
||||
|
||||
useClient.sendData(reqData);
|
||||
|
||||
let respCode = null;
|
||||
let respData = null;
|
||||
let respData1 = null;
|
||||
|
||||
useClient.ws.on('message', (message) => {
|
||||
while (
|
||||
message[2] == 6 &&
|
||||
message[0] == transactionId[0] &&
|
||||
message[1] == transactionId[1] &&
|
||||
_stopMessage == 1
|
||||
) {
|
||||
respData = null;
|
||||
// console.log("*WS MESSAGE EndTrx: " + generate.buf2hex(message));
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING CLEAR CARD KATEGORI PEGAWAI-8 ]: message from HSM ${generate.buf2hex(
|
||||
message
|
||||
)}`
|
||||
);
|
||||
|
||||
respData = message;
|
||||
_stopMessage = 2;
|
||||
}
|
||||
});
|
||||
|
||||
while (respData == null) {
|
||||
await _sleep(10);
|
||||
}
|
||||
|
||||
_stopMessage = 0;
|
||||
|
||||
transactionId[0] = respData[0];
|
||||
transactionId[1] = respData[1];
|
||||
respCode = generate.getResponseCode(respData);
|
||||
respData1 = generate.getResponseData(respData);
|
||||
|
||||
result = {
|
||||
code: '00',
|
||||
message: 'End Transaction Success',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respCode,
|
||||
},
|
||||
};
|
||||
|
||||
// log debug
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ RESPONSE CLEAR CARD KATEGORI PEGAWAI-8 ]: ENDING TOP UP... ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`[ RESPONSE CLEAR CARD KATEGORI PEGAWAI-8 ]: 500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
code: '5001',
|
||||
message:
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = controller;
|
||||
@@ -0,0 +1,51 @@
|
||||
const winston = require('../../../helpers/winston.logger');
|
||||
require('dotenv').config();
|
||||
|
||||
// Get Service Code, Block, dan System Code
|
||||
const controller = async (req, res) => {
|
||||
try {
|
||||
// check service block
|
||||
if (
|
||||
process.env.SERVICEBLOCK_SERVICE_MUTUAL == '' ||
|
||||
process.env.SERVICEBLOCK_BLOCK_READ == '' ||
|
||||
process.env.SERVICEBLOCK_BLOCK_WRITE == ''
|
||||
) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`PLEASE CONFIGURE SERVICE BLOCK ON THE ENVIRONMENT!`
|
||||
);
|
||||
}
|
||||
|
||||
let sytemCode = '939E';
|
||||
let serviceReadNS = '4B1017208B20';
|
||||
let blockReadNS = '800081008200';
|
||||
let serviceMutual = process.env.SERVICEBLOCK_SERVICE_MUTUAL;
|
||||
let blockReadS = process.env.SERVICEBLOCK_BLOCK_READ;
|
||||
let blockWrite = process.env.SERVICEBLOCK_BLOCK_WRITE;
|
||||
let locFlag = 15;
|
||||
return res.status(200).send({
|
||||
code: '00',
|
||||
message: 'Get Service Succeess',
|
||||
data: {
|
||||
sysCode: sytemCode,
|
||||
sReadNS: serviceReadNS,
|
||||
sMutual: serviceMutual,
|
||||
bReadNS: blockReadNS,
|
||||
bReadS: blockReadS,
|
||||
bWrite: blockWrite,
|
||||
lFlag: locFlag,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
return res.json({
|
||||
code: '5001',
|
||||
message:
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = controller;
|
||||
@@ -0,0 +1,51 @@
|
||||
const winston = require('../../../helpers/winston.logger');
|
||||
require('dotenv').config();
|
||||
|
||||
// Get Service Code, Block, dan System Code
|
||||
const controller = async (req, res) => {
|
||||
try {
|
||||
// check service block
|
||||
if (
|
||||
process.env.SERVICEBLOCK_SERVICE_MUTUAL == '' ||
|
||||
process.env.SERVICEBLOCK_BLOCK_READ == '' ||
|
||||
process.env.SERVICEBLOCK_BLOCK_WRITE == ''
|
||||
) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`PLEASE CONFIGURE SERVICE BLOCK ON THE ENVIRONMENT!`
|
||||
);
|
||||
}
|
||||
|
||||
let sytemCode = '939E';
|
||||
let serviceReadNS = '4B1017208B20';
|
||||
let blockReadNS = '800081008200';
|
||||
let serviceMutual = process.env.SERVICEBLOCK_SERVICE_MUTUAL;
|
||||
let blockReadS = process.env.SERVICEBLOCK_BLOCK_READ;
|
||||
let blockWrite = process.env.SERVICEBLOCK_BLOCK_WRITE;
|
||||
let locFlag = 15;
|
||||
return res.status(200).send({
|
||||
code: '00',
|
||||
message: 'Get Service Succeess',
|
||||
data: {
|
||||
sysCode: sytemCode,
|
||||
sReadNS: serviceReadNS,
|
||||
sMutual: serviceMutual,
|
||||
bReadNS: blockReadNS,
|
||||
bReadS: blockReadS,
|
||||
bWrite: blockWrite,
|
||||
lFlag: locFlag,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
return res.json({
|
||||
code: '5001',
|
||||
message:
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = controller;
|
||||
@@ -0,0 +1,233 @@
|
||||
const { default: axios } = require('axios');
|
||||
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();
|
||||
|
||||
let useClient;
|
||||
var counterDirect = 0;
|
||||
|
||||
// set connection HSM server
|
||||
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');
|
||||
|
||||
useClient = client2;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
var { client } = require('../services/webSocket');
|
||||
var { client2 } = require('../services/webSocket2');
|
||||
}
|
||||
|
||||
const controller = async (req, res) => {
|
||||
try {
|
||||
if (counterDirect > 1 || counterDirect < 0) {
|
||||
counterDirect = 0;
|
||||
}
|
||||
counterDirect++;
|
||||
|
||||
let { body } = req;
|
||||
// uniqueCode = body.unique_code;
|
||||
let uniqueCode = await helper.getUniqueCode();
|
||||
uniqueCode = uniqueCode + '' + counterDirect;
|
||||
let result = {};
|
||||
let usingHSMNumber = 1;
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
// set request to HSM server 2
|
||||
if (uniqueCode) {
|
||||
if (parseInt(uniqueCode) % 2 == 0) {
|
||||
// create log
|
||||
// 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 ==================================}`
|
||||
);
|
||||
useClient = client2;
|
||||
}
|
||||
} 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 ==================================}`
|
||||
);
|
||||
useClient = client;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ REQUEST LOADING-BALANCE TOPUP-1 ]: STARTING TOP UP...`
|
||||
);
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE TOPUP-1 ]: ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
|
||||
let felicaPollingResponse = Buffer.from(
|
||||
generate.hexToBytes(body.requestData)
|
||||
);
|
||||
let _stopMessage = 1;
|
||||
let _timeOut = false;
|
||||
|
||||
let _validasi = body.requestData.slice(4, 20);
|
||||
|
||||
let transactionId = Buffer.from([0x00, 0x00]);
|
||||
let apiId = Buffer.from([0x01]);
|
||||
reqData = generate.makeRequestData(
|
||||
transactionId,
|
||||
apiId,
|
||||
felicaPollingResponse
|
||||
);
|
||||
|
||||
useClient.sendData(reqData);
|
||||
|
||||
let respData = null;
|
||||
let respData1 = null;
|
||||
|
||||
setInterval(function () {
|
||||
respData = Buffer.from([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
|
||||
_timeOut = true;
|
||||
}, 10000);
|
||||
|
||||
useClient.ws.on('message', (message) => {
|
||||
let __validasi = generate.buf2hex(message).slice(14, 30);
|
||||
while (
|
||||
message[2] == 1 &&
|
||||
_stopMessage == 1 &&
|
||||
_validasi.toLowerCase() == __validasi.toLowerCase()
|
||||
) {
|
||||
respData = null;
|
||||
// console.log('*WS MESSAGE Auth1v2: ' + generate.buf2hex(message));
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE TOPUP-1 ]: message from HSM ${generate.buf2hex(
|
||||
message
|
||||
)}`
|
||||
);
|
||||
|
||||
respData = message;
|
||||
_stopMessage = 2;
|
||||
}
|
||||
});
|
||||
|
||||
while (respData == null) {
|
||||
await _sleep(10);
|
||||
}
|
||||
|
||||
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`;
|
||||
}
|
||||
|
||||
let response = await axios({
|
||||
url: url,
|
||||
method: 'get',
|
||||
});
|
||||
|
||||
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;
|
||||
|
||||
transactionId[0] = respData[0];
|
||||
transactionId[1] = respData[1];
|
||||
respCode = generate.getResponseCode(respData);
|
||||
respData1 = generate.getResponseData(respData);
|
||||
|
||||
if (respData1) {
|
||||
result = {
|
||||
code: '00',
|
||||
message: 'Request Authenticate 1 Success',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respCode,
|
||||
responseData: respData1,
|
||||
responseLength: respData1.length / 2,
|
||||
unique_code: uniqueCode,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
result = {
|
||||
code: '5004',
|
||||
message: 'Empty Data from HSM',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respCode,
|
||||
responseData: respData1,
|
||||
responseLength: respData1.length / 2,
|
||||
unique_code: uniqueCode,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE TOPUP-1 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`[ RESPONSE LOADING-BALANCE TOPUP-1 ]: 500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
code: '5001',
|
||||
message:
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = controller;
|
||||
@@ -0,0 +1,184 @@
|
||||
const winston = require('../../../helpers/winston.logger');
|
||||
const generate = require('../utils/utils');
|
||||
const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
require('dotenv').config();
|
||||
|
||||
let useClient;
|
||||
|
||||
// set connection HSM server
|
||||
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');
|
||||
|
||||
useClient = client2;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
var { client } = require('../services/webSocket');
|
||||
var { client2 } = require('../services/webSocket2');
|
||||
}
|
||||
|
||||
const controller = async (req, res) => {
|
||||
try {
|
||||
let { body } = req;
|
||||
let uniqueCode = body.unique_code;
|
||||
let result = {};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ REQUEST LOADING-BALANCE TOPUP-2 ]: ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
// set request to HSM server 2
|
||||
if (uniqueCode) {
|
||||
if (parseInt(uniqueCode) % 2 == 0) {
|
||||
// create log
|
||||
// winston.logger.error(`request to HSM server 2`);
|
||||
|
||||
if (client2.clientAuthenticated == false) {
|
||||
useClient = client;
|
||||
} else {
|
||||
useClient = client2;
|
||||
}
|
||||
} else {
|
||||
if (client.clientAuthenticated == false) {
|
||||
useClient = client2;
|
||||
} else {
|
||||
useClient = client;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let transactionId = Buffer.from(generate.hexToBytes(body.trxID));
|
||||
let _validationTrxID = Buffer.from(generate.hexToBytes(body.trxID));
|
||||
let auth2v2requestData = Buffer.from(generate.hexToBytes(body.requestData));
|
||||
let _stopMessage = 1;
|
||||
let _timeOut = false;
|
||||
|
||||
if (auth2v2requestData[0] != 0x41) {
|
||||
result = {
|
||||
code: '5003',
|
||||
message: 'Wrong Respone from Card',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE TOPUP-2 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
}
|
||||
|
||||
let apiId = Buffer.from([0x02]);
|
||||
let reqData = generate.makeRequestData(
|
||||
transactionId,
|
||||
apiId,
|
||||
auth2v2requestData
|
||||
);
|
||||
|
||||
useClient.sendData(reqData);
|
||||
|
||||
let respData = null;
|
||||
let respData1 = null;
|
||||
|
||||
setInterval(function () {
|
||||
respData = Buffer.from([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
|
||||
_timeOut = true;
|
||||
}, 10000);
|
||||
|
||||
useClient.ws.on('message', (message) => {
|
||||
while (
|
||||
message[2] == 2 &&
|
||||
message[0] == _validationTrxID[0] &&
|
||||
message[1] == _validationTrxID[1] &&
|
||||
_stopMessage == 1
|
||||
) {
|
||||
respData = null;
|
||||
// console.log("*WS MESSAGE Auth2v2: " + generate.buf2hex(message));
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE TOPUP-2 ]: message from HSM ${generate.buf2hex(
|
||||
message
|
||||
)}`
|
||||
);
|
||||
|
||||
respData = message;
|
||||
_stopMessage = 2;
|
||||
}
|
||||
});
|
||||
|
||||
while (respData == null) {
|
||||
await _sleep(10);
|
||||
}
|
||||
|
||||
if (_timeOut) {
|
||||
result = {
|
||||
code: '5001',
|
||||
message: 'Timeout',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE TOPUP-2 ]: message from HSM ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
}
|
||||
|
||||
_stopMessage = 0;
|
||||
|
||||
transactionId[0] = respData[0];
|
||||
transactionId[1] = respData[1];
|
||||
respCode = generate.getResponseCode(respData);
|
||||
respData1 = generate.getResponseData(respData);
|
||||
|
||||
result = {
|
||||
code: '00',
|
||||
message: 'Request Authenticate 2 Success',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respCode,
|
||||
responseData: respData1,
|
||||
responseLength: respData1.length / 2,
|
||||
},
|
||||
};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE TOPUP-2 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`[ RESPONSE LOADING-BALANCE TOPUP-2 ]: 500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
code: '5001',
|
||||
message:
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = controller;
|
||||
@@ -0,0 +1,163 @@
|
||||
const winston = require('../../../helpers/winston.logger');
|
||||
const generate = require('../utils/utils');
|
||||
const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
require('dotenv').config();
|
||||
|
||||
let useClient;
|
||||
|
||||
// set connection HSM server
|
||||
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');
|
||||
|
||||
useClient = client2;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
var { client } = require('../services/webSocket');
|
||||
var { client2 } = require('../services/webSocket2');
|
||||
}
|
||||
|
||||
const controller = async (req, res) => {
|
||||
try {
|
||||
let { body } = req;
|
||||
let uniqueCode = body.unique_code;
|
||||
let result = {};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ REQUEST LOADING-BALANCE TOPUP-3 ]: request to HSM ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
// set request to HSM server 2
|
||||
if (uniqueCode) {
|
||||
if (parseInt(uniqueCode) % 2 == 0) {
|
||||
// create log
|
||||
// winston.logger.error(`request to HSM server 2`);
|
||||
|
||||
if (client2.clientAuthenticated == false) {
|
||||
useClient = client;
|
||||
} else {
|
||||
useClient = client2;
|
||||
}
|
||||
} else {
|
||||
if (client.clientAuthenticated == false) {
|
||||
useClient = client2;
|
||||
} else {
|
||||
useClient = client;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let transactionId = Buffer.from(generate.hexToBytes(body.trxID));
|
||||
let auth2v2responseSetData = Buffer.from(
|
||||
generate.hexToBytes(body.requestData)
|
||||
);
|
||||
let _stopMessage = 1;
|
||||
// console.log("Req Auth Resp: " + body.requestData);
|
||||
|
||||
if (auth2v2responseSetData[0] != 0x43) {
|
||||
result = {
|
||||
code: '5003',
|
||||
message: 'Wrong Respone from Card',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE TOPUP-3 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
}
|
||||
|
||||
let apiId = Buffer.from([0x03]);
|
||||
let reqData = generate.makeRequestData(
|
||||
transactionId,
|
||||
apiId,
|
||||
auth2v2responseSetData
|
||||
);
|
||||
|
||||
useClient.sendData(reqData);
|
||||
|
||||
let respData = null;
|
||||
let respData1 = null;
|
||||
|
||||
useClient.ws.on('message', (message) => {
|
||||
while (
|
||||
message[2] == 3 &&
|
||||
message[0] == transactionId[0] &&
|
||||
message[1] == transactionId[1] &&
|
||||
_stopMessage == 1
|
||||
) {
|
||||
respData = null;
|
||||
// console.log("*WS MESSAGE auth2v2 Resp: " + generate.buf2hex(message));
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE TOPUP-3 ]: message from HSM ${generate.buf2hex(
|
||||
message
|
||||
)}`
|
||||
);
|
||||
|
||||
respData = message;
|
||||
_stopMessage = 2;
|
||||
}
|
||||
});
|
||||
|
||||
while (respData == null) {
|
||||
await _sleep(10);
|
||||
}
|
||||
|
||||
_stopMessage = 0;
|
||||
|
||||
transactionId[0] = respData[0];
|
||||
transactionId[1] = respData[1];
|
||||
respCode = generate.getResponseCode(respData);
|
||||
respData1 = generate.getResponseData(respData);
|
||||
|
||||
result = {
|
||||
code: '00',
|
||||
message: 'Request Authenticate Resp Success',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respCode,
|
||||
responseData: respData1,
|
||||
responseLength: respData1.length / 2,
|
||||
},
|
||||
};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE TOPUP-3 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`[ RESPONSE LOADING-BALANCE TOPUP-3 ]: 500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
code: '5001',
|
||||
message:
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = controller;
|
||||
@@ -0,0 +1,146 @@
|
||||
const winston = require('../../../helpers/winston.logger');
|
||||
const generate = require('../utils/utils');
|
||||
const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
require('dotenv').config();
|
||||
|
||||
let useClient;
|
||||
|
||||
// set connection HSM server
|
||||
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');
|
||||
|
||||
useClient = client2;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
var { client } = require('../services/webSocket');
|
||||
var { client2 } = require('../services/webSocket2');
|
||||
}
|
||||
|
||||
const controller = async (req, res) => {
|
||||
try {
|
||||
let { body } = req;
|
||||
let uniqueCode = body.unique_code;
|
||||
let result = {};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ REQUEST LOADING-BALANCE TOPUP-4 ]: ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
// set request to HSM server 2
|
||||
if (uniqueCode) {
|
||||
if (parseInt(uniqueCode) % 2 == 0) {
|
||||
// create log
|
||||
// winston.logger.error(`request to HSM server 2`);
|
||||
|
||||
if (client2.clientAuthenticated == false) {
|
||||
useClient = client;
|
||||
} else {
|
||||
useClient = client2;
|
||||
}
|
||||
} else {
|
||||
if (client.clientAuthenticated == false) {
|
||||
useClient = client2;
|
||||
} else {
|
||||
useClient = client;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let transactionId = Buffer.from(generate.hexToBytes(body.trxID));
|
||||
let trxrequestData = Buffer.from(generate.hexToBytes(body.requestData));
|
||||
let _stopMessage = 1;
|
||||
|
||||
let apiId = Buffer.from([0x04]);
|
||||
let reqData = generate.makeRequestData(
|
||||
transactionId,
|
||||
apiId,
|
||||
trxrequestData
|
||||
);
|
||||
|
||||
useClient.sendData(reqData);
|
||||
|
||||
let respCode = null;
|
||||
let respData = null;
|
||||
let respData1 = null;
|
||||
|
||||
useClient.ws.on('message', (message) => {
|
||||
while (
|
||||
message[2] == 4 &&
|
||||
message[0] == transactionId[0] &&
|
||||
message[1] == transactionId[1] &&
|
||||
_stopMessage == 1
|
||||
) {
|
||||
respData = null;
|
||||
// console.log(
|
||||
// "*WS MESSAGE Transmit Packet: " + generate.buf2hex(message)
|
||||
// );
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE TOPUP-4 ]: message from HSM ${generate.buf2hex(
|
||||
message
|
||||
)}`
|
||||
);
|
||||
|
||||
respData = message;
|
||||
_stopMessage = 2;
|
||||
}
|
||||
});
|
||||
|
||||
while (respData == null) {
|
||||
await _sleep(10);
|
||||
}
|
||||
|
||||
_stopMessage = 0;
|
||||
|
||||
transactionId[0] = respData[0];
|
||||
transactionId[1] = respData[1];
|
||||
respCode = generate.getResponseCode(respData);
|
||||
respData1 = generate.getResponseData(respData);
|
||||
|
||||
result = {
|
||||
code: '00',
|
||||
message: 'Read Succeess',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respCode,
|
||||
responseData: respData1,
|
||||
responseLength: respData1.length / 2,
|
||||
},
|
||||
};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE TOPUP-4 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`[ RESPONSE LOADING-BALANCE TOPUP-4 ]: 500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
code: '5001',
|
||||
message:
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = controller;
|
||||
@@ -0,0 +1,157 @@
|
||||
const winston = require('../../../helpers/winston.logger');
|
||||
const generate = require('../utils/utils');
|
||||
const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
require('dotenv').config();
|
||||
|
||||
let useClient;
|
||||
|
||||
// set connection HSM server
|
||||
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');
|
||||
|
||||
useClient = client2;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
var { client } = require('../services/webSocket');
|
||||
var { client2 } = require('../services/webSocket2');
|
||||
}
|
||||
|
||||
const controller = async (req, res) => {
|
||||
try {
|
||||
let { body } = req;
|
||||
let uniqueCode = body.unique_code;
|
||||
let result = {};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ REQUEST LOADING-BALANCE TOPUP-5 ]: ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
// set request to HSM server 2
|
||||
if (uniqueCode) {
|
||||
if (parseInt(uniqueCode) % 2 == 0) {
|
||||
// create log
|
||||
// winston.logger.error(`request to HSM server 2`);
|
||||
|
||||
if (client2.clientAuthenticated == false) {
|
||||
useClient = client;
|
||||
} else {
|
||||
useClient = client2;
|
||||
}
|
||||
} else {
|
||||
if (client.clientAuthenticated == false) {
|
||||
useClient = client2;
|
||||
} else {
|
||||
useClient = client;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let transactionId = Buffer.from(generate.hexToBytes(body.trxID));
|
||||
let packet = Buffer.from(generate.hexToBytes(body.requestData));
|
||||
let _stopMessage = 1;
|
||||
if (packet[0] != 0x45) {
|
||||
result = {
|
||||
code: '03',
|
||||
message: 'Respone Card Wrong',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE TOPUP-5 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
}
|
||||
|
||||
let apiId = Buffer.from([0x05]);
|
||||
let reqData = generate.makeRequestData(transactionId, apiId, packet);
|
||||
useClient.sendData(reqData);
|
||||
|
||||
let respCode = null;
|
||||
let respData = null;
|
||||
let respData1 = null;
|
||||
|
||||
useClient.ws.on('message', (message) => {
|
||||
while (
|
||||
message[2] == 5 &&
|
||||
message[0] == transactionId[0] &&
|
||||
message[1] == transactionId[1] &&
|
||||
_stopMessage == 1
|
||||
) {
|
||||
respData = null;
|
||||
// console.log(
|
||||
// "*WS MESSAGE Received Packet: " + generate.buf2hex(message)
|
||||
// );
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE TOPUP-5 ]: message from HSM ${generate.buf2hex(
|
||||
message
|
||||
)}`
|
||||
);
|
||||
|
||||
respData = message;
|
||||
_stopMessage = 2;
|
||||
}
|
||||
});
|
||||
|
||||
while (respData == null) {
|
||||
await _sleep(10);
|
||||
}
|
||||
|
||||
_stopMessage = 0;
|
||||
|
||||
transactionId[0] = respData[0];
|
||||
transactionId[1] = respData[1];
|
||||
respCode = generate.getResponseCode(respData);
|
||||
respData1 = generate.getResponseData(respData);
|
||||
|
||||
result = {
|
||||
code: '00',
|
||||
message: 'Read Succeess',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respCode,
|
||||
responseData: respData1,
|
||||
responseLength: respData1.length / 2,
|
||||
},
|
||||
};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE TOPUP-5 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`[ RESPONSE LOADING-BALANCE TOPUP-5 ]: 500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
code: '5001',
|
||||
message:
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = controller;
|
||||
@@ -0,0 +1,265 @@
|
||||
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();
|
||||
|
||||
let useClient;
|
||||
|
||||
// set connection HSM server
|
||||
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');
|
||||
|
||||
useClient = client2;
|
||||
} 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 'topup':
|
||||
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')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Card Number is required'),
|
||||
body('amount')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Amount is required')
|
||||
.isNumeric()
|
||||
.withMessage('Amount is invalid format'),
|
||||
body('reservation_number')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Reservation Number is required')
|
||||
.isArray()
|
||||
.withMessage('Reservation Number is invalid request format'),
|
||||
];
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
const controller = async (req, res) => {
|
||||
try {
|
||||
// param
|
||||
let {
|
||||
mid,
|
||||
tid,
|
||||
card_number,
|
||||
amount,
|
||||
reservation_number,
|
||||
ref_no,
|
||||
write_status,
|
||||
uid,
|
||||
balance,
|
||||
flag,
|
||||
execution_id,
|
||||
unique_code,
|
||||
trxID,
|
||||
requestData,
|
||||
} = req.body;
|
||||
|
||||
let uniqueCode = unique_code;
|
||||
let result = {};
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
// set request to HSM server 2
|
||||
if (uniqueCode) {
|
||||
if (parseInt(uniqueCode) % 2 == 0) {
|
||||
// create log
|
||||
// winston.logger.error(`request to HSM server 2`);
|
||||
|
||||
if (client2.clientAuthenticated == false) {
|
||||
useClient = client;
|
||||
} else {
|
||||
useClient = client2;
|
||||
}
|
||||
} else {
|
||||
if (client.clientAuthenticated == false) {
|
||||
useClient = client2;
|
||||
} else {
|
||||
useClient = client;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ REQUEST LOADING-BALANCE TOPUP-6 ]: ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
|
||||
// check validator
|
||||
let err = validationResult(req, res);
|
||||
if (!err.isEmpty()) {
|
||||
result = {
|
||||
code: '400',
|
||||
message: err.errors[0].msg,
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE TOPUP-6 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
let transactionId = Buffer.from(generate.hexToBytes(trxID));
|
||||
let trxrequestData = Buffer.from(generate.hexToBytes(requestData));
|
||||
let _stopMessage = 1;
|
||||
let execID;
|
||||
if (execution_id) {
|
||||
execID = execution_id;
|
||||
} else {
|
||||
let execByte = Buffer.alloc(2);
|
||||
trxrequestData.copy(execByte, 0, 24, 26);
|
||||
execID = generate.buf2hex(execByte);
|
||||
}
|
||||
|
||||
let apiId = Buffer.from([0x04]);
|
||||
let reqData = generate.makeRequestData(
|
||||
transactionId,
|
||||
apiId,
|
||||
trxrequestData
|
||||
);
|
||||
|
||||
useClient.sendData(reqData);
|
||||
|
||||
let respCode = null;
|
||||
let respData = null;
|
||||
let respData1 = null;
|
||||
|
||||
useClient.ws.on('message', (message) => {
|
||||
while (
|
||||
message[2] == 4 &&
|
||||
message[0] == transactionId[0] &&
|
||||
message[1] == transactionId[1] &&
|
||||
_stopMessage == 1
|
||||
) {
|
||||
respData = null;
|
||||
// console.log(
|
||||
// "*WS MESSAGE Transmit Packet: " + generate.buf2hex(message)
|
||||
// );
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE TOPUP-6 ]: message from HSM ${generate.buf2hex(
|
||||
message
|
||||
)}`
|
||||
);
|
||||
|
||||
respData = message;
|
||||
_stopMessage = 2;
|
||||
}
|
||||
});
|
||||
|
||||
while (respData == null) {
|
||||
await _sleep(10);
|
||||
}
|
||||
|
||||
_stopMessage = 0;
|
||||
|
||||
transactionId[0] = respData[0];
|
||||
transactionId[1] = respData[1];
|
||||
respCode = generate.getResponseCode(respData);
|
||||
respData1 = generate.getResponseData(respData);
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE TOPUP-6 ]: inserting load balance transaction...`
|
||||
);
|
||||
|
||||
let data = {
|
||||
mid: mid,
|
||||
tid: tid,
|
||||
card_number: card_number,
|
||||
amount: amount,
|
||||
reservation_number: reservation_number,
|
||||
ref_no: ref_no,
|
||||
write_status: write_status,
|
||||
uid: uid,
|
||||
balance: balance,
|
||||
flag: flag,
|
||||
unique_code: unique_code,
|
||||
execution_id: execID,
|
||||
};
|
||||
|
||||
// insert data load balance
|
||||
let insert = await loadBalance.loadingBalanceInsert(req, data);
|
||||
if (insert) {
|
||||
if (insert.code == '00') {
|
||||
result = {
|
||||
code: '00',
|
||||
message: 'Generate Write Succeess',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respCode,
|
||||
responseData: respData1,
|
||||
responseLength: respData1.length / 2,
|
||||
load_balance_number: insert.data.load_balance_number,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
result = {
|
||||
code: insert.code,
|
||||
message: insert.message,
|
||||
data: {},
|
||||
};
|
||||
}
|
||||
} else {
|
||||
result = {
|
||||
code: '423',
|
||||
message: 'update/insert failed',
|
||||
data: {},
|
||||
};
|
||||
}
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE TOPUP-6 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`[ RESPONSE LOADING-BALANCE TOPUP-6 ]: 500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
code: '5001',
|
||||
message:
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
validate,
|
||||
controller,
|
||||
};
|
||||
@@ -0,0 +1,318 @@
|
||||
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();
|
||||
|
||||
let useClient;
|
||||
|
||||
// set connection HSM server
|
||||
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');
|
||||
|
||||
useClient = client2;
|
||||
} 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':
|
||||
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')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Card Number is required'),
|
||||
body('amount')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Amount is required')
|
||||
.isNumeric()
|
||||
.withMessage('Amount is invalid format'),
|
||||
body('reservation_number')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Reservation Number is required')
|
||||
.isArray()
|
||||
.withMessage('Reservation Number is invalid request format'),
|
||||
body('load_balance_number')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Load Balance Number is required'),
|
||||
];
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
const controller = async (req, res) => {
|
||||
try {
|
||||
// param
|
||||
let {
|
||||
mid,
|
||||
tid,
|
||||
card_number,
|
||||
amount,
|
||||
reservation_number,
|
||||
ref_no,
|
||||
uid,
|
||||
balance,
|
||||
flag,
|
||||
unique_code,
|
||||
load_balance_number,
|
||||
trxID,
|
||||
requestData,
|
||||
} = req.body;
|
||||
|
||||
let uniqueCode = unique_code;
|
||||
let result = {};
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
// set request to HSM server 2
|
||||
if (uniqueCode) {
|
||||
if (parseInt(uniqueCode) % 2 == 0) {
|
||||
// create log
|
||||
// winston.logger.error(`request to HSM server 2`);
|
||||
|
||||
if (client2.clientAuthenticated == false) {
|
||||
useClient = client;
|
||||
} else {
|
||||
useClient = client2;
|
||||
}
|
||||
} else {
|
||||
if (client.clientAuthenticated == false) {
|
||||
useClient = client2;
|
||||
} else {
|
||||
useClient = client;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// case success write to the card but loss contact with device
|
||||
// result = {
|
||||
// code: "100",
|
||||
// message: "failed topup",
|
||||
// data: {},
|
||||
// };
|
||||
// return res.status(200).send(result);
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ REQUEST LOADING-BALANCE TOPUP-7 ]: ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
|
||||
let transactionId = Buffer.from(generate.hexToBytes(trxID));
|
||||
let packet = Buffer.from(generate.hexToBytes(requestData));
|
||||
let _stopMessage = 1;
|
||||
if (packet[0] != 0x47) {
|
||||
result = {
|
||||
code: '03',
|
||||
message: 'Respone Card Wrong',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE TOPUP-7 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
}
|
||||
|
||||
let apiId = Buffer.from([0x05]);
|
||||
let reqData = generate.makeRequestData(transactionId, apiId, packet);
|
||||
useClient.sendData(reqData);
|
||||
|
||||
let respCode = null;
|
||||
let respData = null;
|
||||
let respData1 = null;
|
||||
|
||||
useClient.ws.on('message', (message) => {
|
||||
while (
|
||||
message[2] == 5 &&
|
||||
message[0] == transactionId[0] &&
|
||||
message[1] == transactionId[1] &&
|
||||
_stopMessage == 1
|
||||
) {
|
||||
respData = null;
|
||||
// console.log(
|
||||
// "*WS MESSAGE Received Packet: " + generate.buf2hex(message)
|
||||
// );
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE TOPUP-7 ]: message from HSM ${generate.buf2hex(
|
||||
message
|
||||
)}`
|
||||
);
|
||||
|
||||
respData = message;
|
||||
_stopMessage = 2;
|
||||
}
|
||||
});
|
||||
|
||||
while (respData == null) {
|
||||
await _sleep(10);
|
||||
}
|
||||
|
||||
_stopMessage = 0;
|
||||
|
||||
transactionId[0] = respData[0];
|
||||
transactionId[1] = respData[1];
|
||||
respCode = generate.getResponseCode(respData);
|
||||
respData1 = generate.getResponseData(respData);
|
||||
|
||||
let data = {};
|
||||
|
||||
if (
|
||||
respData[6] != 0x47 ||
|
||||
(respData1[9] != 0x00 && respData1[10] != 0x00)
|
||||
) {
|
||||
data = {
|
||||
mid: mid,
|
||||
tid: tid,
|
||||
card_number: card_number,
|
||||
amount: amount,
|
||||
reservation_number: reservation_number,
|
||||
ref_no: ref_no,
|
||||
write_status: 'FW',
|
||||
uid: uid,
|
||||
balance: parseInt(balance) + parseInt(amount),
|
||||
flag: parseInt(flag),
|
||||
unique_code: unique_code,
|
||||
load_balance_number: load_balance_number,
|
||||
};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE TOPUP-7 ]: updating load balance transaction is FW...`
|
||||
);
|
||||
|
||||
// update data load balance
|
||||
let update = await loadBalance.loadingBalanceUpdate(data);
|
||||
if (update) {
|
||||
if (update.code == '00') {
|
||||
result = {
|
||||
code: '5002',
|
||||
message: 'failed from HSM',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respData1.slice(6, 10),
|
||||
transcode: null,
|
||||
load_balance_number: update.data.load_balance_number,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
result = {
|
||||
code: update.code,
|
||||
message: update.message,
|
||||
data: {},
|
||||
};
|
||||
}
|
||||
} else {
|
||||
result = {
|
||||
code: '423',
|
||||
message: 'update/insert failed',
|
||||
data: {},
|
||||
};
|
||||
}
|
||||
} else {
|
||||
// jika sudah mencapai maksimum counting flag, maka reset flag ke awal
|
||||
if (flag >= 255) {
|
||||
flag = -1;
|
||||
}
|
||||
|
||||
data = {
|
||||
mid: mid,
|
||||
tid: tid,
|
||||
card_number: card_number,
|
||||
amount: amount,
|
||||
reservation_number: reservation_number,
|
||||
ref_no: ref_no,
|
||||
write_status: null,
|
||||
uid: uid,
|
||||
balance: balance,
|
||||
flag: flag ? parseInt(flag) + 1 : flag,
|
||||
unique_code: unique_code,
|
||||
load_balance_number: load_balance_number,
|
||||
};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${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') {
|
||||
result = {
|
||||
code: '00',
|
||||
message: 'Topup Succeess',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respCode,
|
||||
responseData: respData1,
|
||||
responseLength: respData1.length / 2,
|
||||
load_balance_number: update.data.load_balance_number,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
result = {
|
||||
code: update.code,
|
||||
message: update.message,
|
||||
data: {},
|
||||
};
|
||||
}
|
||||
} else {
|
||||
result = {
|
||||
code: '423',
|
||||
message: 'update/insert failed',
|
||||
data: {},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE TOPUP-7 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).send(result);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`[ RESPONSE LOADING-BALANCE TOPUP-7 ]: 500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
code: '5001',
|
||||
message:
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { validate, controller };
|
||||
@@ -0,0 +1,142 @@
|
||||
const winston = require('../../../helpers/winston.logger');
|
||||
const generate = require('../utils/utils');
|
||||
const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
require('dotenv').config();
|
||||
|
||||
let useClient;
|
||||
|
||||
// set connection HSM server
|
||||
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');
|
||||
|
||||
useClient = client2;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
var { client } = require('../services/webSocket');
|
||||
var { client2 } = require('../services/webSocket2');
|
||||
}
|
||||
|
||||
const controller = async (req, res) => {
|
||||
try {
|
||||
let { body } = req;
|
||||
let uniqueCode = body.unique_code;
|
||||
let result = {};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ REQUEST LOADING-BALANCE TOPUP-8 ]: ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
// set request to HSM server 2
|
||||
if (uniqueCode) {
|
||||
if (parseInt(uniqueCode) % 2 == 0) {
|
||||
// create log
|
||||
// winston.logger.error(`request to HSM server 2`);
|
||||
|
||||
if (client2.clientAuthenticated == false) {
|
||||
useClient = client;
|
||||
} else {
|
||||
useClient = client2;
|
||||
}
|
||||
} else {
|
||||
if (client.clientAuthenticated == false) {
|
||||
useClient = client2;
|
||||
} else {
|
||||
useClient = client;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let transactionId = Buffer.from(generate.hexToBytes(body.trxID));
|
||||
|
||||
let transactionEnd = Buffer.from([]);
|
||||
let apiId = Buffer.from([0x06]);
|
||||
let reqData = generate.makeRequestData(
|
||||
transactionId,
|
||||
apiId,
|
||||
transactionEnd
|
||||
);
|
||||
let _stopMessage = 1;
|
||||
|
||||
useClient.sendData(reqData);
|
||||
|
||||
let respCode = null;
|
||||
let respData = null;
|
||||
let respData1 = null;
|
||||
|
||||
useClient.ws.on('message', (message) => {
|
||||
while (
|
||||
message[2] == 6 &&
|
||||
message[0] == transactionId[0] &&
|
||||
message[1] == transactionId[1] &&
|
||||
_stopMessage == 1
|
||||
) {
|
||||
respData = null;
|
||||
// console.log("*WS MESSAGE EndTrx: " + generate.buf2hex(message));
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE TOPUP-8 ]: message from HSM ${generate.buf2hex(
|
||||
message
|
||||
)}`
|
||||
);
|
||||
|
||||
respData = message;
|
||||
_stopMessage = 2;
|
||||
}
|
||||
});
|
||||
|
||||
while (respData == null) {
|
||||
await _sleep(10);
|
||||
}
|
||||
|
||||
_stopMessage = 0;
|
||||
|
||||
transactionId[0] = respData[0];
|
||||
transactionId[1] = respData[1];
|
||||
respCode = generate.getResponseCode(respData);
|
||||
respData1 = generate.getResponseData(respData);
|
||||
|
||||
result = {
|
||||
code: '00',
|
||||
message: 'End Transaction Success',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respCode,
|
||||
},
|
||||
};
|
||||
|
||||
// log debug
|
||||
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(
|
||||
`[ RESPONSE LOADING-BALANCE TOPUP-8 ]: 500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
code: '5001',
|
||||
message:
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = controller;
|
||||
@@ -6,6 +6,7 @@ const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
const moment = require('moment');
|
||||
const {
|
||||
setLoadBalanceNumberSequence,
|
||||
getLoadBalanceNumberSequence2,
|
||||
} = require('../../middlewares/redis.middleware');
|
||||
moment.locale('id');
|
||||
|
||||
@@ -68,8 +69,9 @@ const generateLoadBalanceNumber = async (data, date, counter) => {
|
||||
|
||||
// insert to temp load balance number
|
||||
let insert = await model.insertLoadBalanceNumber(loadBalanceNumber);
|
||||
// console.log("DEBUGING insert", insert)
|
||||
if (insert.rowCount < 1) {
|
||||
loadBalanceNumber = 'XX';
|
||||
loadBalanceNumber = 'DUPLICATE';
|
||||
}
|
||||
return loadBalanceNumber;
|
||||
};
|
||||
@@ -179,7 +181,7 @@ const updateAllTransaction = async (
|
||||
);
|
||||
|
||||
// update reservation and load balance transaction
|
||||
await model.updateReservationAndLoadingBalance(
|
||||
const update = await model.updateReservationAndLoadingBalance(
|
||||
reservationNumber,
|
||||
data,
|
||||
dataLoadingBalanceDetail,
|
||||
@@ -187,33 +189,37 @@ const updateAllTransaction = async (
|
||||
flag
|
||||
);
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(`${uniqueCode} inserting log for card history...`);
|
||||
if (update) {
|
||||
// log debug
|
||||
winston.logger.debug(`${uniqueCode} inserting log for card history...`);
|
||||
|
||||
// log card history
|
||||
await model.createLoadBalanceLog({
|
||||
i_log_name: 21,
|
||||
d_log: dataLoadingBalance.d_load_balance,
|
||||
c_card_number: cardNumber,
|
||||
c_source: 'CMS',
|
||||
c_location: getPartner ? getPartner.partner_name : null,
|
||||
m_balance_before: parseInt(dataLoadingBalance.m_balance),
|
||||
m_amount: parseInt(dataLoadingBalance.i_topup_amount),
|
||||
m_balance_after: parseInt(balance),
|
||||
j_new_data: { data: data, detail: dataLoadingBalanceDetail },
|
||||
j_old_data: null,
|
||||
c_note: `LOAD BALANCE ${dataLoadingBalance.i_topup_amount} FROM ${
|
||||
getPartner ? getPartner.partner_name : null
|
||||
} SUCCESSFULLY`,
|
||||
c_status: 'S',
|
||||
d_created: now,
|
||||
i_create: null,
|
||||
c_create_username: 'HSM',
|
||||
c_create_fullname: 'HARDWARE SECURE MODULE',
|
||||
c_category: 'T',
|
||||
});
|
||||
// log card history
|
||||
await model.createLoadBalanceLog({
|
||||
i_log_name: 21,
|
||||
d_log: dataLoadingBalance.d_load_balance,
|
||||
c_card_number: cardNumber,
|
||||
c_source: 'CMS',
|
||||
c_location: getPartner ? getPartner.partner_name : null,
|
||||
m_balance_before: parseInt(dataLoadingBalance.m_balance),
|
||||
m_amount: parseInt(dataLoadingBalance.i_topup_amount),
|
||||
m_balance_after: parseInt(balance),
|
||||
j_new_data: { data: data, detail: dataLoadingBalanceDetail },
|
||||
j_old_data: null,
|
||||
c_note: `LOAD BALANCE ${dataLoadingBalance.i_topup_amount} FROM ${
|
||||
getPartner ? getPartner.partner_name : null
|
||||
} SUCCESSFULLY`,
|
||||
c_status: 'S',
|
||||
d_created: now,
|
||||
i_create: null,
|
||||
c_create_username: 'HSM',
|
||||
c_create_fullname: 'HARDWARE SECURE MODULE',
|
||||
c_category: 'T',
|
||||
});
|
||||
|
||||
return true;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// insert new load balance transaction by data on card and update data reservation
|
||||
|
||||
@@ -264,7 +270,7 @@ const updateAllTransaction = async (
|
||||
loadBalanceNoSequence
|
||||
);
|
||||
|
||||
if (newLoadBalanceNumber != 'XX') {
|
||||
if (newLoadBalanceNumber != 'DUPLICATE') {
|
||||
// set sequence to redis
|
||||
// await setLoadBalanceNumberSequence(
|
||||
// req.partner_id_token,
|
||||
@@ -287,7 +293,7 @@ const updateAllTransaction = async (
|
||||
}
|
||||
|
||||
maxLoop++;
|
||||
} while (newLoadBalanceNumber == 'XX');
|
||||
} while (newLoadBalanceNumber == 'DUPLICATE');
|
||||
|
||||
let dataLoadBalance = {
|
||||
c_load_balance_no: newLoadBalanceNumber,
|
||||
@@ -456,50 +462,62 @@ const loadingBalanceRequest = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
let cardBlacklist = await model.getCardBlacklist(card_number);
|
||||
if (cardBlacklist) {
|
||||
if (cardBlacklist.c_status == 'B') {
|
||||
result = {
|
||||
code: '445',
|
||||
message: 'Card is Blacklisted',
|
||||
data: {},
|
||||
};
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
}
|
||||
|
||||
// log debug
|
||||
// winston.logger.debug(
|
||||
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking production card number or not...`
|
||||
// );
|
||||
|
||||
// jika settingan untuk server adalah production
|
||||
if (process.env.SERVER_FOR == 'production') {
|
||||
// jika settingan production maka nomor kartu yang di request harus berawalan angka 1, jika bukan angka 1 maka ditolak
|
||||
if (card_number.substring(0, 1) != '1') {
|
||||
result = {
|
||||
code: '400',
|
||||
message: "It's not production card number.",
|
||||
data: {},
|
||||
};
|
||||
// if (process.env.SERVER_FOR == 'production') {
|
||||
// // jika settingan production maka nomor kartu yang di request harus berawalan angka 1, jika bukan angka 1 maka ditolak
|
||||
// if (card_number.substring(0, 1) != '1') {
|
||||
// result = {
|
||||
// code: '400',
|
||||
// message: "It's not production card number.",
|
||||
// data: {},
|
||||
// };
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE-REQUEST ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
// // log warn
|
||||
// winston.logger.warn(
|
||||
// `${uniqueCode} [ RESPONSE LOADING-BALANCE-REQUEST ]: ${JSON.stringify(
|
||||
// result
|
||||
// )}`
|
||||
// );
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
} else {
|
||||
// jika settingan bukan production, bisa development atau local maka jika ada nomor kartu berawalan angka 1 maka ditolak
|
||||
if (card_number.substring(0, 1) == '1') {
|
||||
result = {
|
||||
code: '400',
|
||||
message:
|
||||
"It's production card number. Please use the development card number.",
|
||||
data: {},
|
||||
};
|
||||
// return res.status(200).json(result);
|
||||
// }
|
||||
// } else {
|
||||
// // jika settingan bukan production, bisa development atau local maka jika ada nomor kartu berawalan angka 1 maka ditolak
|
||||
// if (card_number.substring(0, 1) == '1') {
|
||||
// result = {
|
||||
// code: '400',
|
||||
// message:
|
||||
// "It's production card number. Please use the development card number.",
|
||||
// data: {},
|
||||
// };
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE-REQUEST ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
// // log warn
|
||||
// winston.logger.warn(
|
||||
// `${uniqueCode} [ RESPONSE LOADING-BALANCE-REQUEST ]: ${JSON.stringify(
|
||||
// result
|
||||
// )}`
|
||||
// );
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
}
|
||||
// return res.status(200).json(result);
|
||||
// }
|
||||
// }
|
||||
|
||||
// time
|
||||
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||
@@ -530,6 +548,16 @@ const loadingBalanceRequest = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
if (getPartner.i_partner != req.partner_id_token) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'partner is not match',
|
||||
data: {},
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// get parameter setting pengecekkan nomor kartu dengan card product di CMS
|
||||
let getCheckByCardProductStatusValue =
|
||||
await model.getCheckByCardProductStatusValue();
|
||||
@@ -659,7 +687,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 +823,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 +854,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
|
||||
)}`
|
||||
);
|
||||
@@ -1251,6 +1279,16 @@ const loadingBalanceInsert = async (req, param) => {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (getPartner.i_partner != req.partner_id_token) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'partner is not match',
|
||||
data: {},
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log warn
|
||||
// winston.logger.warn(
|
||||
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: checking reservation status...`
|
||||
@@ -1438,8 +1476,81 @@ const loadingBalanceInsert = async (req, param) => {
|
||||
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: getting loading balance sequence...`
|
||||
// );
|
||||
|
||||
// Pindah ke bawah (nested if condition)
|
||||
|
||||
// if (!loadBalanceNoSequence) {
|
||||
// // get loading balance
|
||||
// getLoadBalanceSequence = await model.getLoadBalanceSequence(
|
||||
// getPartner,
|
||||
// today
|
||||
// );
|
||||
// loadBalanceNoSequence = getLoadBalanceSequence
|
||||
// ? parseInt(getLoadBalanceSequence.i_load_balance_no_seq) + 1
|
||||
// : 1;
|
||||
// }
|
||||
|
||||
let maxLoop = 0;
|
||||
// do {
|
||||
// // await _sleep(helper.randomNumberInt());
|
||||
// console.log("DEBUGING loadBalanceNoSequence", loadBalanceNoSequence)
|
||||
// if (maxLoop > 0) {
|
||||
// loadBalanceNoSequence++;
|
||||
// }
|
||||
|
||||
// // set sequence to redis
|
||||
// await setLoadBalanceNumberSequence(
|
||||
// req.partner_id_token,
|
||||
// loadBalanceNoSequence
|
||||
// );
|
||||
|
||||
// // log warn
|
||||
// // winston.logger.warn(
|
||||
// // `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: generating load balance number...`
|
||||
// // );
|
||||
|
||||
// loadBalanceNumber = await generateLoadBalanceNumber(
|
||||
// getPartner,
|
||||
// moment(today).format('YYMMDD'),
|
||||
// loadBalanceNoSequence
|
||||
// );
|
||||
|
||||
// // if (loadBalanceNumber != 'XX') {
|
||||
// // set sequence to redis
|
||||
// // await setLoadBalanceNumberSequence(
|
||||
// // req.partner_id_token,
|
||||
// // loadBalanceNoSequence
|
||||
// // );
|
||||
// // }
|
||||
|
||||
// // log warn
|
||||
// winston.logger.debug(
|
||||
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: load balance number sequence is ${loadBalanceNoSequence}.`
|
||||
// );
|
||||
|
||||
// if (maxLoop > maxLoopParameter) {
|
||||
// // create log
|
||||
// winston.logger.error(
|
||||
// `${uniqueCode} [ RESPONSE LOADING-BALANCE-INSERT ]: 500 internal server error. Server is busy. please try again`
|
||||
// );
|
||||
|
||||
// return {
|
||||
// code: '500',
|
||||
// message:
|
||||
// process.env.NODE_ENV != 'production'
|
||||
// ? '500 internal server error (max loop) - backend server.'
|
||||
// : '500 internal server error (max loop) - backend server.',
|
||||
// data: {},
|
||||
// };
|
||||
// }
|
||||
|
||||
// maxLoop++;
|
||||
// } while (loadBalanceNumber == 'XX');
|
||||
|
||||
//================== Start nested if condition ====================
|
||||
loadBalanceNoSequence = await getLoadBalanceNumberSequence2(req);
|
||||
console.log('DEBUGING loadBalanceNoSequence START', loadBalanceNoSequence);
|
||||
|
||||
if (!loadBalanceNoSequence) {
|
||||
// get loading balance
|
||||
getLoadBalanceSequence = await model.getLoadBalanceSequence(
|
||||
getPartner,
|
||||
today
|
||||
@@ -1447,65 +1558,130 @@ const loadingBalanceInsert = async (req, param) => {
|
||||
loadBalanceNoSequence = getLoadBalanceSequence
|
||||
? parseInt(getLoadBalanceSequence.i_load_balance_no_seq) + 1
|
||||
: 1;
|
||||
}
|
||||
|
||||
let maxLoop = 0;
|
||||
do {
|
||||
// await _sleep(helper.randomNumberInt());
|
||||
|
||||
if (maxLoop > 0) {
|
||||
loadBalanceNoSequence++;
|
||||
}
|
||||
|
||||
// set sequence to redis
|
||||
await setLoadBalanceNumberSequence(
|
||||
req.partner_id_token,
|
||||
loadBalanceNoSequence + 1
|
||||
);
|
||||
console.log(
|
||||
'Masuk kondisi !loadBalanceNoSequence',
|
||||
loadBalanceNoSequence
|
||||
);
|
||||
}
|
||||
|
||||
// log warn
|
||||
// winston.logger.warn(
|
||||
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: generating load balance number...`
|
||||
// );
|
||||
// Percobaan 1
|
||||
loadBalanceNumber = await generateLoadBalanceNumber(
|
||||
getPartner,
|
||||
moment(today).format('YYMMDD'),
|
||||
loadBalanceNoSequence
|
||||
);
|
||||
// log warn
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT Percobaan 1 ]: load balance number sequence is ${loadBalanceNoSequence}.`
|
||||
);
|
||||
console.log('DEBUGING loadBalanceNumber PERCOBAAN 1', loadBalanceNumber);
|
||||
|
||||
if (loadBalanceNumber == 'DUPLICATE') {
|
||||
loadBalanceNoSequence = await getLoadBalanceNumberSequence2(req);
|
||||
console.log(
|
||||
'DEBUGING loadBalanceNoSequence PERCOBAAN 2',
|
||||
loadBalanceNoSequence
|
||||
);
|
||||
// Percobaan 2
|
||||
loadBalanceNumber = await generateLoadBalanceNumber(
|
||||
getPartner,
|
||||
moment(today).format('YYMMDD'),
|
||||
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}.`
|
||||
// );
|
||||
|
||||
if (maxLoop > maxLoopParameter) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE-INSERT ]: 500 internal server error. Server is busy. please try again`
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT Percobaan 2 ]: load balance number sequence is ${loadBalanceNoSequence}.`
|
||||
);
|
||||
console.log('DEBUGING loadBalanceNumber PERCOBAAN 2', loadBalanceNumber);
|
||||
if (loadBalanceNumber == 'DUPLICATE') {
|
||||
loadBalanceNoSequence = await getLoadBalanceNumberSequence2(req);
|
||||
console.log(
|
||||
'DEBUGING loadBalanceNoSequence PERCOBAAN 3',
|
||||
loadBalanceNoSequence
|
||||
);
|
||||
// Percobaan 3
|
||||
loadBalanceNumber = await generateLoadBalanceNumber(
|
||||
getPartner,
|
||||
moment(today).format('YYMMDD'),
|
||||
loadBalanceNoSequence
|
||||
);
|
||||
// log warn
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT Percobaan 3 ]: load balance number sequence is ${loadBalanceNoSequence}.`
|
||||
);
|
||||
console.log(
|
||||
'DEBUGING loadBalanceNumber PERCOBAAN 3',
|
||||
loadBalanceNumber
|
||||
);
|
||||
if (loadBalanceNumber == 'DUPLICATE') {
|
||||
loadBalanceNoSequence = await getLoadBalanceNumberSequence2(req);
|
||||
console.log(
|
||||
'DEBUGING loadBalanceNoSequence PERCOBAAN 4',
|
||||
loadBalanceNoSequence
|
||||
);
|
||||
// Percobaan 4
|
||||
loadBalanceNumber = await generateLoadBalanceNumber(
|
||||
getPartner,
|
||||
moment(today).format('YYMMDD'),
|
||||
loadBalanceNoSequence
|
||||
);
|
||||
// log warn
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT Percobaan 4 ]: load balance number sequence is ${loadBalanceNoSequence}.`
|
||||
);
|
||||
console.log(
|
||||
'DEBUGING loadBalanceNumber PERCOBAAN 4',
|
||||
loadBalanceNumber
|
||||
);
|
||||
if (loadBalanceNumber == 'DUPLICATE') {
|
||||
loadBalanceNoSequence = await getLoadBalanceNumberSequence2(req);
|
||||
console.log(
|
||||
'DEBUGING loadBalanceNoSequence PERCOBAAN 5',
|
||||
loadBalanceNoSequence
|
||||
);
|
||||
// Percobaan 5
|
||||
loadBalanceNumber = await generateLoadBalanceNumber(
|
||||
getPartner,
|
||||
moment(today).format('YYMMDD'),
|
||||
loadBalanceNoSequence
|
||||
);
|
||||
// log warn
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT Percobaan 5 ]: load balance number sequence is ${loadBalanceNoSequence}.`
|
||||
);
|
||||
console.log(
|
||||
'DEBUGING loadBalanceNumber PERCOBAAN 5',
|
||||
loadBalanceNumber
|
||||
);
|
||||
if (loadBalanceNumber == 'DUPLICATE') {
|
||||
// log warn
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: load balance number sequence is ${loadBalanceNoSequence}.`
|
||||
);
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE-INSERT ]: 505 internal server error. Server is busy. please try again`
|
||||
);
|
||||
|
||||
return {
|
||||
code: '500',
|
||||
message:
|
||||
process.env.NODE_ENV != 'production'
|
||||
? '500 internal server error (max loop) - backend server.'
|
||||
: '500 internal server error (max loop) - backend server.',
|
||||
data: {},
|
||||
};
|
||||
return {
|
||||
code: '505',
|
||||
message:
|
||||
process.env.NODE_ENV != 'production'
|
||||
? '505 internal server error (max loop) - backend server.'
|
||||
: '505 Server is busy. please try again.',
|
||||
data: {},
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
maxLoop++;
|
||||
} while (loadBalanceNumber == 'XX');
|
||||
|
||||
//================== End nested if condition ====================
|
||||
let data = {
|
||||
c_load_balance_no: loadBalanceNumber,
|
||||
d_load_balance: now,
|
||||
@@ -1649,7 +1825,6 @@ const loadingBalanceInsert = async (req, param) => {
|
||||
// balance
|
||||
// )} [FLAG] : ${JSON.stringify(flag)}`
|
||||
// );
|
||||
|
||||
if (insertLoadingBalance > 0) {
|
||||
result = {
|
||||
code: '00',
|
||||
@@ -1761,6 +1936,16 @@ const loadingBalanceUpdate = async (param) => {
|
||||
return result;
|
||||
}
|
||||
|
||||
// if (getPartner.i_partner != req.partner_id_token) {
|
||||
// result = {
|
||||
// code: '412',
|
||||
// message: 'partner is not match',
|
||||
// data: {},
|
||||
// };
|
||||
|
||||
// return res.status(200).json(result);
|
||||
// }
|
||||
|
||||
let data = {
|
||||
d_load_balance: now,
|
||||
c_ref_no: ref_no,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const knex = require('../../../infrastructure/database/knex');
|
||||
const winston = require('../../helpers/winston.logger');
|
||||
|
||||
// CHECK CARD NUMBER
|
||||
const checkCardNumber = (cardNumber) => {
|
||||
@@ -56,6 +57,15 @@ const getIssuer = (id) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET IS CARD ADDED TO BLACKLIST
|
||||
const getCardBlacklist = (card_number) => {
|
||||
let result = knex('public.t_m_card_blacklist')
|
||||
.select('c_status')
|
||||
.where('c_card_number', card_number)
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET CHECKING CARD PRODUCT FROM GLOBAL PARAMETER
|
||||
const getCheckByCardProductStatusValue = () => {
|
||||
let result = knex('t_m_global_parameter')
|
||||
@@ -295,7 +305,7 @@ const insertLoadingBalance = async (
|
||||
let loadDetail = [];
|
||||
detail.forEach((element) => {
|
||||
loadDetail.push({
|
||||
i_load_balance: id,
|
||||
i_load_balance: id.i_load_balance,
|
||||
i_reservation_balance: element.i_reservation_balance,
|
||||
c_reservation_no: element.c_reservation_no,
|
||||
i_amount: element.i_amount,
|
||||
@@ -327,7 +337,7 @@ const insertLoadingBalance = async (
|
||||
let loadDetail = [];
|
||||
detail.forEach((element) => {
|
||||
loadDetail.push({
|
||||
i_load_balance: id,
|
||||
i_load_balance: id.i_load_balance,
|
||||
i_reservation_balance: element.i_reservation_balance,
|
||||
c_reservation_no: element.c_reservation_no,
|
||||
i_amount: element.i_amount,
|
||||
@@ -490,7 +500,7 @@ const insertLoadingBalanceHistoryOnly = async (
|
||||
let loadDetail = [];
|
||||
detail.forEach((element) => {
|
||||
loadDetail.push({
|
||||
i_load_balance: id,
|
||||
i_load_balance: id.i_load_balance,
|
||||
i_reservation_balance: element.i_reservation_balance,
|
||||
c_reservation_no: element.c_reservation_no,
|
||||
i_amount: element.i_amount,
|
||||
@@ -614,17 +624,34 @@ const updateReservationAndLoadingBalance = async (
|
||||
.where('c_load_balance_no', data.c_load_balance_no)
|
||||
.then(() => {
|
||||
// insert load balance history
|
||||
// winston.logger.debug(
|
||||
// `${reservationNumber} proses insert t_d_load_balance_history updateReservationAndLoadingBalance`
|
||||
// );
|
||||
return knex('trx.t_d_load_balance_history')
|
||||
.transacting(trx)
|
||||
.returning('i_load_balance')
|
||||
.insert(data);
|
||||
})
|
||||
.then((history) => {
|
||||
// winston.logger.debug(
|
||||
// `${JSON.stringify(history)} history t_d_load_balance_history_detail`
|
||||
// );
|
||||
// winston.logger.debug(
|
||||
// `${JSON.stringify(
|
||||
// history[0]
|
||||
// )} id t_d_load_balance_history_detail before parseint`
|
||||
// );
|
||||
let id = history[0];
|
||||
// winston.logger.debug(
|
||||
// `${id} id t_d_load_balance_history_detail id only`
|
||||
// );
|
||||
// winston.logger.debug(
|
||||
// `${id.i_load_balance} id t_d_load_balance_history_detail id.i_load_balance`
|
||||
// );
|
||||
let loadDetail = [];
|
||||
detail.forEach((element) => {
|
||||
loadDetail.push({
|
||||
i_load_balance: id,
|
||||
i_load_balance: id.i_load_balance,
|
||||
i_reservation_balance: element.i_reservation_balance,
|
||||
c_reservation_no: element.c_reservation_no,
|
||||
i_amount: element.i_amount,
|
||||
@@ -639,6 +666,11 @@ const updateReservationAndLoadingBalance = async (
|
||||
});
|
||||
});
|
||||
|
||||
// winston.logger.debug(
|
||||
// `${reservationNumber} proses insert t_d_load_balance_history_detail updateReservationAndLoadingBalance: ${JSON.stringify(
|
||||
// loadDetail
|
||||
// )}`
|
||||
// );
|
||||
// insert detail load balance
|
||||
return knex('trx.t_d_load_balance_history_detail')
|
||||
.transacting(trx)
|
||||
@@ -646,6 +678,9 @@ const updateReservationAndLoadingBalance = async (
|
||||
})
|
||||
.then(() => {
|
||||
// update reservation
|
||||
// winston.logger.debug(
|
||||
// `${reservationNumber} proses update t_d_reservation_balance updateReservationAndLoadingBalance`
|
||||
// );
|
||||
return knex('trx.t_d_reservation_balance')
|
||||
.transacting(trx)
|
||||
.update({
|
||||
@@ -662,16 +697,31 @@ const updateReservationAndLoadingBalance = async (
|
||||
})
|
||||
.whereIn('c_reservation_no', reservationNumber);
|
||||
})
|
||||
.then(trx.commit)
|
||||
.catch(trx.rollback);
|
||||
.then(() => {
|
||||
// winston.logger.debug(`${reservationNumber} commit transaction`);
|
||||
trx.commit();
|
||||
})
|
||||
.catch((error) => {
|
||||
winston.logger.debug(
|
||||
`${reservationNumber} rollback transaction: ${error.message}`
|
||||
);
|
||||
trx.rollback(); // Rollback transaction
|
||||
// throw error; // Rethrow error to outer catch
|
||||
});
|
||||
})
|
||||
.then((result) => {
|
||||
// winston.logger.debug(
|
||||
// `${reservationNumber} result success ${JSON.stringify(result)}}`
|
||||
// );
|
||||
// console.log(result);
|
||||
return result.rowCount;
|
||||
return true;
|
||||
})
|
||||
.catch((error) => {
|
||||
winston.logger.debug(
|
||||
`${reservationNumber} result error: ${error.message}`
|
||||
);
|
||||
// console.log(error.message);
|
||||
return error.message;
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1012,7 +1062,7 @@ const updateReservationAndInsertLoadingBalance = async (
|
||||
let loadDetail = [];
|
||||
detailLoadBalance.forEach((element) => {
|
||||
loadDetail.push({
|
||||
i_load_balance: id,
|
||||
i_load_balance: id.i_load_balance,
|
||||
i_reservation_balance: element.i_reservation_balance,
|
||||
c_reservation_no: element.c_reservation_no,
|
||||
i_amount: element.i_reservation_amount,
|
||||
@@ -1077,6 +1127,7 @@ module.exports = {
|
||||
checkCardNumber,
|
||||
getPartner,
|
||||
getIssuer,
|
||||
getCardBlacklist,
|
||||
getCheckByCardProductStatusValue,
|
||||
getReservationPending,
|
||||
getReservationPendingWithFlagCounter,
|
||||
|
||||
@@ -136,6 +136,58 @@ const paymentRecon = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
console.log(getPartner);
|
||||
|
||||
// check payment recon status is enable
|
||||
if (getPartner.b_payment_recon != true) {
|
||||
result = {
|
||||
code: '444',
|
||||
message: 'Partner unable to receive payment reconciliations',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE PAYMENT-RECON ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// check partner reservation number yang di request sama dengan partner yang di token
|
||||
let checkReservation = await model.checkReservation(reservation_number);
|
||||
|
||||
if (!checkReservation) {
|
||||
result = {
|
||||
code: '400',
|
||||
message: 'Reservation number does not exist.',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE PAYMENT-RECON ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
if (checkReservation.i_partner != partner_id) {
|
||||
result = {
|
||||
code: '443',
|
||||
message:
|
||||
'Partner for payment reconciliation and transaction does not match',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE PAYMENT-RECON ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// check reservation number yang di request sudah berhasil di recon atau belum sebelumnnya
|
||||
let checkReservationNumberAndAmountAlreadyRecon =
|
||||
await model.checkReservationNumberAndAmountAlreadyRecon(
|
||||
|
||||
@@ -1,33 +1,34 @@
|
||||
const knex = require("../../../infrastructure/database/knex");
|
||||
const knex = require('../../../infrastructure/database/knex');
|
||||
|
||||
// GET PARTNER, MERCHANT, TERMINAL FROM TID
|
||||
const getPartner = (mid, tid) => {
|
||||
let result = knex
|
||||
.select(
|
||||
"t_m_partner.i_partner",
|
||||
"t_m_partner.c_code as partner_code",
|
||||
"t_m_partner.c_name as partner_name",
|
||||
"t_m_merchant.i_merchant",
|
||||
"t_m_merchant.c_code as merchant_code",
|
||||
"t_m_merchant.c_name as merchant_name",
|
||||
"t_m_merchant.e_mid as mid",
|
||||
"t_m_terminal.i_terminal",
|
||||
"t_m_terminal.c_code as terminal_code",
|
||||
"t_m_terminal.c_name as terminal_name",
|
||||
"t_m_terminal.e_tid as tid"
|
||||
't_m_partner.i_partner',
|
||||
't_m_partner.c_code as partner_code',
|
||||
't_m_partner.c_name as partner_name',
|
||||
't_m_partner.b_payment_recon',
|
||||
't_m_merchant.i_merchant',
|
||||
't_m_merchant.c_code as merchant_code',
|
||||
't_m_merchant.c_name as merchant_name',
|
||||
't_m_merchant.e_mid as mid',
|
||||
't_m_terminal.i_terminal',
|
||||
't_m_terminal.c_code as terminal_code',
|
||||
't_m_terminal.c_name as terminal_name',
|
||||
't_m_terminal.e_tid as tid'
|
||||
)
|
||||
.from("t_m_terminal")
|
||||
.from('t_m_terminal')
|
||||
.leftJoin(
|
||||
"t_m_merchant",
|
||||
"t_m_terminal.i_merchant",
|
||||
"t_m_merchant.i_merchant"
|
||||
't_m_merchant',
|
||||
't_m_terminal.i_merchant',
|
||||
't_m_merchant.i_merchant'
|
||||
)
|
||||
.leftJoin("t_m_partner", "t_m_merchant.i_partner", "t_m_partner.i_partner")
|
||||
.where("t_m_merchant.e_mid", mid)
|
||||
.where("t_m_terminal.e_tid", tid)
|
||||
.where("t_m_terminal.c_status", "A")
|
||||
.where("t_m_merchant.c_status", "A")
|
||||
.where("t_m_partner.c_status", "A")
|
||||
.leftJoin('t_m_partner', 't_m_merchant.i_partner', 't_m_partner.i_partner')
|
||||
.where('t_m_merchant.e_mid', mid)
|
||||
.where('t_m_terminal.e_tid', tid)
|
||||
.where('t_m_terminal.c_status', 'A')
|
||||
.where('t_m_merchant.c_status', 'A')
|
||||
.where('t_m_partner.c_status', 'A')
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
@@ -35,57 +36,66 @@ const getPartner = (mid, tid) => {
|
||||
const getPartnerByID = (partner_id) => {
|
||||
let result = knex
|
||||
.select(
|
||||
"t_m_partner.i_partner",
|
||||
"t_m_partner.c_code as partner_code",
|
||||
"t_m_partner.c_name as partner_name"
|
||||
't_m_partner.i_partner',
|
||||
't_m_partner.c_code as partner_code',
|
||||
't_m_partner.c_name as partner_name',
|
||||
't_m_partner.b_payment_recon'
|
||||
)
|
||||
.from("t_m_partner")
|
||||
.where("t_m_partner.i_partner", partner_id)
|
||||
.where("t_m_partner.c_status", "A")
|
||||
.from('t_m_partner')
|
||||
.where('t_m_partner.i_partner', partner_id)
|
||||
.where('t_m_partner.c_status', 'A')
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
const checkReservationNumberAndAmount = (reservationNumber) => {
|
||||
let result = knex("trx.t_d_reservation_balance")
|
||||
.count("* as total_transaction")
|
||||
.sum("i_reservation_amount as total_amount")
|
||||
.groupBy("c_ref_no")
|
||||
.where("c_reservation_no", reservationNumber)
|
||||
let result = knex('trx.t_d_reservation_balance')
|
||||
.count('* as total_transaction')
|
||||
.sum('i_reservation_amount as total_amount')
|
||||
.groupBy('c_ref_no')
|
||||
.where('c_reservation_no', reservationNumber)
|
||||
// .where("c_status", "A")
|
||||
.whereNull("c_payment_recon_no")
|
||||
.whereNull('c_payment_recon_no')
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
const checkReservationCanceledStatus = (reservationNumber) => {
|
||||
let result = knex("trx.t_d_reservation_balance")
|
||||
.where("c_reservation_no", reservationNumber)
|
||||
.where("c_status", "X")
|
||||
let result = knex('trx.t_d_reservation_balance')
|
||||
.where('c_reservation_no', reservationNumber)
|
||||
.where('c_status', 'X')
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
const checkReservation = (reservationNumber) => {
|
||||
let result = knex('trx.t_d_reservation_balance')
|
||||
.where('c_reservation_no', reservationNumber)
|
||||
.where('c_status', '!=', 'X')
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
const checkReservationNumberAndAmountAlreadyRecon = (reservationNumber) => {
|
||||
let result = knex("trx.t_d_reservation_balance")
|
||||
.select("c_payment_recon_no", "d_payment_recon")
|
||||
.where("c_reservation_no", reservationNumber)
|
||||
let result = knex('trx.t_d_reservation_balance')
|
||||
.select('c_payment_recon_no', 'd_payment_recon')
|
||||
.where('c_reservation_no', reservationNumber)
|
||||
// .where("c_status", "A")
|
||||
.whereNotNull("c_payment_recon_no")
|
||||
.whereNotNull('c_payment_recon_no')
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// UPDATE PAYMENT RECON
|
||||
const updatePaymentReconNo = (data) => {
|
||||
let result = knex("trx.t_d_reservation_balance")
|
||||
let result = knex('trx.t_d_reservation_balance')
|
||||
.update({
|
||||
c_payment_recon_no: data.payment_recon_no,
|
||||
d_payment: data.date,
|
||||
d_payment_recon: data.time,
|
||||
})
|
||||
.whereNull("c_payment_recon_no")
|
||||
.where("c_reservation_no", data.reservation_number);
|
||||
.whereNull('c_payment_recon_no')
|
||||
.where('c_reservation_no', data.reservation_number);
|
||||
return result;
|
||||
};
|
||||
|
||||
@@ -104,7 +114,7 @@ const insertPaymentReconTransaction = (
|
||||
responseMessage,
|
||||
responseData
|
||||
) => {
|
||||
let result = knex("payment.t_d_payment_recon").insert({
|
||||
let result = knex('payment.t_d_payment_recon').insert({
|
||||
d_payment: date,
|
||||
d_payment_recon: now,
|
||||
c_partner_code: partnerCode,
|
||||
@@ -123,34 +133,34 @@ const insertPaymentReconTransaction = (
|
||||
|
||||
// INSERT TEMP PAYMENT RECON NUMBER
|
||||
const insertPaymentReconNumber = (paymentReconNumber) => {
|
||||
let result = knex("payment.t_d_payment_recon_no_validate")
|
||||
let result = knex('payment.t_d_payment_recon_no_validate')
|
||||
.insert({
|
||||
c_payment_recon_no: paymentReconNumber,
|
||||
})
|
||||
.onConflict("c_payment_recon_no")
|
||||
.onConflict('c_payment_recon_no')
|
||||
.ignore();
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET LAST COUNTER PAYMENT RECON NO
|
||||
const getLastCounterPaymentReconNo = (partnerCode, reconDate) => {
|
||||
let result = knex("payment.t_d_payment_recon")
|
||||
.select("c_payment_recon_no", "d_payment_recon")
|
||||
.whereRaw("??::date = ?", ["d_payment_recon", reconDate])
|
||||
.where("c_partner_code", partnerCode)
|
||||
let result = knex('payment.t_d_payment_recon')
|
||||
.select('c_payment_recon_no', 'd_payment_recon')
|
||||
.whereRaw('??::date = ?', ['d_payment_recon', reconDate])
|
||||
.where('c_partner_code', partnerCode)
|
||||
// .orderBy("d_payment_recon", "desc")
|
||||
.orderBy("c_payment_recon_no", "desc")
|
||||
.orderBy('c_payment_recon_no', 'desc')
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
const getReservationToRecon = (date) => {
|
||||
let result = knex("trx.t_d_reservation_balance")
|
||||
.select("c_reservation_no", "i_reservation_amount")
|
||||
.whereNull("d_cancel")
|
||||
.whereNull("c_payment_recon_no")
|
||||
.whereRaw("??::date = ?", ["d_reservation", date])
|
||||
.orderBy("c_reservation_no", "asc");
|
||||
let result = knex('trx.t_d_reservation_balance')
|
||||
.select('c_reservation_no', 'i_reservation_amount')
|
||||
.whereNull('d_cancel')
|
||||
.whereNull('c_payment_recon_no')
|
||||
.whereRaw('??::date = ?', ['d_reservation', date])
|
||||
.orderBy('c_reservation_no', 'asc');
|
||||
return result;
|
||||
};
|
||||
|
||||
@@ -159,6 +169,7 @@ module.exports = {
|
||||
getPartnerByID,
|
||||
checkReservationNumberAndAmount,
|
||||
checkReservationCanceledStatus,
|
||||
checkReservation,
|
||||
checkReservationNumberAndAmountAlreadyRecon,
|
||||
updatePaymentReconNo,
|
||||
insertPaymentReconTransaction,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,97 @@
|
||||
const knex = require('../../../infrastructure/database/knex');
|
||||
|
||||
// GET IS CARD ADDED TO BLACKLIST
|
||||
const getCardBlacklist = (card_number) => {
|
||||
let result = knex('public.t_m_card_blacklist')
|
||||
.select('c_status')
|
||||
.where('c_card_number', card_number)
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET IS CARD ADDED TO BLACKLIST
|
||||
const getCardReplacement = (card_number) => {
|
||||
let result = knex('trx.t_d_card_replacement')
|
||||
.select()
|
||||
.where('c_card_no', card_number)
|
||||
.orderBy('i_card_replacement', 'DESC')
|
||||
.first();
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET IS CARD ADDED TO BLACKLIST
|
||||
const getCardProduct = (card_number) => {
|
||||
let result = knex('public.t_m_card_product')
|
||||
.select()
|
||||
.where('c_card_number', card_number)
|
||||
.orderBy('i_request_order', 'DESC')
|
||||
.first();
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET CHECKING FROM GLOBAL PARAMETER
|
||||
const getGlobalParameterData = (code) => {
|
||||
let result = knex('t_m_global_parameter')
|
||||
.select('c_value')
|
||||
.where('c_code', code)
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET LAST BALANCE FROM CARD HISTORY
|
||||
const getLastBalanceFromCardHistory = (cardNumber) => {
|
||||
let result = knex('log.t_log_card')
|
||||
.select('m_balance_after')
|
||||
.where('c_card_number', cardNumber)
|
||||
.where('c_status', 'S')
|
||||
.where('m_balance_after', '>', 0)
|
||||
.orderBy('d_log', 'desc')
|
||||
.limit(1)
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET ACCUMULATION BALANCE IN THIS MONTH FROM CARD HISTORY
|
||||
const getAccumulationBalanceInThisMonthFromCardHistory = (
|
||||
cardNumber,
|
||||
year,
|
||||
month
|
||||
) => {
|
||||
let result = knex('log.t_log_card')
|
||||
.sum('m_amount as accumulation_balance')
|
||||
.where('c_card_number', cardNumber)
|
||||
.where('c_status', 'S')
|
||||
.where('m_balance_after', '>', 0)
|
||||
.whereRaw("DATE_PART('YEAR', ??) = ?", ['d_log', year])
|
||||
.whereRaw("DATE_PART('MONTH', ??) = ?", ['d_log', month])
|
||||
.whereIn('i_log_name', [21])
|
||||
.groupBy('c_card_number')
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// UPDATE CARD REPLACEMENT
|
||||
const updateReplacement = async (i_card_replacement, dataReplacement) => {
|
||||
let result = await knex('trx.t_d_card_replacement')
|
||||
.update(dataReplacement, ['*'])
|
||||
.where({ i_card_replacement: i_card_replacement });
|
||||
return result;
|
||||
};
|
||||
|
||||
const insertReplacementDetail = async (dataReplacement) => {
|
||||
let result = await knex("trx.t_d_card_replacement_detail").insert(dataReplacement);
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getCardBlacklist,
|
||||
getCardReplacement,
|
||||
getCardProduct,
|
||||
getGlobalParameterData,
|
||||
getLastBalanceFromCardHistory,
|
||||
getAccumulationBalanceInThisMonthFromCardHistory,
|
||||
updateReplacement,
|
||||
insertReplacementDetail
|
||||
};
|
||||
@@ -0,0 +1,219 @@
|
||||
const { param, body, validationResult } = require('express-validator');
|
||||
const helper = require('../../helpers/helper');
|
||||
const winston = require('../../helpers/winston.logger');
|
||||
const model = require('./refundkmt.model');
|
||||
const moment = require('moment');
|
||||
moment.locale('id');
|
||||
|
||||
// VALIDATION
|
||||
const validate = (method) => {
|
||||
switch (method) {
|
||||
case 'callbackOy':
|
||||
return [
|
||||
body('partner_trx_id')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Partner Trx Id is required'),
|
||||
body('trx_id').not().isEmpty().withMessage('Trx Id is required'),
|
||||
body('amount').not().isEmpty().withMessage('Amount is required'),
|
||||
body('recipient_bank')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Recipient Bank is required'),
|
||||
body('recipient_account')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Recipient Account is required'),
|
||||
];
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
const callbackOy = async (req, res) => {
|
||||
try {
|
||||
// generate unique code
|
||||
// unique code ini digunakan untuk keperluan log agar mudah untuk dibaca
|
||||
let uniqueCode = helper.getUniqueCode();
|
||||
let result = {};
|
||||
|
||||
// param
|
||||
let {
|
||||
status,
|
||||
amount,
|
||||
recipient_name,
|
||||
recipient_bank,
|
||||
recipient_account,
|
||||
trx_id,
|
||||
partner_trx_id,
|
||||
timestamp,
|
||||
created_date,
|
||||
last_updated_date,
|
||||
} = req.body;
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ REQUEST REFUND-KMT ]: ${JSON.stringify(req.body)}`
|
||||
);
|
||||
|
||||
// check validator
|
||||
let err = validationResult(req, res);
|
||||
if (!err.isEmpty()) {
|
||||
result = {
|
||||
code: '400',
|
||||
message: err.errors[0].msg,
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE REFUND-KMT ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// time
|
||||
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE REFUND-KMT ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
let recipient_bank_code = recipient_bank.toUpperCase();
|
||||
// check trx_id yang di request match
|
||||
let checkRequest = await model.checkRedeem(
|
||||
partner_trx_id,
|
||||
trx_id,
|
||||
amount,
|
||||
recipient_bank_code,
|
||||
recipient_account
|
||||
);
|
||||
|
||||
if (!checkRequest) {
|
||||
result = {
|
||||
code: '400',
|
||||
message: 'Refund Request Transaction is not found.',
|
||||
data: {},
|
||||
};
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE REFUND-KMT ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
return res.status(200).json(result);
|
||||
} else if (checkRequest.c_status?.trim() == 'A') {
|
||||
result = {
|
||||
code: '400',
|
||||
message: 'Refund transaction is already completed.',
|
||||
data: {},
|
||||
};
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE REFUND-KMT ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ checkRequest ]: ${JSON.stringify(checkRequest)}`
|
||||
);
|
||||
|
||||
if (status.code != '000') {
|
||||
result = {
|
||||
code: '400',
|
||||
message: status.message,
|
||||
data: {
|
||||
trx_id: trx_id,
|
||||
partner_trx_id: partner_trx_id,
|
||||
amount: amount,
|
||||
recipient_bank: recipient_bank_code,
|
||||
recipient_account: recipient_account,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const date_reimbursement = moment(last_updated_date, 'DD-MM-YYYY HH:mm:ss').format(
|
||||
'YYYY-MM-DD HH:mm:ss'
|
||||
);
|
||||
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ log date_reimbusement ]: ${JSON.stringify(date_reimbursement)}`
|
||||
);
|
||||
|
||||
//Update Card Replacement
|
||||
await model.updateReplacementComplete(
|
||||
checkRequest.i_card_replacement,
|
||||
checkRequest.c_request_no,
|
||||
date_reimbursement
|
||||
);
|
||||
|
||||
/*
|
||||
//Notif Email
|
||||
let urlCMS = '';
|
||||
if (process.env.SERVER_FOR == 'production') {
|
||||
urlCMS = 'https://cms.kci.id';
|
||||
} else if (process.env.SERVER_FOR == 'development') {
|
||||
urlCMS = 'http://10.20.14.69';
|
||||
} else {
|
||||
urlCMS = 'http://localhost:8000';
|
||||
}
|
||||
|
||||
let axios = require('axios');
|
||||
|
||||
const url = urlCMS + '/api/redeem/notifemail';
|
||||
console.log('urlCMS', url);
|
||||
|
||||
// let resp = await axios.post(url, body, config);
|
||||
const responseMail = await axios({
|
||||
method: 'post',
|
||||
url: url,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
data: {
|
||||
i_card_replacement: checkRequest.i_card_replacement?.trim(),
|
||||
c_request_no: checkRequest.c_request_no?.trim(),
|
||||
c_card_no: checkRequest.c_card_no?.trim(),
|
||||
status: 'complete',
|
||||
},
|
||||
});
|
||||
*/
|
||||
// console.log('urlCMS', url)
|
||||
|
||||
result = {
|
||||
code: '00',
|
||||
message: 'success',
|
||||
data: {
|
||||
trx_id: trx_id,
|
||||
partner_trx_id: partner_trx_id,
|
||||
amount: amount,
|
||||
recipient_bank: recipient_bank,
|
||||
recipient_account: recipient_account,
|
||||
last_updated_date: last_updated_date,
|
||||
},
|
||||
};
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ RESPONSE REFUND-KMT ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`[ RESPONSE REFUND-KMT ]: 500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return res.status(200).json({
|
||||
code: '500',
|
||||
message:
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
validate,
|
||||
callbackOy,
|
||||
};
|
||||
@@ -0,0 +1,55 @@
|
||||
const knex = require("../../../infrastructure/database/knex");
|
||||
|
||||
const checkRedeem = (partner_trx_id, trx_id, amount, recipient_bank, recipient_account) => {
|
||||
let result = knex
|
||||
.select(
|
||||
"t_d_card_replacement.i_card_replacement",
|
||||
"t_d_card_replacement.c_request_no",
|
||||
"t_d_card_replacement.c_card_no",
|
||||
"t_d_card_replacement.i_request_disburse",
|
||||
"t_d_card_replacement.c_refund_trx_id",
|
||||
"t_d_card_replacement.c_status"
|
||||
)
|
||||
.from("trx.t_d_card_replacement")
|
||||
// .leftJoin(
|
||||
// "t_m_merchant", "t_m_terminal.c_card_no", "t_m_merchant.i_merchant"
|
||||
// )
|
||||
// .leftJoin("t_m_partner", "t_m_merchant.i_partner", "t_m_partner.i_partner")
|
||||
.where("t_d_card_replacement.c_method", "CASHLESS")
|
||||
// .where("t_d_card_replacement.c_status", "OP")
|
||||
.where("t_d_card_replacement.i_last_balance", amount)
|
||||
.where("t_d_card_replacement.c_request_no", partner_trx_id)
|
||||
.where("t_d_card_replacement.c_refund_trx_id", trx_id)
|
||||
.where("t_d_card_replacement.c_bank_code", recipient_bank)
|
||||
.where("t_d_card_replacement.c_account_number", recipient_account)
|
||||
// .whereNull("t_d_card_replacement.c_status", "OP")
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// UPDATE REPLACEMENT
|
||||
const updateReplacementComplete = (i_replacement, request_no, date_disburse) => {
|
||||
let result = knex("trx.t_d_card_replacement")
|
||||
.where("i_card_replacement", i_replacement)
|
||||
.where("c_request_no", request_no)
|
||||
// .update({
|
||||
// c_status: "A",
|
||||
// c_status_name: "COMPLETED",
|
||||
// d_disburse: date_disburse,
|
||||
// c_response_code: "000",
|
||||
// c_response_message: "Success"
|
||||
// });
|
||||
.update({
|
||||
c_status: "A",
|
||||
c_status_name: "COMPLETED",
|
||||
d_disburse: date_disburse,
|
||||
c_response_code: "000",
|
||||
c_response_message: "Success"
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
checkRedeem,
|
||||
updateReplacementComplete
|
||||
};
|
||||
@@ -111,10 +111,17 @@ 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)}`
|
||||
);
|
||||
|
||||
// trim card number
|
||||
card_number = card_number.trim();
|
||||
|
||||
// check validator
|
||||
let err = validationResult(req, res);
|
||||
if (!err.isEmpty()) {
|
||||
@@ -125,11 +132,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);
|
||||
}
|
||||
@@ -142,44 +149,56 @@ const checkReservation = async (req, res) => {
|
||||
// `${uniqueCode} [ PROCESSING RESERVATION-CHECK ] checking production card number or not...`
|
||||
// );
|
||||
|
||||
// jika settingan diperuntukan untuk production
|
||||
if (process.env.SERVER_FOR == 'production') {
|
||||
// kartu yang di request bukan kartu production maka akan di tolak
|
||||
if (card_number.substring(0, 1) != '1') {
|
||||
let cardBlacklist = await model.getCardBlacklist(card_number);
|
||||
if (cardBlacklist) {
|
||||
if (cardBlacklist.c_status == 'B') {
|
||||
result = {
|
||||
code: '400',
|
||||
message: "It's not production card number.",
|
||||
code: '445',
|
||||
message: 'Card is Blacklisted',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE RESERVATION-CHECK ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
} else {
|
||||
// jika settingan bukan diperuntukan untuk production, bisa development atau local atau yang lainnya dan kemudian kartu yang di request merupakan kartu production maka akan di tolak
|
||||
if (card_number.substring(0, 1) == '1') {
|
||||
result = {
|
||||
code: '400',
|
||||
message:
|
||||
"It's production card number. Please use the development card number.",
|
||||
data: {},
|
||||
};
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE RESERVATION-CHECK ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
}
|
||||
|
||||
// jika settingan diperuntukan untuk production
|
||||
// if (process.env.SERVER_FOR == 'production') {
|
||||
// // kartu yang di request bukan kartu production maka akan di tolak
|
||||
// if (card_number.substring(0, 1) != '1') {
|
||||
// result = {
|
||||
// code: '400',
|
||||
// message: "It's not production card number.",
|
||||
// data: {},
|
||||
// };
|
||||
|
||||
// // log warn
|
||||
// // winston.logger.warn(
|
||||
// // `${uniqueCode} [ RESPONSE RESERVATION-CHECK ]: ${JSON.stringify(
|
||||
// // result
|
||||
// // )}`
|
||||
// // );
|
||||
|
||||
// return res.status(200).json(result);
|
||||
// }
|
||||
// } else {
|
||||
// // jika settingan bukan diperuntukan untuk production, bisa development atau local atau yang lainnya dan kemudian kartu yang di request merupakan kartu production maka akan di tolak
|
||||
// if (card_number.substring(0, 1) == '1') {
|
||||
// result = {
|
||||
// code: '400',
|
||||
// message:
|
||||
// "It's production card number. Please use the development card number.",
|
||||
// data: {},
|
||||
// };
|
||||
// // log warn
|
||||
// // winston.logger.warn(
|
||||
// // `${uniqueCode} [ RESPONSE RESERVATION-CHECK ]: ${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(
|
||||
@@ -195,6 +214,28 @@ const checkReservation = async (req, res) => {
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
// winston.logger.warn(
|
||||
// `${uniqueCode} [ RESPONSE RESERVATION-CHECK ]: ${JSON.stringify(
|
||||
// result
|
||||
// )}`
|
||||
// );
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
if (getPartner.i_partner != req.partner_id_token) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'partner is not match',
|
||||
data: {
|
||||
body: req.body,
|
||||
partner_id_token: req.partner_id_token,
|
||||
partner_user_id_token: req.partner_user_id_token,
|
||||
headers: req.headers,
|
||||
},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE RESERVATION-CHECK ]: ${JSON.stringify(
|
||||
@@ -236,7 +277,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)}`
|
||||
);
|
||||
|
||||
@@ -280,6 +325,9 @@ const reservationValidate = async (req, res) => {
|
||||
)}`
|
||||
);
|
||||
|
||||
// trim card number
|
||||
card_number = card_number.trim();
|
||||
|
||||
// check validator
|
||||
let err = validationResult(req, res);
|
||||
if (!err.isEmpty()) {
|
||||
@@ -307,46 +355,58 @@ const reservationValidate = async (req, res) => {
|
||||
// `${uniqueCode} [ PROCESSING RESERVATION-VALIDATE ] checking production card number or not...`
|
||||
// );
|
||||
|
||||
// jika settingan diperuntukan untuk production
|
||||
if (process.env.SERVER_FOR == 'production') {
|
||||
// kartu yang di request bukan kartu production maka akan di tolak
|
||||
if (card_number.substring(0, 1) != '1') {
|
||||
let cardBlacklist = await model.getCardBlacklist(card_number);
|
||||
if (cardBlacklist) {
|
||||
if (cardBlacklist.c_status == 'B') {
|
||||
result = {
|
||||
code: '400',
|
||||
message: "It's not production card number.",
|
||||
code: '445',
|
||||
message: 'Card is Blacklisted',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE RESERVATION-VALIDATE ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
} else {
|
||||
// jika settingan bukan diperuntukan untuk production, bisa development atau local atau yang lainnya dan kemudian kartu yang di request merupakan kartu production maka akan di tolak
|
||||
if (card_number.substring(0, 1) == '1') {
|
||||
result = {
|
||||
code: '400',
|
||||
message:
|
||||
"It's production card number. Please use the development card number.",
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE RESERVATION-VALIDATE ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
}
|
||||
|
||||
// jika settingan diperuntukan untuk production
|
||||
// if (process.env.SERVER_FOR == 'production') {
|
||||
// // kartu yang di request bukan kartu production maka akan di tolak
|
||||
// if (card_number.substring(0, 1) != '1') {
|
||||
// result = {
|
||||
// code: '400',
|
||||
// message: "It's not production card number.",
|
||||
// data: {},
|
||||
// };
|
||||
|
||||
// // log warn
|
||||
// winston.logger.warn(
|
||||
// `${uniqueCode} [ RESPONSE RESERVATION-VALIDATE ]: ${JSON.stringify(
|
||||
// result
|
||||
// )}`
|
||||
// );
|
||||
|
||||
// return res.status(200).json(result);
|
||||
// }
|
||||
// } else {
|
||||
// // jika settingan bukan diperuntukan untuk production, bisa development atau local atau yang lainnya dan kemudian kartu yang di request merupakan kartu production maka akan di tolak
|
||||
// if (card_number.substring(0, 1) == '1') {
|
||||
// result = {
|
||||
// code: '400',
|
||||
// message:
|
||||
// "It's production card number. Please use the development card number.",
|
||||
// data: {},
|
||||
// };
|
||||
|
||||
// // log warn
|
||||
// winston.logger.warn(
|
||||
// `${uniqueCode} [ RESPONSE RESERVATION-VALIDATE ]: ${JSON.stringify(
|
||||
// result
|
||||
// )}`
|
||||
// );
|
||||
|
||||
// return res.status(200).json(result);
|
||||
// }
|
||||
// }
|
||||
|
||||
// time
|
||||
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||
let today = moment().format('YYYY-MM-DD');
|
||||
@@ -380,6 +440,16 @@ const reservationValidate = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
if (getPartner.i_partner != req.partner_id_token) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'partner is not match',
|
||||
data: {},
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
// get settingan dari parameter apakah nomor kartu yang di request harus di cek dengan data card product CMS atau tidak
|
||||
// winston.logger.debug(
|
||||
@@ -617,16 +687,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) {
|
||||
@@ -694,6 +770,9 @@ const reservationValidateV2 = async (req, res) => {
|
||||
)}`
|
||||
);
|
||||
|
||||
// trim card number
|
||||
// card_number = card_number.trim();
|
||||
|
||||
// check validator
|
||||
let err = validationResult(req, res);
|
||||
if (!err.isEmpty()) {
|
||||
@@ -713,6 +792,18 @@ const reservationValidateV2 = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
let cardBlacklist = await model.getCardBlacklist(card_number);
|
||||
if (cardBlacklist) {
|
||||
if (cardBlacklist.c_status == 'B') {
|
||||
result = {
|
||||
code: '445',
|
||||
message: 'Card is Blacklisted',
|
||||
data: {},
|
||||
};
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
}
|
||||
|
||||
// log debug
|
||||
// pengecekkan nomor kartu yang di request adalah kartu production atau bukan berdasarkan settingan di .ENV dengan constanta SERVER_FOR.
|
||||
// Jika settingan .ENV SERVER_FOR adalah production dan nomor kartu KMT yang di request adalah kartu development maka sistem online topup akan menolaknya. Begitupun sebaliknya
|
||||
@@ -722,44 +813,44 @@ const reservationValidateV2 = async (req, res) => {
|
||||
// );
|
||||
|
||||
// jika settingan diperuntukan untuk production
|
||||
if (process.env.SERVER_FOR == 'production') {
|
||||
// kartu yang di request bukan kartu production maka akan di tolak
|
||||
if (card_number.substring(0, 1) != '1') {
|
||||
result = {
|
||||
code: '400',
|
||||
message: "It's not production card number.",
|
||||
data: {},
|
||||
};
|
||||
// if (process.env.SERVER_FOR == 'production') {
|
||||
// // kartu yang di request bukan kartu production maka akan di tolak
|
||||
// if (card_number.substring(0, 1) != '1') {
|
||||
// result = {
|
||||
// code: '400',
|
||||
// message: "It's not production card number.",
|
||||
// data: {},
|
||||
// };
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE RESERVATION-VALIDATE-V2 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
// // log warn
|
||||
// winston.logger.warn(
|
||||
// `${uniqueCode} [ RESPONSE RESERVATION-VALIDATE-V2 ]: ${JSON.stringify(
|
||||
// result
|
||||
// )}`
|
||||
// );
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
} else {
|
||||
// jika settingan bukan diperuntukan untuk production, bisa development atau local atau yang lainnya dan kemudian kartu yang di request merupakan kartu production maka akan di tolak
|
||||
if (card_number.substring(0, 1) == '1') {
|
||||
result = {
|
||||
code: '400',
|
||||
message:
|
||||
"It's production card number. Please use the development card number.",
|
||||
data: {},
|
||||
};
|
||||
// return res.status(200).json(result);
|
||||
// }
|
||||
// } else {
|
||||
// // jika settingan bukan diperuntukan untuk production, bisa development atau local atau yang lainnya dan kemudian kartu yang di request merupakan kartu production maka akan di tolak
|
||||
// if (card_number.substring(0, 1) == '1') {
|
||||
// result = {
|
||||
// code: '400',
|
||||
// message:
|
||||
// "It's production card number. Please use the development card number.",
|
||||
// data: {},
|
||||
// };
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE RESERVATION-VALIDATE-V2 ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
// // log warn
|
||||
// winston.logger.warn(
|
||||
// `${uniqueCode} [ RESPONSE RESERVATION-VALIDATE-V2 ]: ${JSON.stringify(
|
||||
// result
|
||||
// )}`
|
||||
// );
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
}
|
||||
// return res.status(200).json(result);
|
||||
// }
|
||||
// }
|
||||
|
||||
// time
|
||||
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||
@@ -794,6 +885,16 @@ const reservationValidateV2 = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
if (getPartner.i_partner != req.partner_id_token) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'partner is not match',
|
||||
data: {},
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
// get settingan dari parameter apakah nomor kartu yang di request harus di cek dengan data card product CMS atau tidak
|
||||
// winston.logger.debug(
|
||||
@@ -1046,16 +1147,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1159,6 +1266,9 @@ const reservation = async (req, res) => {
|
||||
`${uniqueCode} [ REQUEST RESERVATION ]: ${JSON.stringify(req.body)}`
|
||||
);
|
||||
|
||||
// trim card number
|
||||
card_number = card_number.trim();
|
||||
|
||||
// check validator
|
||||
let err = validationResult(req, res);
|
||||
if (!err.isEmpty()) {
|
||||
@@ -1184,42 +1294,54 @@ const reservation = async (req, res) => {
|
||||
// `${uniqueCode} [ PROCESSING RESERVATION ] checking production card number or not...`
|
||||
// );
|
||||
|
||||
// jika settingan diperuntukan untuk production
|
||||
if (process.env.SERVER_FOR == 'production') {
|
||||
// kartu yang di request bukan kartu production maka akan di tolak
|
||||
if (card_number.substring(0, 1) != '1') {
|
||||
let cardBlacklist = await model.getCardBlacklist(card_number);
|
||||
if (cardBlacklist) {
|
||||
if (cardBlacklist.c_status == 'B') {
|
||||
result = {
|
||||
code: '400',
|
||||
message: "It's not production card number.",
|
||||
code: '445',
|
||||
message: 'Card is Blacklisted',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE RESERVATION ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
} else {
|
||||
// jika settingan bukan diperuntukan untuk production, bisa development atau local atau yang lainnya dan kemudian kartu yang di request merupakan kartu production maka akan di tolak
|
||||
if (card_number.substring(0, 1) == '1') {
|
||||
result = {
|
||||
code: '400',
|
||||
message:
|
||||
"It's production card number. Please use the development card number.",
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE RESERVATION ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
}
|
||||
|
||||
// jika settingan diperuntukan untuk production
|
||||
// if (process.env.SERVER_FOR == 'production') {
|
||||
// // kartu yang di request bukan kartu production maka akan di tolak
|
||||
// if (card_number.substring(0, 1) != '1') {
|
||||
// result = {
|
||||
// code: '400',
|
||||
// message: "It's not production card number.",
|
||||
// data: {},
|
||||
// };
|
||||
|
||||
// // log warn
|
||||
// winston.logger.warn(
|
||||
// `${uniqueCode} [ RESPONSE RESERVATION ]: ${JSON.stringify(result)}`
|
||||
// );
|
||||
|
||||
// return res.status(200).json(result);
|
||||
// }
|
||||
// } else {
|
||||
// // jika settingan bukan diperuntukan untuk production, bisa development atau local atau yang lainnya dan kemudian kartu yang di request merupakan kartu production maka akan di tolak
|
||||
// if (card_number.substring(0, 1) == '1') {
|
||||
// result = {
|
||||
// code: '400',
|
||||
// message:
|
||||
// "It's production card number. Please use the development card number.",
|
||||
// data: {},
|
||||
// };
|
||||
|
||||
// // log warn
|
||||
// winston.logger.warn(
|
||||
// `${uniqueCode} [ RESPONSE RESERVATION ]: ${JSON.stringify(result)}`
|
||||
// );
|
||||
|
||||
// return res.status(200).json(result);
|
||||
// }
|
||||
// }
|
||||
|
||||
// time
|
||||
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||
let today = moment().format('YYYY-MM-DD');
|
||||
@@ -1249,6 +1371,16 @@ const reservation = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
if (getPartner.i_partner != req.partner_id_token) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'partner is not match',
|
||||
data: {},
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
// get settingan dari parameter apakah nomor kartu yang di request harus di cek dengan data card product CMS atau tidak
|
||||
// winston.logger.debug(
|
||||
@@ -1497,16 +1629,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1803,6 +1941,9 @@ const reservationV2 = async (req, res) => {
|
||||
`${uniqueCode} [ REQUEST RESERVATION-V2 ]: ${JSON.stringify(req.body)}`
|
||||
);
|
||||
|
||||
// trim card number
|
||||
// card_number = card_number.trim();
|
||||
|
||||
// check validator
|
||||
let err = validationResult(req, res);
|
||||
if (!err.isEmpty()) {
|
||||
@@ -1889,6 +2030,20 @@ const reservationV2 = async (req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
let cardBlacklist = await model.getCardBlacklist(
|
||||
reservationData.card_number
|
||||
);
|
||||
if (cardBlacklist) {
|
||||
if (cardBlacklist.c_status == 'B') {
|
||||
result = {
|
||||
code: '445',
|
||||
message: 'Card is Blacklisted',
|
||||
data: {},
|
||||
};
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
}
|
||||
|
||||
if (amount) {
|
||||
if (reservationData.amount != amount) {
|
||||
result = {
|
||||
@@ -1967,40 +2122,40 @@ const reservationV2 = async (req, res) => {
|
||||
// );
|
||||
|
||||
// jika settingan diperuntukan untuk production
|
||||
if (process.env.SERVER_FOR == 'production') {
|
||||
// kartu yang di request bukan kartu production maka akan di tolak
|
||||
if (card_number.substring(0, 1) != '1') {
|
||||
result = {
|
||||
code: '400',
|
||||
message: "It's not production card number.",
|
||||
data: {},
|
||||
};
|
||||
// if (process.env.SERVER_FOR == 'production') {
|
||||
// // kartu yang di request bukan kartu production maka akan di tolak
|
||||
// if (card_number.substring(0, 1) != '1') {
|
||||
// result = {
|
||||
// code: '400',
|
||||
// message: "It's not production card number.",
|
||||
// data: {},
|
||||
// };
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE RESERVATION-V2 ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
// // log warn
|
||||
// winston.logger.warn(
|
||||
// `${uniqueCode} [ RESPONSE RESERVATION-V2 ]: ${JSON.stringify(result)}`
|
||||
// );
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
} else {
|
||||
// jika settingan bukan diperuntukan untuk production, bisa development atau local atau yang lainnya dan kemudian kartu yang di request merupakan kartu production maka akan di tolak
|
||||
if (card_number.substring(0, 1) == '1') {
|
||||
result = {
|
||||
code: '400',
|
||||
message:
|
||||
"It's production card number. Please use the development card number.",
|
||||
data: {},
|
||||
};
|
||||
// return res.status(200).json(result);
|
||||
// }
|
||||
// } else {
|
||||
// // jika settingan bukan diperuntukan untuk production, bisa development atau local atau yang lainnya dan kemudian kartu yang di request merupakan kartu production maka akan di tolak
|
||||
// if (card_number.substring(0, 1) == '1') {
|
||||
// result = {
|
||||
// code: '400',
|
||||
// message:
|
||||
// "It's production card number. Please use the development card number.",
|
||||
// data: {},
|
||||
// };
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE RESERVATION-V2 ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
// // log warn
|
||||
// winston.logger.warn(
|
||||
// `${uniqueCode} [ RESPONSE RESERVATION-V2 ]: ${JSON.stringify(result)}`
|
||||
// );
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
}
|
||||
// return res.status(200).json(result);
|
||||
// }
|
||||
// }
|
||||
|
||||
// time
|
||||
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||
@@ -2031,6 +2186,16 @@ const reservationV2 = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
if (getPartner.i_partner != req.partner_id_token) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'partner is not match',
|
||||
data: {},
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
// get settingan dari parameter apakah nomor kartu yang di request harus di cek dengan data card product CMS atau tidak
|
||||
// winston.logger.debug(
|
||||
@@ -2298,16 +2463,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2482,6 +2653,8 @@ const reservationV2 = async (req, res) => {
|
||||
// `${uniqueCode} [ PROCESSING RESERVATION-V2 ] inserting reservation transaction...`
|
||||
// );
|
||||
|
||||
// (belum) ada issue disini, jadi ada case reservation number nya sama, terus error query harusnya ada handle response message nya, yg sekarang malah masuk ke blok reservation saved successfully.
|
||||
|
||||
// insert transaction
|
||||
let insert = await model.insertReservation(data);
|
||||
|
||||
@@ -2665,6 +2838,16 @@ const cancelReservationValidate = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
if (getPartner.i_partner != req.partner_id_token) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'partner is not match',
|
||||
data: {},
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
// proses pengecekkan status reservation number yang di request
|
||||
// winston.logger.debug(
|
||||
@@ -2850,6 +3033,16 @@ const cancelReservation = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
if (getPartner.i_partner != req.partner_id_token) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'partner is not match',
|
||||
data: {},
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
// proses pengecekkan status reservation number yang di request
|
||||
// winston.logger.debug(
|
||||
@@ -3326,6 +3519,16 @@ const cancelReservationValidateV2 = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
if (getPartner.i_partner != req.partner_id_token) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'partner is not match',
|
||||
data: {},
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
let getReservationCanBeCanceled;
|
||||
|
||||
// jika cancelation reservation dilakukan dengan menggunakan ref no
|
||||
@@ -3744,6 +3947,16 @@ const cancelReservationV2 = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
if (getPartner.i_partner != req.partner_id_token) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'partner is not match',
|
||||
data: {},
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
// proses pengecekkan status reservation number yang di request
|
||||
// winston.logger.debug(
|
||||
@@ -3990,6 +4203,16 @@ const cancelReservationV2_1 = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
if (getPartner.i_partner != req.partner_id_token) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'partner is not match',
|
||||
data: {},
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
// proses pengecekkan status reservation number yang di request
|
||||
// winston.logger.debug(
|
||||
@@ -4218,6 +4441,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
|
||||
@@ -4245,6 +4470,16 @@ const getFeeSharing = async (req, res) => {
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
if (getPartner.i_partner != req.partner_id_token) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'partner is not match',
|
||||
data: {},
|
||||
};
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// set default issuer fee
|
||||
let issuerFee = 0;
|
||||
let channelFee = 0;
|
||||
@@ -4253,16 +4488,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4293,6 +4534,51 @@ const getFeeSharing = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
const decrpytRequest = 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 = {};
|
||||
|
||||
let { reservation_data } = req.body;
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ REQUEST DECRYPT ]: ${JSON.stringify(req.body)}`
|
||||
);
|
||||
|
||||
reservationData = helper.decryptText(reservation_data);
|
||||
// parsing data to json format
|
||||
parseData = JSON.parse(reservationData);
|
||||
result = {
|
||||
code: '00',
|
||||
message: 'decrypted successfully.',
|
||||
data: parseData,
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ RESPONSE DECRYPT ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
} catch (error) {
|
||||
result = {
|
||||
code: '500',
|
||||
message: 'decrypted failed.',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.error(
|
||||
`${uniqueCode} [ RESPONSE DECRYPT ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
validate,
|
||||
checkReservation,
|
||||
@@ -4309,4 +4595,5 @@ module.exports = {
|
||||
cancelReservationV2,
|
||||
cancelReservationV2_1,
|
||||
getFeeSharing,
|
||||
decrpytRequest,
|
||||
};
|
||||
|
||||
@@ -72,6 +72,15 @@ const getIssuer = (id, time) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET IS CARD ADDED TO BLACKLIST
|
||||
const getCardBlacklist = (card_number) => {
|
||||
let result = knex('public.t_m_card_blacklist')
|
||||
.select('c_status')
|
||||
.where('c_card_number', card_number)
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET RESERVATION EXPIRATION DATE FROM GLOBAL PARAMETER
|
||||
const getReservationExpirationDateValue = () => {
|
||||
let result = knex('t_m_global_parameter')
|
||||
@@ -540,6 +549,7 @@ module.exports = {
|
||||
getReservationNumberSequence,
|
||||
getPartner,
|
||||
getIssuer,
|
||||
getCardBlacklist,
|
||||
getReservationExpirationDateValue,
|
||||
getReservationExpirationDateMeasure,
|
||||
getCheckByCardProductStatusValue,
|
||||
|
||||
@@ -10,6 +10,13 @@ router.get(
|
||||
controller.apiGenerateCahsIn
|
||||
);
|
||||
|
||||
router.get(
|
||||
"/online/cash-in-sales",
|
||||
// auth.authenticateToken,
|
||||
// controller.validate("generateInvoice"),
|
||||
controller.apiGenerateCashInSales
|
||||
);
|
||||
|
||||
router.post(
|
||||
"/online/cash-in/posting",
|
||||
// auth.authenticateToken,
|
||||
|
||||
@@ -1,43 +1,82 @@
|
||||
const { Router } = require("express");
|
||||
const { Router } = require('express');
|
||||
const router = Router();
|
||||
|
||||
const auth = require("../middlewares/jwt.middleware");
|
||||
const _readData = require("../modules/hsm/readData");
|
||||
const _readDataResp = require("../modules/hsm/readDataResp");
|
||||
const auth = require('../middlewares/jwt.middleware');
|
||||
|
||||
const _auth1 = require("../modules/hsm/authenticate1");
|
||||
const _auth2 = require("../modules/hsm/authenticate2");
|
||||
const _authResp = require("../modules/hsm/authenticateResp");
|
||||
// Topup
|
||||
const _auth1 = require('../modules/hsm/topup/topup_1');
|
||||
const _auth2 = require('../modules/hsm/topup/topup_2');
|
||||
const _authResp = require('../modules/hsm/topup/topup_3');
|
||||
|
||||
const _topup = require("../modules/hsm/topup");
|
||||
const _topupResp = require("../modules/hsm/topupResp");
|
||||
const _readData = require('../modules/hsm/topup/topup_4');
|
||||
const _readDataResp = require('../modules/hsm/topup/topup_5');
|
||||
|
||||
const _end = require("../modules/hsm/endTranscation");
|
||||
const _topup = require('../modules/hsm/topup/topup_6');
|
||||
const _topupResp = require('../modules/hsm/topup/topup_7');
|
||||
|
||||
const _getService = require("../modules/hsm/service_block");
|
||||
const _end = require('../modules/hsm/topup/topup_8');
|
||||
|
||||
const _getService = require('../modules/hsm/topup/service_block');
|
||||
|
||||
router.post("/topup1", auth.authenticateToken, _auth1);
|
||||
router.post("/topup2", auth.authenticateToken, _auth2);
|
||||
router.post("/topup3", auth.authenticateToken, _authResp);
|
||||
router.post("/topup4", auth.authenticateToken, _readData);
|
||||
router.post("/topup5", auth.authenticateToken, _readDataResp);
|
||||
router.post('/topup1', auth.authenticateToken, _auth1);
|
||||
router.post('/topup2', auth.authenticateToken, _auth2);
|
||||
router.post('/topup3', auth.authenticateToken, _authResp);
|
||||
router.post('/topup4', auth.authenticateToken, _readData);
|
||||
router.post('/topup5', auth.authenticateToken, _readDataResp);
|
||||
|
||||
router.post(
|
||||
"/topup6",
|
||||
'/topup6',
|
||||
auth.authenticateToken,
|
||||
_topup.validate("topup"),
|
||||
_topup.validate('topup'),
|
||||
_topup.controller
|
||||
);
|
||||
router.post(
|
||||
"/topup7",
|
||||
'/topup7',
|
||||
auth.authenticateToken,
|
||||
_topupResp.validate("topupResponse"),
|
||||
_topupResp.validate('topupResponse'),
|
||||
_topupResp.controller
|
||||
);
|
||||
|
||||
router.post("/topup8", auth.authenticateToken, _end);
|
||||
router.post('/topup8', auth.authenticateToken, _end);
|
||||
|
||||
router.get("/getservice", auth.authenticateToken, _getService);
|
||||
router.get('/getservice', auth.authenticateToken, _getService);
|
||||
|
||||
// Clear Card
|
||||
const _authClear1 = require('../modules/hsm/clear_card/clear_1');
|
||||
const _authClear2 = require('../modules/hsm/clear_card/clear_2');
|
||||
const _authRespClear = require('../modules/hsm/clear_card/clear_3');
|
||||
|
||||
const _readDataClear = require('../modules/hsm/clear_card/clear_4');
|
||||
const _readDataRespClear = require('../modules/hsm/clear_card/clear_5');
|
||||
|
||||
const _clear = require('../modules/hsm/clear_card/clear_6');
|
||||
const _clearResp = require('../modules/hsm/clear_card/clear_7');
|
||||
|
||||
const _endClear = require('../modules/hsm/clear_card/clear_8');
|
||||
|
||||
const _getServiceClear = require('../modules/hsm/clear_card/service_block');
|
||||
|
||||
router.post('/clear1', auth.authenticateToken, _authClear1);
|
||||
router.post('/clear2', auth.authenticateToken, _authClear2);
|
||||
router.post('/clear3', auth.authenticateToken, _authRespClear);
|
||||
router.post('/clear4', auth.authenticateToken, _readDataClear);
|
||||
router.post('/clear5', auth.authenticateToken, _readDataRespClear);
|
||||
|
||||
router.post(
|
||||
'/clear6',
|
||||
auth.authenticateToken,
|
||||
_clear.validate('clear'),
|
||||
_clear.controller
|
||||
);
|
||||
router.post(
|
||||
'/clear7',
|
||||
auth.authenticateToken,
|
||||
_clearResp.validate('clearResponse'),
|
||||
_clearResp.controller
|
||||
);
|
||||
|
||||
router.post('/clear8', auth.authenticateToken, _endClear);
|
||||
|
||||
router.get('/clear/getservice', auth.authenticateToken, _getServiceClear);
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
const express = require("express");
|
||||
const router = express.Router();
|
||||
const auth = require("../middlewares/jwt.middleware");
|
||||
const controller = require("../modules/pos/pos.controller");
|
||||
|
||||
// API Sample Get Last Balance
|
||||
router.post(
|
||||
"/pos/card-lastbalance",
|
||||
auth.authenticateToken,
|
||||
controller.validate("validateLastBalance"),
|
||||
controller.checkLastBalance
|
||||
);
|
||||
|
||||
// API Validate Sales MT
|
||||
router.post(
|
||||
"/pos/cardsales/validate",
|
||||
auth.authenticateToken,
|
||||
controller.validate("validateCardSales"),
|
||||
controller.validateSales
|
||||
);
|
||||
|
||||
// API Validate Topup MT
|
||||
router.post(
|
||||
"/pos/cardtopup/validate",
|
||||
auth.authenticateToken,
|
||||
controller.validate("validateCardTopup"),
|
||||
controller.validateTopup
|
||||
);
|
||||
|
||||
// API Validate Redeem MT
|
||||
router.post(
|
||||
"/pos/cardredeem/validate",
|
||||
auth.authenticateToken,
|
||||
controller.validate("validateCardRedeem"),
|
||||
controller.validateRedeem
|
||||
);
|
||||
|
||||
// API Check Blacklist
|
||||
router.post(
|
||||
"/pos/checkcardblacklist",
|
||||
auth.authenticateToken,
|
||||
controller.validate("checkBlacklist"),
|
||||
controller.checkBlacklist
|
||||
);
|
||||
|
||||
// API Validate Replacement MT
|
||||
router.post(
|
||||
"/pos/cardreplacement/validate",
|
||||
auth.authenticateToken,
|
||||
controller.validate("validateCardReplacement"),
|
||||
controller.validateReplacement
|
||||
);
|
||||
|
||||
// API Replacement Confirm
|
||||
router.post(
|
||||
"/pos/cardreplacement/confirm",
|
||||
auth.authenticateToken,
|
||||
controller.validate("cardReplacementConfirm"),
|
||||
controller.replacementConfirm
|
||||
);
|
||||
|
||||
module.exports = router;
|
||||
@@ -0,0 +1,13 @@
|
||||
const express = require("express");
|
||||
const router = express.Router();
|
||||
// const auth = require("../middlewares/jwt.middleware");
|
||||
const controller = require("../modules/refundkmt/refundkmt.controller");
|
||||
|
||||
router.post(
|
||||
"/refund-callback",
|
||||
// auth.authenticateToken,
|
||||
controller.validate("callbackOy"),
|
||||
controller.callbackOy
|
||||
);
|
||||
|
||||
module.exports = router;
|
||||
@@ -98,6 +98,12 @@ router.post(
|
||||
controller.getFeeSharing
|
||||
);
|
||||
|
||||
router.post(
|
||||
'/reservation/decrypt',
|
||||
auth.authenticateToken,
|
||||
controller.decrpytRequest
|
||||
);
|
||||
|
||||
// router.post(
|
||||
// '/reservation/cancel/v2.1',
|
||||
// auth.authenticateToken,
|
||||
|
||||
@@ -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
|
||||
@@ -31,7 +45,10 @@ DB_PASSWORD_POOLING=inhc0mmute_cms
|
||||
# ==================================== LOKI =====================================
|
||||
LOKI_URL=http://10.20.14.30:3100
|
||||
|
||||
# ==================================== APP PROMETHEUS =====================================
|
||||
# ==================================== LOKI =====================================
|
||||
LOKI_URL=http://localhost:3100
|
||||
|
||||
# =============================== 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 = parseInt(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 = parseInt(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
+1528
-1568
File diff suppressed because it is too large
Load Diff
+7
-6
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "topuponline",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"version": "1.5.7",
|
||||
"description": "change file rotate log from 90 days to 60 days",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "nodemon index",
|
||||
@@ -22,7 +22,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/mohamadihsan/topuponline#readme",
|
||||
"dependencies": {
|
||||
"axios": "^0.27.2",
|
||||
"axios": "^1.7.7",
|
||||
"bcrypt": "^5.0.1",
|
||||
"body-parser": "^1.19.0",
|
||||
"check-internet-connected": "^2.0.6",
|
||||
@@ -32,8 +32,8 @@
|
||||
"express": "^4.17.1",
|
||||
"express-validator": "^6.10.0",
|
||||
"express-winston": "^4.2.0",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"knex": "^0.95.4",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"knex": "^3.1.0",
|
||||
"moment": "^2.29.3",
|
||||
"node-cron": "^3.0.1",
|
||||
"pg": "^8.6.0",
|
||||
@@ -41,11 +41,12 @@
|
||||
"prom-client": "^14.2.0",
|
||||
"redis": "^4.6.5",
|
||||
"response-time": "^2.3.2",
|
||||
"sticky-session": "^0.1.0",
|
||||
"winston": "^3.7.2",
|
||||
"winston-daily-rotate-file": "^4.7.1",
|
||||
"winston-loki": "^6.0.6",
|
||||
"ws": "^8.5.0",
|
||||
"xml2js": "^0.4.23"
|
||||
"xml2js": "^0.6.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jest": "^29.0.2",
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 48 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 9.7 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 32 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 60 KiB |
@@ -12,7 +12,9 @@ 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 posRoute = require('../application/routes/pos.routes');
|
||||
const pooling = require('../application/routes/pooling.routes');
|
||||
const refundkmtRoute = require('../application/routes/refundkmt.routes');
|
||||
const cron = require('node-cron');
|
||||
const moment = require('moment');
|
||||
require('dotenv').config();
|
||||
@@ -51,6 +53,9 @@ var corsOptions = {
|
||||
// app.use(cors(corsOptions));
|
||||
app.use(cors(corsOptions));
|
||||
|
||||
// add static file
|
||||
app.use(express.static('public'));
|
||||
|
||||
// parse requests of content-type - application/json
|
||||
app.use(bodyParser.json());
|
||||
|
||||
@@ -79,7 +84,9 @@ app.use('/api/', paymentReconRoute);
|
||||
app.use('/api/', reservationRoute);
|
||||
app.use('/api/', invoiceRoute);
|
||||
app.use('/api/', cashinRoute);
|
||||
app.use('/api/', posRoute);
|
||||
app.use('/api/', pooling);
|
||||
app.use('/api/', refundkmtRoute);
|
||||
|
||||
// ============================== SAP SCHEDULLER =============================
|
||||
|
||||
|
||||
Reference in New Issue
Block a user