mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-06 10:06:27 +00:00
Compare commits
212 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 | |||
| 083e0af4a0 | |||
| 8c0b6f7e7c | |||
| b87e6cc450 | |||
| cee0352271 | |||
| afc72b73ec | |||
| dfce874ce9 | |||
| a2079a7263 | |||
| 19de123628 | |||
| b942d114ad | |||
| 69ab898bf3 | |||
| 7c66ebe702 | |||
| 84de02de26 | |||
| d5df8d4f32 | |||
| ae74b4c1bd | |||
| dab14b66c4 | |||
| 46e3cd689b | |||
| 6b0d67ee60 | |||
| 481858117d | |||
| 7805bc902b | |||
| 1fd9940706 | |||
| 95f4a03e81 | |||
| 5d8f4d086e | |||
| 4c7230ba6b | |||
| 409fe6f0ce | |||
| 1b2eff69b4 | |||
| d0e3fb289e | |||
| e3ab361b24 | |||
| fc28f4e767 | |||
| 14026e8bf0 | |||
| 4f69c84b5f | |||
| 3c1fc92d59 | |||
| 44f81586e3 | |||
| a333ddb58f | |||
| e51a7bc98c | |||
| f2c5d65ec0 | |||
| af52b6916b | |||
| bcb9225466 | |||
| ad0942a93d | |||
| 90dfdc8857 | |||
| 4828a230fb | |||
| 476235440c | |||
| 933e83cd1a | |||
| 04885f22d6 | |||
| 97860df622 | |||
| 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 moment = require('moment');
|
||||||
const winston = require("winston");
|
const winston = require('winston');
|
||||||
const loki = require("winston-loki");
|
const loki = require('winston-loki');
|
||||||
require("winston-daily-rotate-file");
|
require('winston-daily-rotate-file');
|
||||||
require("dotenv").config();
|
require('dotenv').config();
|
||||||
const { combine, timestamp, printf, colorize, align, json } = winston.format;
|
const { combine, timestamp, printf, colorize, align, json } = winston.format;
|
||||||
let lokiUrl = process.env.LOKI_URL;
|
let lokiUrl = process.env.LOKI_URL;
|
||||||
|
|
||||||
@@ -18,32 +18,32 @@ var log;
|
|||||||
|
|
||||||
const fileRotateTransport = new winston.transports.DailyRotateFile({
|
const fileRotateTransport = new winston.transports.DailyRotateFile({
|
||||||
filename: `./lokiLog/%DATE%-onlinetopup.log`,
|
filename: `./lokiLog/%DATE%-onlinetopup.log`,
|
||||||
datePattern: "YYYY-MM-DD",
|
datePattern: 'YYYY-MM-DD',
|
||||||
maxFiles: "1d",
|
maxFiles: '1d',
|
||||||
});
|
});
|
||||||
|
|
||||||
if (
|
if (
|
||||||
process.env.NODE_ENV == "production" ||
|
process.env.NODE_ENV == 'production' ||
|
||||||
process.env.NODE_ENV == "PRODUCTION"
|
process.env.NODE_ENV == 'PRODUCTION'
|
||||||
) {
|
) {
|
||||||
log = winston.createLogger({
|
log = winston.createLogger({
|
||||||
levels: logLevels,
|
levels: logLevels,
|
||||||
level: process.env.LOG_LEVEL || "info",
|
level: process.env.LOG_LEVEL || 'info',
|
||||||
exitOnError: false,
|
exitOnError: false,
|
||||||
// format: combine(timestamp(), json()),
|
// format: combine(timestamp(), json()),
|
||||||
format: combine(
|
format: combine(
|
||||||
// colorize({ all: true }),
|
// colorize({ all: true }),
|
||||||
timestamp({
|
timestamp({
|
||||||
format: "YYYY-MM-DD HH:mm:ss.SSS",
|
format: 'YYYY-MM-DD HH:mm:ss.SSS',
|
||||||
}),
|
}),
|
||||||
align(),
|
align(),
|
||||||
printf((info) => `[${info.timestamp}] ${info.level}: ${info.message}`)
|
printf((info) => `[${info.timestamp}] ${info.level}: ${info.message}`)
|
||||||
),
|
),
|
||||||
defaultMeta: { service: "topuponline" },
|
defaultMeta: { service: 'topuponline' },
|
||||||
transports: [
|
transports: [
|
||||||
new loki({
|
new loki({
|
||||||
host: lokiUrl,
|
host: lokiUrl,
|
||||||
labels: { app: "topuponline" },
|
labels: { app: 'topuponline' },
|
||||||
json: true,
|
json: true,
|
||||||
format: json(),
|
format: json(),
|
||||||
replaceTimestamp: true,
|
replaceTimestamp: true,
|
||||||
@@ -59,7 +59,7 @@ if (
|
|||||||
transports: [
|
transports: [
|
||||||
new loki({
|
new loki({
|
||||||
host: lokiUrl,
|
host: lokiUrl,
|
||||||
labels: { app: "topuponline" },
|
labels: { app: 'topuponline' },
|
||||||
handleExceptions: true,
|
handleExceptions: true,
|
||||||
handleRejections: true,
|
handleRejections: true,
|
||||||
clearOnError: 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(
|
log.add(
|
||||||
new winston.transports.Console({
|
new winston.transports.Console({
|
||||||
// format: winston.format.cli(),
|
// format: winston.format.cli(),
|
||||||
format: combine(
|
format: combine(
|
||||||
colorize({ all: true }),
|
colorize({ all: true }),
|
||||||
timestamp({
|
timestamp({
|
||||||
format: "YYYY-MM-DD HH:mm:ss.SSS",
|
format: 'YYYY-MM-DD HH:mm:ss.SSS',
|
||||||
}),
|
}),
|
||||||
align(),
|
align(),
|
||||||
printf((info) => `[${info.timestamp}] ${info.level}: ${info.message}`)
|
printf((info) => `[${info.timestamp}] ${info.level}: ${info.message}`)
|
||||||
|
|||||||
@@ -1,49 +1,59 @@
|
|||||||
const jwt = require("jsonwebtoken");
|
const jwt = require('jsonwebtoken');
|
||||||
const helper = require("../helpers/helper");
|
const helper = require('../helpers/helper');
|
||||||
|
const winston = require('../helpers/winston.logger');
|
||||||
|
|
||||||
const generateRefreshToken = (req) => {
|
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 = {
|
let signOptions = {
|
||||||
issuer: 'CMS Kereta Commuter Indonesia',
|
issuer: 'CMS Kereta Commuter Indonesia',
|
||||||
expiresIn: expiresIn,
|
expiresIn: expiresIn,
|
||||||
}
|
};
|
||||||
|
|
||||||
return jwt.sign(req, process.env.REFRESH_TOKEN_SECRET, signOptions);
|
return jwt.sign(req, process.env.REFRESH_TOKEN_SECRET, signOptions);
|
||||||
};
|
};
|
||||||
|
|
||||||
const authenticateRefreshToken = (req, res, next) => {
|
const authenticateRefreshToken = (req, res, next) => {
|
||||||
|
|
||||||
let verifyOptions = {
|
let verifyOptions = {
|
||||||
issuer: 'CMS Kereta Commuter Indonesia',
|
issuer: 'CMS Kereta Commuter Indonesia',
|
||||||
}
|
};
|
||||||
|
|
||||||
jwt.verify(req.header("refresh_token"), process.env.REFRESH_TOKEN_SECRET, verifyOptions, (err, data) => {
|
jwt.verify(
|
||||||
if (err) {
|
req.headers['refresh-token'],
|
||||||
return res.json({
|
process.env.REFRESH_TOKEN_SECRET,
|
||||||
code: "400",
|
verifyOptions,
|
||||||
message: "Refresh Token is invalid. Please login!",
|
(err, data) => {
|
||||||
data: {},
|
if (err) {
|
||||||
});
|
return res.json({
|
||||||
|
code: '400',
|
||||||
|
message: 'Refresh Token is invalid. Please login!!',
|
||||||
|
data: {},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
next();
|
||||||
}
|
}
|
||||||
|
);
|
||||||
next();
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const generateAccessToken = (req) => {
|
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 = {
|
let signOptions = {
|
||||||
issuer: 'CMS Kereta Commuter Indonesia',
|
issuer: 'CMS Kereta Commuter Indonesia',
|
||||||
expiresIn: expiresIn,
|
expiresIn: expiresIn,
|
||||||
}
|
};
|
||||||
|
|
||||||
if (req.user_group_id == "1") {
|
if (req.user_group_id == '1') {
|
||||||
expiresIn = parseInt(process.env.JWT_EXPIRATION_ADMIN_WEB);
|
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);
|
expiresIn = parseInt(process.env.JWT_EXPIRATION_MOBILE_PHONE);
|
||||||
} else if (
|
} else if (
|
||||||
req.user_group_id == "3" ||
|
req.user_group_id == '3' ||
|
||||||
req.user_group_id == "4" ||
|
req.user_group_id == '4' ||
|
||||||
req.user_group_id == "5"
|
req.user_group_id == '5'
|
||||||
) {
|
) {
|
||||||
expiresIn = parseInt(process.env.JWT_EXPIRATION_TERMINAL);
|
expiresIn = parseInt(process.env.JWT_EXPIRATION_TERMINAL);
|
||||||
}
|
}
|
||||||
@@ -52,43 +62,59 @@ const generateAccessToken = (req) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const authenticateToken = async (req, res, next) => {
|
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) {
|
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) {
|
if (!token) {
|
||||||
return res.json({
|
return res.json({
|
||||||
code: "401",
|
code: '401',
|
||||||
message: "Token is required",
|
message: 'Token is required',
|
||||||
data: {},
|
data: {},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let verifyOptions = {
|
let verifyOptions = {
|
||||||
issuer: 'CMS Kereta Commuter Indonesia',
|
issuer: 'CMS Kereta Commuter Indonesia',
|
||||||
}
|
};
|
||||||
|
|
||||||
await jwt.verify(token, process.env.TOKEN_SECRET, verifyOptions, (err, data) => {
|
await jwt.verify(
|
||||||
if (err) {
|
token,
|
||||||
return res.json({
|
process.env.TOKEN_SECRET,
|
||||||
code: "402",
|
verifyOptions,
|
||||||
message: "Invalid Token.",
|
(err, data) => {
|
||||||
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 {
|
} else {
|
||||||
return res.json({
|
return res.json({
|
||||||
code: "400",
|
code: '400',
|
||||||
message: "Header not found",
|
message: 'Header not found',
|
||||||
data: {},
|
data: {},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,8 +121,71 @@ const setReservationNumberSequence = async (partner_id, sequence) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getLoadBalanceNumberSequence = async (req, res, next) => {
|
||||||
|
// set default load_balance_number_sequence dari partner apapun is null
|
||||||
|
req.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
|
||||||
|
req.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)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
};
|
||||||
|
|
||||||
|
const setLoadBalanceNumberSequence = async (partner_id, sequence) => {
|
||||||
|
// 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 }
|
||||||
|
|
||||||
|
let setValue = {
|
||||||
|
date: moment().format('YYYY-MM-DD'),
|
||||||
|
sequence: parseInt(sequence),
|
||||||
|
};
|
||||||
|
|
||||||
|
await redisClient.SET(
|
||||||
|
`load_balance_number_sequence_${partner_id}`,
|
||||||
|
JSON.stringify(setValue)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
redisMiddleware,
|
redisMiddleware,
|
||||||
getReservationNumberSequence,
|
getReservationNumberSequence,
|
||||||
setReservationNumberSequence,
|
setReservationNumberSequence,
|
||||||
|
getLoadBalanceNumberSequence,
|
||||||
|
setLoadBalanceNumberSequence,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -75,10 +75,14 @@ const loginPartnerUser = async (req, res, next) => {
|
|||||||
let { email, password } = req.body;
|
let { email, password } = req.body;
|
||||||
|
|
||||||
// log info
|
// log info
|
||||||
winston.logger.info(
|
// winston.logger.info(
|
||||||
`${uniqueCode} [ REQUEST LOGIN-PARTNER-USER ]: ${JSON.stringify({
|
// `${uniqueCode} [ REQUEST LOGIN-PARTNER-USER ]: ${JSON.stringify({
|
||||||
email: email,
|
// email: email,
|
||||||
})}`
|
// })}`
|
||||||
|
// );
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`${uniqueCode} [ REQUEST LOGIN-PARTNER-USER ]: ${JSON.stringify(result)}`
|
||||||
);
|
);
|
||||||
|
|
||||||
// validate
|
// validate
|
||||||
@@ -101,9 +105,9 @@ const loginPartnerUser = async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOGIN-PARTNER-USER ]: checking data login...`
|
// `${uniqueCode} [ PROCESSING LOGIN-PARTNER-USER ]: checking data login...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// check status data partner user apakah masih aktif atau tidak
|
// check status data partner user apakah masih aktif atau tidak
|
||||||
let checkDataLoginPartnerUser = await model.checkDataLoginPartnerUser(
|
let checkDataLoginPartnerUser = await model.checkDataLoginPartnerUser(
|
||||||
@@ -129,9 +133,9 @@ const loginPartnerUser = async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOGIN-PARTNER-USER ]: checking password...`
|
// `${uniqueCode} [ PROCESSING LOGIN-PARTNER-USER ]: checking password...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// check password
|
// check password
|
||||||
let checkPassword = await bcrypt.compare(
|
let checkPassword = await bcrypt.compare(
|
||||||
@@ -158,9 +162,9 @@ const loginPartnerUser = async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOGIN-PARTNER-USER ]: generating access token...`
|
// `${uniqueCode} [ PROCESSING LOGIN-PARTNER-USER ]: generating access token...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// generate access token, yaitu token transaksi yang digunakan untuk setiap request ke setiap end point api
|
// generate access token, yaitu token transaksi yang digunakan untuk setiap request ke setiap end point api
|
||||||
let accessToken = await jwt.generateAccessToken({
|
let accessToken = await jwt.generateAccessToken({
|
||||||
@@ -171,9 +175,9 @@ const loginPartnerUser = async (req, res, next) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOGIN-PARTNER-USER ]: generating refresh token...`
|
// `${uniqueCode} [ PROCESSING LOGIN-PARTNER-USER ]: generating refresh token...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// generate refresh token, yaitu token yang digunakan untuk mendapatkan token transaksi baru jika token sebelumnya sudah expired
|
// generate refresh token, yaitu token yang digunakan untuk mendapatkan token transaksi baru jika token sebelumnya sudah expired
|
||||||
let refreshToken = await jwt.generateRefreshToken({
|
let refreshToken = await jwt.generateRefreshToken({
|
||||||
@@ -184,9 +188,9 @@ const loginPartnerUser = async (req, res, next) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOGIN-PARTNER-USER ]: inserting refresh token...`
|
// `${uniqueCode} [ PROCESSING LOGIN-PARTNER-USER ]: inserting refresh token...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// insert refresh token
|
// insert refresh token
|
||||||
await model.insertRefreshTokenPartner(email, refreshToken);
|
await model.insertRefreshTokenPartner(email, refreshToken);
|
||||||
@@ -201,9 +205,9 @@ const loginPartnerUser = async (req, res, next) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// log info
|
// log info
|
||||||
winston.logger.info(
|
// winston.logger.info(
|
||||||
`${uniqueCode} [ RESPONSE LOGIN-PARTNER-USER ]: ${JSON.stringify(result)}`
|
// `${uniqueCode} [ RESPONSE LOGIN-PARTNER-USER ]: ${JSON.stringify(result)}`
|
||||||
);
|
// );
|
||||||
|
|
||||||
return res.status(200).json(result);
|
return res.status(200).json(result);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -263,9 +267,9 @@ const loginTerminal = async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOGIN-TERMINAL ]: checking MID and TID...`
|
// `${uniqueCode} [ PROCESSING LOGIN-TERMINAL ]: checking MID and TID...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// check mid dan tid, apakah mid dan tid yang di request terdaftar dan status nya aktif di sistem CMS
|
// check mid dan tid, apakah mid dan tid yang di request terdaftar dan status nya aktif di sistem CMS
|
||||||
let checkMidTid = await model.checkMidTid(mid, tid);
|
let checkMidTid = await model.checkMidTid(mid, tid);
|
||||||
@@ -285,9 +289,9 @@ const loginTerminal = async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOGIN-TERMINAL ]: checking data login...`
|
// `${uniqueCode} [ PROCESSING LOGIN-TERMINAL ]: checking data login...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// check data mid dan tid yang di request sudah di daftarkan di terminal login dan statusnya aktif atau tidak
|
// check data mid dan tid yang di request sudah di daftarkan di terminal login dan statusnya aktif atau tidak
|
||||||
let checkDataLogin = await model.checkDataLogin(mid, tid);
|
let checkDataLogin = await model.checkDataLogin(mid, tid);
|
||||||
@@ -309,9 +313,9 @@ const loginTerminal = async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOGIN-TERMINAL ]: checking password...`
|
// `${uniqueCode} [ PROCESSING LOGIN-TERMINAL ]: checking password...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// check password
|
// check password
|
||||||
let checkPassword = await bcrypt.compare(
|
let checkPassword = await bcrypt.compare(
|
||||||
@@ -336,9 +340,9 @@ const loginTerminal = async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOGIN-TERMINAL ]: generating access token...`
|
// `${uniqueCode} [ PROCESSING LOGIN-TERMINAL ]: generating access token...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// generate access token, yaitu token transaksi yang digunakan untuk request ke setiap end point api
|
// generate access token, yaitu token transaksi yang digunakan untuk request ke setiap end point api
|
||||||
let accessToken = await jwt.generateAccessToken({
|
let accessToken = await jwt.generateAccessToken({
|
||||||
@@ -347,9 +351,9 @@ const loginTerminal = async (req, res, next) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOGIN-TERMINAL ]: generating refresh token...`
|
// `${uniqueCode} [ PROCESSING LOGIN-TERMINAL ]: generating refresh token...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// generate refresh token, yaitu token yang digunakan untuk mengenerate token transaksi baru jika token sebelumnya sudah expired
|
// generate refresh token, yaitu token yang digunakan untuk mengenerate token transaksi baru jika token sebelumnya sudah expired
|
||||||
let refreshToken = await jwt.generateRefreshToken({
|
let refreshToken = await jwt.generateRefreshToken({
|
||||||
@@ -358,9 +362,9 @@ const loginTerminal = async (req, res, next) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOGIN-TERMINAL ]: inserting refresh token...`
|
// `${uniqueCode} [ PROCESSING LOGIN-TERMINAL ]: inserting refresh token...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// insert refresh token
|
// insert refresh token
|
||||||
await model.insertRefreshToken(mid, tid, refreshToken);
|
await model.insertRefreshToken(mid, tid, refreshToken);
|
||||||
@@ -437,9 +441,9 @@ const register = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING REGISTER ]: checking MID and TID...`
|
// `${uniqueCode} [ PROCESSING REGISTER ]: checking MID and TID...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// check mid dan tid yang di request sudah terdaftar di master terminal sistem CMS atau belum dan status nya aktif
|
// check mid dan tid yang di request sudah terdaftar di master terminal sistem CMS atau belum dan status nya aktif
|
||||||
let checkMidTid = await model.checkMidTid(mid, tid);
|
let checkMidTid = await model.checkMidTid(mid, tid);
|
||||||
@@ -459,9 +463,9 @@ const register = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING REGISTER ]: checking data login...`
|
// `${uniqueCode} [ PROCESSING REGISTER ]: checking data login...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// check data login, apaka mid dan tid yang di request sudah terdaftar di terminal login atau belum
|
// check data login, apaka mid dan tid yang di request sudah terdaftar di terminal login atau belum
|
||||||
let checkDataLogin = await model.checkDataLogin(mid, tid);
|
let checkDataLogin = await model.checkDataLogin(mid, tid);
|
||||||
@@ -483,9 +487,9 @@ const register = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING REGISTER ]: encrypting password...`
|
// `${uniqueCode} [ PROCESSING REGISTER ]: encrypting password...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// encrypt password
|
// encrypt password
|
||||||
let saltRounds = 10;
|
let saltRounds = 10;
|
||||||
@@ -507,9 +511,9 @@ const register = async (req, res) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING REGISTER ]: inserting data login...`
|
// `${uniqueCode} [ PROCESSING REGISTER ]: inserting data login...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// insert data login
|
// insert data login
|
||||||
result = await model.insertDataLogin(data);
|
result = await model.insertDataLogin(data);
|
||||||
@@ -556,7 +560,7 @@ const refreshTokenTerminal = async (req, res) => {
|
|||||||
let result = {};
|
let result = {};
|
||||||
|
|
||||||
let { mid, tid } = req.body;
|
let { mid, tid } = req.body;
|
||||||
let refresh_token = req.header('refresh_token');
|
let refresh_token = req.headers['refresh-token'];
|
||||||
|
|
||||||
// log info
|
// log info
|
||||||
winston.logger.info(
|
winston.logger.info(
|
||||||
@@ -585,17 +589,17 @@ const refreshTokenTerminal = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING REFRESH-TOKEN-TERMINAL ]: authenticating refresh token...`
|
// `${uniqueCode} [ PROCESSING REFRESH-TOKEN-TERMINAL ]: authenticating refresh token...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// verify, apaka refresh token yang di request valid atau tidak
|
// verify, apaka refresh token yang di request valid atau tidak
|
||||||
await jwt.authenticateRefreshToken;
|
await jwt.authenticateRefreshToken;
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING REFRESH-TOKEN-TERMINAL ]: checking refresh token...`
|
// `${uniqueCode} [ PROCESSING REFRESH-TOKEN-TERMINAL ]: checking refresh token...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// cek apakah refresh token yang di request terdaftar di sistem CMS
|
// cek apakah refresh token yang di request terdaftar di sistem CMS
|
||||||
let checkRefreshToken = await model.checkRefreshToken(
|
let checkRefreshToken = await model.checkRefreshToken(
|
||||||
@@ -623,9 +627,9 @@ const refreshTokenTerminal = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING REFRESH-TOKEN-TERMINAL ]: generating access token...`
|
// `${uniqueCode} [ PROCESSING REFRESH-TOKEN-TERMINAL ]: generating access token...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
let accessToken;
|
let accessToken;
|
||||||
let refreshToken;
|
let refreshToken;
|
||||||
@@ -637,9 +641,9 @@ const refreshTokenTerminal = async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING REFRESH-TOKEN-TERMINAL ]: generating refresh token...`
|
// `${uniqueCode} [ PROCESSING REFRESH-TOKEN-TERMINAL ]: generating refresh token...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// generate new refresh token
|
// generate new refresh token
|
||||||
refreshToken = await jwt.generateRefreshToken({
|
refreshToken = await jwt.generateRefreshToken({
|
||||||
@@ -648,9 +652,9 @@ const refreshTokenTerminal = async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING REFRESH-TOKEN-TERMINAL ]: updating refresh token...`
|
// `${uniqueCode} [ PROCESSING REFRESH-TOKEN-TERMINAL ]: updating refresh token...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// update insert refresh token
|
// update insert refresh token
|
||||||
await model.updateRefreshToken(mid, tid, refresh_token, refreshToken);
|
await model.updateRefreshToken(mid, tid, refresh_token, refreshToken);
|
||||||
@@ -702,14 +706,14 @@ const refreshTokenPartnerUser = async (req, res) => {
|
|||||||
let result = {};
|
let result = {};
|
||||||
|
|
||||||
let { email } = req.body;
|
let { email } = req.body;
|
||||||
let refresh_token = req.header('refresh_token');
|
let refresh_token = req.headers['refresh-token'];
|
||||||
|
|
||||||
// log info
|
// log info
|
||||||
winston.logger.info(
|
// winston.logger.info(
|
||||||
`${uniqueCode} [ REQUEST REFRESH-TOKEN-PARTNER-USER ]: ${JSON.stringify(
|
// `${uniqueCode} [ REQUEST REFRESH-TOKEN-PARTNER-USER ]: ${JSON.stringify(
|
||||||
req.body
|
// req.body
|
||||||
)}`
|
// )}`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// validate
|
// validate
|
||||||
let err = validationResult(req);
|
let err = validationResult(req);
|
||||||
@@ -731,17 +735,17 @@ const refreshTokenPartnerUser = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING REFRESH-TOKEN-PARTNER-USER ]: authenticating refresh token...`
|
// `${uniqueCode} [ PROCESSING REFRESH-TOKEN-PARTNER-USER ]: authenticating refresh token...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// verify apaka refresh token yang di request valid atau tidak
|
// verify apaka refresh token yang di request valid atau tidak
|
||||||
await jwt.authenticateRefreshToken;
|
await jwt.authenticateRefreshToken;
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING REFRESH-TOKEN-PARTNER-USER ]: checking refresh token...`
|
// `${uniqueCode} [ PROCESSING REFRESH-TOKEN-PARTNER-USER ]: checking refresh token...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// cek apaka refresh token yang di request terdaftar di sistem CMS atau tidak
|
// cek apaka refresh token yang di request terdaftar di sistem CMS atau tidak
|
||||||
let checkRefreshToken = await model.checkRefreshTokenPartner(
|
let checkRefreshToken = await model.checkRefreshTokenPartner(
|
||||||
@@ -768,9 +772,9 @@ const refreshTokenPartnerUser = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING REFRESH-TOKEN-PARTNER-USER ]: generating access token...`
|
// `${uniqueCode} [ PROCESSING REFRESH-TOKEN-PARTNER-USER ]: generating access token...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
let accessToken;
|
let accessToken;
|
||||||
let refreshToken;
|
let refreshToken;
|
||||||
@@ -807,9 +811,9 @@ const refreshTokenPartnerUser = async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING REFRESH-TOKEN-PARTNER-USER ]: generating refresh token...`
|
// `${uniqueCode} [ PROCESSING REFRESH-TOKEN-PARTNER-USER ]: generating refresh token...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// generate new refresh token
|
// generate new refresh token
|
||||||
refreshToken = await jwt.generateRefreshToken({
|
refreshToken = await jwt.generateRefreshToken({
|
||||||
@@ -820,9 +824,9 @@ const refreshTokenPartnerUser = async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING REFRESH-TOKEN-PARTNER-USER ]: updating refresh token...`
|
// `${uniqueCode} [ PROCESSING REFRESH-TOKEN-PARTNER-USER ]: updating refresh token...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// update insert refresh token
|
// update insert refresh token
|
||||||
await model.updateRefreshTokenPartner(email, refresh_token, refreshToken);
|
await model.updateRefreshTokenPartner(email, refresh_token, refreshToken);
|
||||||
@@ -837,11 +841,11 @@ const refreshTokenPartnerUser = async (req, res) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// log info
|
// log info
|
||||||
winston.logger.info(
|
// winston.logger.info(
|
||||||
`${uniqueCode} [ RESPONSE REFRESH-TOKEN-PARTNER-USER ]: ${JSON.stringify(
|
// `${uniqueCode} [ RESPONSE REFRESH-TOKEN-PARTNER-USER ]: ${JSON.stringify(
|
||||||
result
|
// result
|
||||||
)}`
|
// )}`
|
||||||
);
|
// );
|
||||||
|
|
||||||
return res.status(200).json(result);
|
return res.status(200).json(result);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
const { param, body, validationResult } = require("express-validator");
|
const { param, body, validationResult } = require('express-validator');
|
||||||
const helper = require("../../helpers/helper");
|
const helper = require('../../helpers/helper');
|
||||||
const winston = require("../../helpers/winston.logger");
|
const winston = require('../../helpers/winston.logger');
|
||||||
const model = require("./cahsin.model");
|
const model = require('./cahsin.model');
|
||||||
const moment = require("moment");
|
const moment = require('moment');
|
||||||
const knex = require("../../../infrastructure/database/knex");
|
const knex = require('../../../infrastructure/database/knex');
|
||||||
|
|
||||||
moment.locale("id");
|
moment.locale('id');
|
||||||
|
|
||||||
var result = {};
|
var result = {};
|
||||||
var uniqueCode;
|
var uniqueCode;
|
||||||
@@ -13,14 +13,32 @@ var uniqueCode;
|
|||||||
// VALIDATION
|
// VALIDATION
|
||||||
const validate = (method) => {
|
const validate = (method) => {
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case "generateInvoice":
|
case 'generateInvoice':
|
||||||
return [
|
return [
|
||||||
body('trx_date').notEmpty().withMessage('trx_date is required!').isISO8601().withMessage('invalid trx_date format YYYY-MM-DD !').escape().trim(),
|
body('trx_date')
|
||||||
body('repost').notEmpty().withMessage('repost is required!').isBoolean().withMessage('repost must boolean!').escape().trim(),
|
.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 [
|
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:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -29,7 +47,6 @@ const validate = (method) => {
|
|||||||
|
|
||||||
// POSTING INVOICE
|
// POSTING INVOICE
|
||||||
const apiGenerateCahsIn = async (req, res) => {
|
const apiGenerateCahsIn = async (req, res) => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// generate unique code
|
// generate unique code
|
||||||
uniqueCode = helper.getUniqueCode();
|
uniqueCode = helper.getUniqueCode();
|
||||||
@@ -44,7 +61,7 @@ const apiGenerateCahsIn = async (req, res) => {
|
|||||||
const err = validationResult(req, res);
|
const err = validationResult(req, res);
|
||||||
if (!err.isEmpty()) {
|
if (!err.isEmpty()) {
|
||||||
result = {
|
result = {
|
||||||
code: "400",
|
code: '400',
|
||||||
message: err.errors[0].msg,
|
message: err.errors[0].msg,
|
||||||
data: {},
|
data: {},
|
||||||
};
|
};
|
||||||
@@ -57,40 +74,92 @@ const apiGenerateCahsIn = async (req, res) => {
|
|||||||
return res.status(200).json(result);
|
return res.status(200).json(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
const cashIn = await _generateCashIn(uniqueCode)
|
const cashIn = await _generateCashIn(uniqueCode);
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
code: "200",
|
code: '200',
|
||||||
message: "Succes posting",
|
message: 'Succes posting',
|
||||||
data: cashIn
|
data: cashIn,
|
||||||
};
|
};
|
||||||
|
|
||||||
return res.status(200).json(result);
|
return res.status(200).json(result);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// create log
|
// create log
|
||||||
winston.logger.error(
|
winston.logger.error(
|
||||||
`500 internal server error - backend server | ${error.message}`
|
`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({
|
return res.status(200).json(result);
|
||||||
code: "500",
|
}
|
||||||
message:
|
|
||||||
process.env.NODE_ENV != "production"
|
|
||||||
? error.message
|
|
||||||
: "500 internal server error - backend server.",
|
|
||||||
data: {},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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
|
// RETRY POSTING INVOICE
|
||||||
const apiPostingCahsIn = async (req, res) => {
|
const apiPostingCahsIn = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
// generate unique code
|
// generate unique code
|
||||||
uniqueCode = helper.getUniqueCode()
|
uniqueCode = helper.getUniqueCode();
|
||||||
let { body } = req
|
let { body } = req;
|
||||||
// log info
|
// log info
|
||||||
winston.logger.info(
|
winston.logger.info(
|
||||||
`${uniqueCode} REQUEST posting cash in : ${JSON.stringify(req.body)}`
|
`${uniqueCode} REQUEST posting cash in : ${JSON.stringify(req.body)}`
|
||||||
@@ -100,184 +169,406 @@ const apiPostingCahsIn = async (req, res) => {
|
|||||||
const err = validationResult(req, res);
|
const err = validationResult(req, res);
|
||||||
if (!err.isEmpty()) {
|
if (!err.isEmpty()) {
|
||||||
result = {
|
result = {
|
||||||
code: "400",
|
code: '400',
|
||||||
message: err.errors[0].msg,
|
message: err.errors[0].msg,
|
||||||
data: {},
|
data: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
// log warn
|
// log warn
|
||||||
winston.logger.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 res.status(200).json(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// return uniqueCode
|
// 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 = {
|
result = {
|
||||||
code: "200",
|
code: '200',
|
||||||
message: "Succes",
|
message: 'Succes',
|
||||||
data: invoice,
|
data: invoice,
|
||||||
}
|
};
|
||||||
|
|
||||||
return res.status(200).json(result);
|
return res.status(200).json(result);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// create log
|
// create log
|
||||||
winston.logger.error(
|
winston.logger.error(
|
||||||
`500 internal server error - backend server | ${error.message}`
|
`500 internal server error - backend server | ${error.message}`
|
||||||
);
|
);
|
||||||
|
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
code: "500",
|
code: '500',
|
||||||
message:
|
message:
|
||||||
process.env.NODE_ENV != "production"
|
process.env.NODE_ENV != 'production'
|
||||||
? error.message
|
? error.message
|
||||||
: "500 internal server error - backend server.",
|
: '500 internal server error - backend server.',
|
||||||
data: {},
|
data: {},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
const _generateCashIn = async (uniqueCode) => {
|
const _generateCashIn = async (uniqueCode) => {
|
||||||
|
let partnerRecon = await model.getPartnerRecon(knex);
|
||||||
let partnerRecon = await model.getPartnerRecon(knex)
|
|
||||||
// return partnerRecon
|
// 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) {
|
for (const item of partnerRecon) {
|
||||||
let reserve = []
|
let reserve = [];
|
||||||
let code = ""
|
let code = '';
|
||||||
await knex.transaction(async trx => {
|
await knex.transaction(async (trx) => {
|
||||||
code = await model.generateCode(trx, item.c_partner_code, moment().format("YYMMDD"))
|
try {
|
||||||
winston.logger.info(`SCHEDULER-FB70-${uniqueCode} generate cash in : ${code}`)
|
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
|
// Cash-in
|
||||||
const dataCahsIn = {
|
let dataCahsIn = {
|
||||||
c_partner_code : item.c_partner_code,
|
c_partner_code: item.c_partner_code,
|
||||||
c_partner_name : item.c_partner_name,
|
c_partner_name: item.c_partner_name,
|
||||||
c_cash_in_no : code,
|
c_cash_in_no: code,
|
||||||
c_in_period : item.c_in_period,
|
c_in_period: item.c_in_period,
|
||||||
d_credit : item.d_payment,
|
d_credit: item.d_payment,
|
||||||
c_invoice_no : item.c_invoice_no,
|
c_invoice_no: item.c_invoice_no,
|
||||||
i_amount : item.amount
|
i_amount: item.amount,
|
||||||
}
|
};
|
||||||
|
|
||||||
winston.logger.info(`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN ${code} DATA : ${JSON.stringify(dataCahsIn)}`)
|
winston.logger.info(
|
||||||
const cashIn = await model.insertCashIn(trx, dataCahsIn)
|
`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN ${code} DATA : ${JSON.stringify(
|
||||||
|
dataCahsIn
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
|
||||||
winston.logger.info(`SCHEDULER-FB70-${uniqueCode} INSERT CASH-IN HISTORY ${code} DATA : ${JSON.stringify(dataCahsIn)}`)
|
// CASH-IN DETAIL
|
||||||
const paymentyHistory = await model.writePaynentHistory(dataCahsIn, "SUCCESSFULLY", 0, trx)
|
let data = [];
|
||||||
|
const reserv = await model.getReserve(
|
||||||
|
trx,
|
||||||
|
item.c_partner_code,
|
||||||
|
item.d_payment,
|
||||||
|
item.c_invoice_no
|
||||||
|
);
|
||||||
|
|
||||||
// Insert cahs in detail
|
//TOTAL AMOUNT CASH-IN
|
||||||
let data = []
|
let cashInAmount = 0;
|
||||||
const reserv = await model.getReserve(trx, item.c_partner_code, item.d_payment, item.c_invoice_no)
|
for (const itemCI of reserv) {
|
||||||
for (const detail of reserv) {
|
cashInAmount += parseInt(itemCI.i_reservation_amount);
|
||||||
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 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,
|
|
||||||
}
|
}
|
||||||
|
dataCahsIn.i_amount = cashInAmount;
|
||||||
|
|
||||||
await model.updateIntoReserve(trx, dataReserve, reserveNo)
|
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) => {
|
const _postingCashIn = async (uniqueCode) => {
|
||||||
let data = []
|
let data = [];
|
||||||
let postingEt = await model.getPostingEt(knex)
|
let postingEt = await model.getPostingEt(knex);
|
||||||
|
|
||||||
for (const item of postingEt) {
|
for (const item of postingEt) {
|
||||||
await knex.transaction(async trx => {
|
await knex.transaction(async (trx) => {
|
||||||
|
winston.logger.info(
|
||||||
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} GET POSTING ET : ${JSON.stringify(item)}`)
|
`SCHEDULER-RETRY-${uniqueCode} GET POSTING ET : ${JSON.stringify(item)}`
|
||||||
|
);
|
||||||
|
|
||||||
let xmlHeader = {
|
let xmlHeader = {
|
||||||
doc_header_text : item.doc_header_text ? item.doc_header_text : "",
|
doc_header_text: item.doc_header_text ? item.doc_header_text : '',
|
||||||
ba: item.ba ? item.ba : "",
|
ba: item.ba ? item.ba : '',
|
||||||
doc_date : item.doc_date ? item.doc_date : "",
|
doc_date: item.doc_date ? item.doc_date : '',
|
||||||
posting_date : item.posting_date ? item.posting_date : "",
|
posting_date: item.posting_date ? item.posting_date : '',
|
||||||
fisc_year : item.fiscal_year ? item.fiscal_year : "",
|
fisc_year: item.fiscal_year ? item.fiscal_year : '',
|
||||||
fisc_period : item.fis_period ? item.fis_period: "",
|
fisc_period: item.fis_period ? item.fis_period : '',
|
||||||
doc_type: item.doc_type ? item.doc_type : "",
|
doc_type: item.doc_type ? item.doc_type : '',
|
||||||
c_invoice_no : item.reference ? item.reference : ""
|
c_invoice_no: item.reference ? item.reference : '',
|
||||||
}
|
};
|
||||||
|
|
||||||
let xmlItem = ['S', 'H'].map(key => {
|
let xmlItem = ['S', 'H'].map((key) => {
|
||||||
return {
|
return {
|
||||||
c_account_code_topup : key == 'S' ? item.customer : "",
|
c_account_code_topup: key == 'S' ? item.customer : '',
|
||||||
c_account_topup : key == 'H' ? item.account : "",
|
c_account_topup: key == 'H' ? item.account : '',
|
||||||
ba : item.ba,
|
ba: item.ba,
|
||||||
amount : item.amount,
|
amount: item.amount,
|
||||||
posting_date : item.posting_date,
|
posting_date: item.posting_date,
|
||||||
c_invoice_no : item.reference,
|
c_invoice_no: item.reference,
|
||||||
item_text :key == 'S' ? item.text1 : item.text2,
|
item_text: key == 'S' ? item.text1 : item.text2,
|
||||||
de_cre : key
|
de_cre: key,
|
||||||
}
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
let xmlRequest = helper.generateXMLRequest('ZFMCMS_FI_001', xmlHeader, xmlItem)
|
let xmlRequest = helper.generateXMLRequest(
|
||||||
console.log(xmlRequest)
|
'ZFMCMS_FI_001',
|
||||||
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} REQUEST posting ${item.reference} to SAP : ${xmlRequest}`);
|
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'
|
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';
|
||||||
|
|
||||||
const response = await helper.postingSAP(url, xmlRequest)
|
const response = await helper.postingSAP(url, xmlRequest);
|
||||||
|
|
||||||
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} RESPONSE posting ${item.reference} to SAP : ${JSON.stringify(response)}`);
|
winston.logger.info(
|
||||||
|
`SCHEDULER-RETRY-${uniqueCode} RESPONSE posting ${
|
||||||
|
item.reference
|
||||||
|
} to SAP : ${JSON.stringify(response)}`
|
||||||
|
);
|
||||||
|
|
||||||
const resSAP = helper.getXMLData(response)
|
const resSAP = helper.getXMLData(response);
|
||||||
|
|
||||||
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} TRANSACTION 2`);
|
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} TRANSACTION 2`);
|
||||||
// UPDATE CMS
|
// 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)
|
const cms = await model.setReturnSAP(item.no_dok, resSAP, trx);
|
||||||
|
|
||||||
winston.logger.info(`SCHEDULER-RETRY-${uniqueCode} RESULT CMS : ${JSON.stringify(cms)}`)
|
winston.logger.info(
|
||||||
|
`SCHEDULER-RETRY-${uniqueCode} RESULT CMS : ${JSON.stringify(cms)}`
|
||||||
})
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return postingEt
|
return postingEt;
|
||||||
|
};
|
||||||
}
|
|
||||||
|
|
||||||
function wait(milliseconds) {
|
function wait(milliseconds) {
|
||||||
return new Promise(resolve => setTimeout(resolve, milliseconds));
|
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
validate,
|
validate,
|
||||||
apiGenerateCahsIn,
|
apiGenerateCahsIn,
|
||||||
|
apiGenerateCashInSales,
|
||||||
apiPostingCahsIn,
|
apiPostingCahsIn,
|
||||||
_postingCashIn,
|
_postingCashIn,
|
||||||
_generateCashIn
|
_generateCashIn,
|
||||||
|
_generateCashInSales
|
||||||
};
|
};
|
||||||
@@ -1,17 +1,18 @@
|
|||||||
|
|
||||||
// GET PARTNER, MERCHANT, TERMINAL FROM TID
|
// GET PARTNER, MERCHANT, TERMINAL FROM TID
|
||||||
const generateInvoice = async (invoiceDate, repost, trx) => {
|
const generateInvoice = async (invoiceDate, repost, trx) => {
|
||||||
|
let result = await trx.select(
|
||||||
let result = await trx.select(trx.raw(`* FROM payment.sp_payment_req_topup_online('${invoiceDate}', ${repost})`))
|
trx.raw(
|
||||||
|
`* FROM payment.sp_payment_req_topup_online('${invoiceDate}', ${repost})`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
};
|
||||||
}
|
|
||||||
|
|
||||||
const insertPostingEt = async (code, dataCashIn, trx) => {
|
const insertPostingEt = async (code, dataCashIn, trx) => {
|
||||||
let type = ['S', 'H']
|
let type = ['S', 'H'];
|
||||||
let et = []
|
let et = [];
|
||||||
let posting_et = []
|
let posting_et = [];
|
||||||
type.forEach((item, index) => {
|
type.forEach((item, index) => {
|
||||||
let data = {
|
let data = {
|
||||||
file_name: code,
|
file_name: code,
|
||||||
@@ -25,137 +26,193 @@ const insertPostingEt = async (code, dataCashIn, trx) => {
|
|||||||
reference: code,
|
reference: code,
|
||||||
amount: dataCashIn.amount,
|
amount: dataCashIn.amount,
|
||||||
ba: dataCashIn.ba,
|
ba: dataCashIn.ba,
|
||||||
indeks: (index+1),
|
indeks: index + 1,
|
||||||
totalidx: type.length,
|
totalidx: type.length,
|
||||||
doc_header_text: code,
|
doc_header_text: code,
|
||||||
pos_status : 4
|
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,
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if(item == 'H'){
|
et.push(data);
|
||||||
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)
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
posting_et = await trx('public.posting_et').insert(et, ['indeks', 'customer', 'account', 'ba', 'fiscal_year', 'amount', 'no_dok', 'text', 'debit_kredit'])
|
posting_et = await trx('public.posting_et').insert(et, [
|
||||||
|
'indeks',
|
||||||
return posting_et[0]
|
'customer',
|
||||||
|
'account',
|
||||||
}
|
|
||||||
|
|
||||||
const getPostingEt = async(trx) => {
|
|
||||||
|
|
||||||
const result = await trx('public.posting_et AS pe').select([
|
|
||||||
'doc_header_text',
|
|
||||||
'ba',
|
'ba',
|
||||||
'doc_date',
|
|
||||||
'posting_date',
|
|
||||||
'fiscal_year',
|
'fiscal_year',
|
||||||
trx.raw(`TO_CHAR(doc_date::DATE, 'MM') AS fis_period`),
|
|
||||||
'doc_type',
|
|
||||||
'reference',
|
|
||||||
'no_dok',
|
|
||||||
'tcode',
|
|
||||||
'amount',
|
'amount',
|
||||||
trx.raw(`'IDR' AS currency`),
|
'no_dok',
|
||||||
trx.raw(`(SELECT customer FROM public.posting_et where reference = pe.reference and debit_kredit = 'S') as customer`),
|
'text',
|
||||||
trx.raw(`(SELECT account FROM public.posting_et where reference = pe.reference and debit_kredit = 'H') as account `),
|
'debit_kredit',
|
||||||
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"])
|
|
||||||
|
|
||||||
.groupBy(['doc_header_text', 'ba', 'doc_header_text', 'tcode', 'ba', 'amount', 'posting_date', 'doc_date', 'doc_type', 'fiscal_year', 'reference', 'no_dok'])
|
return posting_et[0];
|
||||||
|
};
|
||||||
|
|
||||||
return result
|
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'])
|
||||||
|
|
||||||
}
|
.groupBy([
|
||||||
|
'doc_header_text',
|
||||||
|
'ba',
|
||||||
|
'doc_header_text',
|
||||||
|
'tcode',
|
||||||
|
'ba',
|
||||||
|
'amount',
|
||||||
|
'posting_date',
|
||||||
|
'doc_date',
|
||||||
|
'doc_type',
|
||||||
|
'fiscal_year',
|
||||||
|
'reference',
|
||||||
|
'no_dok',
|
||||||
|
]);
|
||||||
|
|
||||||
const setReturnSAP = async (code, resSAP, trx) => {
|
return result;
|
||||||
let t_cash_in = []
|
};
|
||||||
let reserveBalance = []
|
|
||||||
|
|
||||||
if(resSAP.type == 'S'){
|
const setReturnSAP = async (code, resSAP, trx) => {
|
||||||
|
let t_cash_in = [];
|
||||||
|
let reserveBalance = [];
|
||||||
|
|
||||||
|
if (resSAP.type == 'S') {
|
||||||
// update invoice
|
// update invoice
|
||||||
t_cash_in = await trx('payment.t_d_cash_in').update({
|
t_cash_in = await trx('payment.t_d_cash_in')
|
||||||
c_return_sap: resSAP.data.E_DOCUMENTNUMBER,
|
.update(
|
||||||
c_return_year_sap: resSAP.data.E_DOCUMENTYEAR
|
{
|
||||||
}, ['c_cash_in_no','c_return_sap'])
|
c_return_sap: resSAP.data.E_DOCUMENTNUMBER,
|
||||||
.where({
|
c_return_year_sap: resSAP.data.E_DOCUMENTYEAR,
|
||||||
c_cash_in_no: code
|
},
|
||||||
});
|
['c_cash_in_no', 'c_return_sap']
|
||||||
|
)
|
||||||
|
.where({
|
||||||
|
c_cash_in_no: code,
|
||||||
|
});
|
||||||
|
|
||||||
// update load balance
|
// update load balance
|
||||||
reserveBalance = await trx('trx.t_d_reservation_balance').update({
|
reserveBalance = await trx('trx.t_d_reservation_balance')
|
||||||
c_return_cash_in_sap: resSAP.data.E_DOCUMENTNUMBER,
|
.update(
|
||||||
c_cash_in_no: code
|
{
|
||||||
}, ['c_cash_in_no', 'c_return_sap'])
|
c_return_cash_in_sap: resSAP.data.E_DOCUMENTNUMBER,
|
||||||
.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}')`)
|
c_cash_in_no: code,
|
||||||
|
},
|
||||||
}else {
|
['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 text = resSAP.message;
|
||||||
let result = text.toUpperCase();
|
let result = text.toUpperCase();
|
||||||
if(result.includes("ALREADY")){
|
if (result.includes('ALREADY')) {
|
||||||
let result = text.toUpperCase().split('-');
|
let result = text.toUpperCase().split('-');
|
||||||
let doc_number = result[1].trim().split(" ")[0]
|
let doc_number = result[1].trim().split(' ')[0];
|
||||||
// update invoice
|
// update invoice
|
||||||
const d = new Date();
|
const d = new Date();
|
||||||
let year = d.getFullYear();
|
let year = d.getFullYear();
|
||||||
t_cash_in = await trx('payment.t_d_cash_in').update({
|
t_cash_in = await trx('payment.t_d_cash_in')
|
||||||
c_return_sap: doc_number,
|
.update(
|
||||||
c_return_year_sap: year
|
{
|
||||||
}, ['c_cash_in_no','c_return_sap'])
|
c_return_sap: doc_number,
|
||||||
.where({
|
c_return_year_sap: year,
|
||||||
c_cash_in_no: code
|
},
|
||||||
});
|
['c_cash_in_no', 'c_return_sap']
|
||||||
|
)
|
||||||
|
.where({
|
||||||
|
c_cash_in_no: code,
|
||||||
|
});
|
||||||
|
|
||||||
// update load balance
|
// update load balance
|
||||||
reserveBalance = await trx('trx.t_d_reservation_balance').update({
|
reserveBalance = await trx('trx.t_d_reservation_balance')
|
||||||
c_return_cash_in_sap: resSAP.data.E_DOCUMENTNUMBER,
|
.update(
|
||||||
c_cash_in_no: code
|
{
|
||||||
}, ['c_cash_in_no', 'c_return_sap'])
|
c_return_cash_in_sap: resSAP.data.E_DOCUMENTNUMBER,
|
||||||
.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}')`)
|
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
|
// update posting et
|
||||||
const posting_et = await trx('public.posting_et').update({
|
const posting_et = await trx('public.posting_et')
|
||||||
pos_status : resSAP.type == 'S' ? 0 : 4,
|
.update(
|
||||||
status0 : resSAP.type,
|
{
|
||||||
no_doksap : resSAP.data.E_DOCUMENTNUMBER ? resSAP.data.E_DOCUMENTNUMBER : null,
|
pos_status: resSAP.type == 'S' ? 0 : 4,
|
||||||
status1 : resSAP.message ? resSAP.message : null
|
status0: resSAP.type,
|
||||||
}, ['file_name','status0']).where({
|
no_doksap: resSAP.data.E_DOCUMENTNUMBER
|
||||||
no_dok: code
|
? resSAP.data.E_DOCUMENTNUMBER
|
||||||
})
|
: null,
|
||||||
|
status1: resSAP.message ? resSAP.message : null,
|
||||||
|
},
|
||||||
|
['file_name', 'status0']
|
||||||
|
)
|
||||||
|
.where({
|
||||||
|
no_dok: code,
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
cash_in : t_cash_in[0],
|
cash_in: t_cash_in[0],
|
||||||
reserveBalance : reserveBalance[0],
|
reserveBalance: reserveBalance[0],
|
||||||
posting_et : posting_et[0]
|
posting_et: posting_et[0],
|
||||||
}
|
};
|
||||||
|
};
|
||||||
}
|
|
||||||
|
|
||||||
const getRecon = async (trx) => {
|
const getRecon = async (trx) => {
|
||||||
|
|
||||||
let sql = `SELECT
|
let sql = `SELECT
|
||||||
tdi.c_invoice_no,
|
tdi.c_invoice_no,
|
||||||
'FB70' AS tcode,
|
'FB70' AS tcode,
|
||||||
@@ -200,157 +257,335 @@ const getRecon = async (trx) => {
|
|||||||
SELECT c_reservation_no FROM payment.t_d_payment_recon tdpr WHERE tdpr.c_status = 'S'
|
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
|
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`
|
ORDER BY tdpr.d_payment`;
|
||||||
let result = await trx.raw(sql)
|
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')
|
||||||
|
.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')
|
|
||||||
})
|
|
||||||
.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([
|
const getSalesKMT = async (trx, code, date, invoice) => {
|
||||||
"tdpr.c_partner_code",
|
const res = await trx
|
||||||
"tdrb.c_partner_name",
|
.select([
|
||||||
"tdi.c_invoice_no",
|
'tdskm.c_sales_no',
|
||||||
"tdi.d_invoice_date",
|
'tdskm.i_total_billing',
|
||||||
trx.raw("to_char(tdpr.d_payment, 'YYYY-MM-DD') AS d_payment"),
|
'tdpr.c_payment_recon_no',
|
||||||
trx.raw("SUM(tdrb.i_reservation_amount) AS amount"),
|
'tdpr.d_payment',
|
||||||
"tmp.c_account_topup",
|
'tdpr.d_payment_recon',
|
||||||
"tmp.c_account_code_topup",
|
'tdskm.c_partner_code',
|
||||||
"i_company",
|
'tdskm.c_partner_name',
|
||||||
"i_holding",
|
'tdsi.c_invoice_no',
|
||||||
trx.raw(`CASE
|
'tdsi.m_total_billing as invoice_amount'
|
||||||
WHEN to_char(tdpr.d_payment, 'MM') = to_char(tdi.d_invoice_date, 'MM')
|
])
|
||||||
|
.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'
|
THEN 'IP'
|
||||||
ELSE
|
ELSE
|
||||||
'OP'
|
'OP'
|
||||||
END c_in_period`),
|
END c_in_period`),
|
||||||
])
|
])
|
||||||
.from("trx.t_d_reservation_balance AS tdrb")
|
.from('trx.t_d_reservation_balance AS tdrb')
|
||||||
.leftJoin('trx.t_d_load_balance as tdlb', function () {
|
.leftJoin('trx.t_d_load_balance as tdlb', function () {
|
||||||
this.on('tdrb.c_load_balance_no', '=', 'tdlb.c_load_balance_no')
|
this.on('tdrb.c_load_balance_no', '=', 'tdlb.c_load_balance_no');
|
||||||
})
|
})
|
||||||
.leftJoin('payment.t_d_invoice as tdi', function () {
|
.leftJoin('payment.t_d_invoice as tdi', function () {
|
||||||
this.on('tdi.c_invoice_no', '=', 'tdlb.c_invoice_no')
|
this.on('tdi.c_invoice_no', '=', 'tdlb.c_invoice_no').orOn(
|
||||||
})
|
'tdi.c_invoice_no',
|
||||||
.leftJoin('payment.t_d_payment_recon as tdpr', function () {
|
'=',
|
||||||
this.on('tdpr.c_reservation_no', '=', 'tdrb.c_reservation_no')
|
'tdrb.c_invoice_no'
|
||||||
})
|
);
|
||||||
.leftJoin('public.t_m_partner as tmp', function () {
|
})
|
||||||
this.on('tmp.c_code', '=', 'tdrb.c_partner_code')
|
.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');
|
||||||
|
// })
|
||||||
|
|
||||||
.where("tdrb.c_status", "=", "A")
|
.where('tdrb.c_status', '=', 'A')
|
||||||
.where("tdi.c_status", "!=", "X")
|
.where('tdi.c_status', '!=', 'X')
|
||||||
.where("tdpr.c_status", "=", "S")
|
.where('tdpr.c_status', '=', 'S')
|
||||||
.whereNotNull("tdi.c_return_sap")
|
.whereNotNull('tdi.c_return_sap')
|
||||||
.whereNotNull("tdrb.c_load_balance_no")
|
.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)`)
|
.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"])
|
.groupBy([
|
||||||
// .toSql()
|
'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
|
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) => {
|
const generateCode = async (trx, c_partner_code, d_payment_recon) => {
|
||||||
let code = ""
|
let code = '';
|
||||||
let prefix = `CIN${c_partner_code}${d_payment_recon}`
|
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`)])
|
let result = await trx
|
||||||
.from("payment.t_d_cash_in")
|
.select([trx.raw(`substring(c_cash_in_no, 13, 3) AS code`)])
|
||||||
.whereRaw(`substring(c_cash_in_no, 1, 12) = '${prefix}'`)
|
.from('payment.t_d_cash_in')
|
||||||
// .where("d_project_date", projectDate)
|
.whereRaw(`substring(c_cash_in_no, 1, 12) = '${prefix}'`)
|
||||||
.orderBy('c_cash_in_no', 'DESC')
|
// .where("d_project_date", projectDate)
|
||||||
.first()
|
.orderBy('c_cash_in_no', 'DESC')
|
||||||
|
.first();
|
||||||
|
|
||||||
if(result){
|
if (result) {
|
||||||
let counter = parseInt(result.code)+1
|
let counter = parseInt(result.code) + 1;
|
||||||
counter = String(counter).padStart(3, '0');
|
counter = String(counter).padStart(3, '0');
|
||||||
code = `${prefix}${counter}`
|
code = `${prefix}${counter}`;
|
||||||
|
} else {
|
||||||
}else{
|
code = `${prefix}001`;
|
||||||
code = `${prefix}001`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return code
|
return code;
|
||||||
}
|
};
|
||||||
|
|
||||||
const insertCashInDetail = async (trx, data) => {
|
const insertCashInDetail = async (trx, data) => {
|
||||||
let result = []
|
let result = [];
|
||||||
if(data.length > 0){
|
// if (data.length > 0) {
|
||||||
result = await trx('payment.t_d_cash_in_detail').insert(data,["*"])
|
// 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) => {
|
const updateIntoReserve = async (trx, dataReserve, reserveNo) => {
|
||||||
let result = await trx('trx.t_d_reservation_balance').update(dataReserve, ["*"]).where({c_reservation_no: reserveNo})
|
let result = await trx('trx.t_d_reservation_balance')
|
||||||
return result
|
.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) => {
|
const insertCashIn = async (trx, data) => {
|
||||||
let result = await trx('payment.t_d_cash_in').insert(data,["*"])
|
let result = await trx('payment.t_d_cash_in').insert(data, ['*']);
|
||||||
return result[0]
|
return result[0];
|
||||||
}
|
};
|
||||||
|
|
||||||
const writePaynentHistory = async (data, message, i_log_name, trx) => {
|
const writePaynentHistory = async (data, message, i_log_name, trx) => {
|
||||||
console.log(data)
|
console.log(data);
|
||||||
const result = await trx('log.t_log_invoice').insert({
|
const result = await trx('log.t_log_invoice').insert(
|
||||||
// i_log_name : 102,
|
{
|
||||||
i_log_name : 119,
|
// i_log_name : 102,
|
||||||
d_log : trx.raw('NOW()'),
|
i_log_name: 119,
|
||||||
c_invoice_no : data.c_cash_in_no,
|
d_log: trx.raw('NOW()'),
|
||||||
c_partner_name : data.c_partner_name,
|
c_invoice_no: data.c_cash_in_no,
|
||||||
j_new_data : JSON.stringify(data),
|
c_partner_name: data.c_partner_name,
|
||||||
d_payment_date: trx.raw('NOW()'),
|
j_new_data: JSON.stringify(data),
|
||||||
c_note : message,
|
d_payment_date: trx.raw('NOW()'),
|
||||||
c_status : 'S',
|
c_note: message,
|
||||||
d_created : trx.raw('NOW()'),
|
c_status: 'S',
|
||||||
m_amount : data.amount,
|
d_created: trx.raw('NOW()'),
|
||||||
m_mdr_amount : 0,
|
m_amount: data.amount,
|
||||||
m_mdr_net : data.amount
|
m_mdr_amount: 0,
|
||||||
|
m_mdr_net: data.amount,
|
||||||
|
},
|
||||||
|
['i_log_name', 'c_note']
|
||||||
|
);
|
||||||
|
|
||||||
}, ['i_log_name', 'c_note'])
|
return result;
|
||||||
|
};
|
||||||
return result
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
generateInvoice,
|
generateInvoice,
|
||||||
@@ -358,12 +593,14 @@ module.exports = {
|
|||||||
setReturnSAP,
|
setReturnSAP,
|
||||||
getPostingEt,
|
getPostingEt,
|
||||||
writePaynentHistory,
|
writePaynentHistory,
|
||||||
|
|
||||||
getRecon,
|
getRecon,
|
||||||
generateCode,
|
generateCode,
|
||||||
insertCashInDetail,
|
insertCashInDetail,
|
||||||
getReserve,
|
|
||||||
getPartnerRecon,
|
getPartnerRecon,
|
||||||
|
getPartnerReconSales,
|
||||||
|
getReserve,
|
||||||
|
getSalesKMT,
|
||||||
insertCashIn,
|
insertCashIn,
|
||||||
updateIntoReserve
|
updateIntoReserve,
|
||||||
|
updateIntoSalesKMT
|
||||||
};
|
};
|
||||||
@@ -91,8 +91,8 @@ const cardHistory = async (req, res) => {
|
|||||||
new Date((parseInt(element.slice(0, 8), 16) + 946684800) * 1000)
|
new Date((parseInt(element.slice(0, 8), 16) + 946684800) * 1000)
|
||||||
).format('YYYY-MM-DD HH:mm:ss');
|
).format('YYYY-MM-DD HH:mm:ss');
|
||||||
nominal = parseInt(element.slice(8, 16), 16);
|
nominal = parseInt(element.slice(8, 16), 16);
|
||||||
mid = element.slice(16, 20);
|
mid = element.slice(16, 20).toUpperCase();
|
||||||
tid = element.slice(20, 24);
|
tid = element.slice(20, 24).toUpperCase();
|
||||||
|
|
||||||
// blok yang menandakan konten untuk reska
|
// blok yang menandakan konten untuk reska
|
||||||
checkReskaFormat = element.slice(14, 20);
|
checkReskaFormat = element.slice(14, 20);
|
||||||
@@ -198,6 +198,14 @@ const history = async (req, res) => {
|
|||||||
// param
|
// param
|
||||||
let { mid, tid, card_number, start_date, end_date } = req.body;
|
let { mid, tid, card_number, start_date, end_date } = req.body;
|
||||||
|
|
||||||
|
if (mid) {
|
||||||
|
mid = mid.toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tid) {
|
||||||
|
tid = tid.toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
// log info
|
// log info
|
||||||
winston.logger.info(
|
winston.logger.info(
|
||||||
`${uniqueCode} [ REQUEST CARD-HISTORY-FROM-CMS ]: ${JSON.stringify(
|
`${uniqueCode} [ REQUEST CARD-HISTORY-FROM-CMS ]: ${JSON.stringify(
|
||||||
@@ -228,9 +236,9 @@ const history = async (req, res) => {
|
|||||||
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING CARD-HISTORY-FROM-CMS ]: checking parameter start date and end date...`
|
// `${uniqueCode} [ PROCESSING CARD-HISTORY-FROM-CMS ]: checking parameter start date and end date...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// validation inquiry date
|
// validation inquiry date
|
||||||
if ((!start_date && end_date) || (start_date && !end_date)) {
|
if ((!start_date && end_date) || (start_date && !end_date)) {
|
||||||
@@ -251,9 +259,9 @@ const history = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING CARD-HISTORY-FROM-CMS ]: checking mid and tid is valid or not...`
|
// `${uniqueCode} [ PROCESSING CARD-HISTORY-FROM-CMS ]: checking mid and tid is valid or not...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// get partner, merchant, terminal from tid
|
// get partner, merchant, terminal from tid
|
||||||
let getPartner = await model.getPartner(mid, tid);
|
let getPartner = await model.getPartner(mid, tid);
|
||||||
@@ -275,9 +283,9 @@ const history = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING CARD-HISTORY-FROM-CMS ]: getting history card from log CMS...`
|
// `${uniqueCode} [ PROCESSING CARD-HISTORY-FROM-CMS ]: getting history card from log CMS...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// get data history kartu di log sistem CMS
|
// get data history kartu di log sistem CMS
|
||||||
let history = await model.historyByCardNumber(
|
let history = await model.historyByCardNumber(
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
const { default: axios } = require('axios');
|
||||||
const helper = require('../../helpers/helper');
|
const helper = require('../../helpers/helper');
|
||||||
const winston = require('../../helpers/winston.logger');
|
const winston = require('../../helpers/winston.logger');
|
||||||
const generate = require('./utils/utils');
|
const generate = require('./utils/utils');
|
||||||
@@ -33,6 +34,7 @@ const controller = async (req, res) => {
|
|||||||
let uniqueCode = await helper.getUniqueCode();
|
let uniqueCode = await helper.getUniqueCode();
|
||||||
uniqueCode = uniqueCode + '' + counterDirect;
|
uniqueCode = uniqueCode + '' + counterDirect;
|
||||||
let result = {};
|
let result = {};
|
||||||
|
let usingHSMNumber = 1;
|
||||||
|
|
||||||
// set connection HSM server
|
// set connection HSM server
|
||||||
if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||||
@@ -43,12 +45,14 @@ const controller = async (req, res) => {
|
|||||||
// winston.logger.error(`request to HSM server 2`);
|
// winston.logger.error(`request to HSM server 2`);
|
||||||
|
|
||||||
if (client2.clientAuthenticated == false) {
|
if (client2.clientAuthenticated == false) {
|
||||||
|
usingHSMNumber = 1;
|
||||||
// log warn
|
// log warn
|
||||||
winston.logger.warn(
|
winston.logger.warn(
|
||||||
`${uniqueCode} ================================== REDIRECT USING HSM SERVER 1 ==================================}`
|
`${uniqueCode} ================================== REDIRECT USING HSM SERVER 1 ==================================}`
|
||||||
);
|
);
|
||||||
useClient = client;
|
useClient = client;
|
||||||
} else {
|
} else {
|
||||||
|
usingHSMNumber = 2;
|
||||||
// log warn
|
// log warn
|
||||||
winston.logger.warn(
|
winston.logger.warn(
|
||||||
`${uniqueCode} ================================== USING HSM SERVER 2 ==================================}`
|
`${uniqueCode} ================================== USING HSM SERVER 2 ==================================}`
|
||||||
@@ -57,12 +61,14 @@ const controller = async (req, res) => {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (client.clientAuthenticated == false) {
|
if (client.clientAuthenticated == false) {
|
||||||
|
usingHSMNumber = 2;
|
||||||
// log warn
|
// log warn
|
||||||
winston.logger.warn(
|
winston.logger.warn(
|
||||||
`${uniqueCode} ================================== REDIRECT USING HSM SERVER 2 ==================================}`
|
`${uniqueCode} ================================== REDIRECT USING HSM SERVER 2 ==================================}`
|
||||||
);
|
);
|
||||||
useClient = client2;
|
useClient = client2;
|
||||||
} else {
|
} else {
|
||||||
|
usingHSMNumber = 1;
|
||||||
// log warn
|
// log warn
|
||||||
winston.logger.warn(
|
winston.logger.warn(
|
||||||
`${uniqueCode} ================================== USING HSM SERVER 1 ==================================}`
|
`${uniqueCode} ================================== USING HSM SERVER 1 ==================================}`
|
||||||
@@ -137,20 +143,34 @@ const controller = async (req, res) => {
|
|||||||
await _sleep(10);
|
await _sleep(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (_timeOut) {
|
if (_timeOut) {
|
||||||
// result = {
|
let url = `http://${process.env.IP_HSM_SERVER_1}/feliqserver/v1/api/hsm/refresh`;
|
||||||
// code: "5001",
|
if (usingHSMNumber == 2) {
|
||||||
// message: "Timeout",
|
url = `http://${process.env.IP_HSM_SERVER_2}/feliqserver/v1/api/hsm/refresh`;
|
||||||
// data: {},
|
}
|
||||||
// };
|
|
||||||
|
|
||||||
// // log warn
|
let response = await axios({
|
||||||
// winston.logger.warn(
|
url: url,
|
||||||
// `${uniqueCode} response HSM - auth1v2: ${JSON.stringify(result)}`
|
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;
|
_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;
|
||||||
@@ -62,7 +62,7 @@ function startInterval() {
|
|||||||
interval = setInterval(function () {
|
interval = setInterval(function () {
|
||||||
checkInternetConnected(config)
|
checkInternetConnected(config)
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
console.log(`retry open websocket server 1`); //successfully connected to a server
|
// console.log(`retry open websocket server 1`); //successfully connected to a server
|
||||||
// log debug
|
// log debug
|
||||||
// winston.logger.debug(`retry open websocket server 1`);
|
// winston.logger.debug(`retry open websocket server 1`);
|
||||||
client.open();
|
client.open();
|
||||||
@@ -106,7 +106,7 @@ class WebSocketClient {
|
|||||||
// Disconnection of WebSocket
|
// Disconnection of WebSocket
|
||||||
close = () => {
|
close = () => {
|
||||||
this.ws.close();
|
this.ws.close();
|
||||||
console.log(`websocket server 1 close`);
|
// console.log(`websocket server 1 close`);
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
// winston.logger.debug(`websocket server 1 close`);
|
// winston.logger.debug(`websocket server 1 close`);
|
||||||
@@ -114,13 +114,13 @@ class WebSocketClient {
|
|||||||
|
|
||||||
// Open event
|
// Open event
|
||||||
onOpen = () => {
|
onOpen = () => {
|
||||||
console.log(`opening websocket server 1`);
|
// console.log(`opening websocket server 1`);
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
// winston.logger.debug(`opening websocket server 1`);
|
// winston.logger.debug(`opening websocket server 1`);
|
||||||
|
|
||||||
if (this.isOpened()) {
|
if (this.isOpened()) {
|
||||||
console.log(`websocket server 1 open successfully`);
|
// console.log(`websocket server 1 open successfully`);
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
// winston.logger.debug(`websocket server 1 open successfully`);
|
// winston.logger.debug(`websocket server 1 open successfully`);
|
||||||
@@ -137,7 +137,7 @@ class WebSocketClient {
|
|||||||
};
|
};
|
||||||
|
|
||||||
onClose = () => {
|
onClose = () => {
|
||||||
console.log(`websocket server 1 close`);
|
// console.log(`websocket server 1 close`);
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
// winston.logger.debug(`websocket server 1 close`);
|
// winston.logger.debug(`websocket server 1 close`);
|
||||||
@@ -209,9 +209,9 @@ class WebSocketClient {
|
|||||||
message[1] == 0
|
message[1] == 0
|
||||||
) {
|
) {
|
||||||
respData = null;
|
respData = null;
|
||||||
console.log(
|
// console.log(
|
||||||
`websocket server 1 message tenant: ${generate.buf2hex(message)}`
|
// `websocket server 1 message tenant: ${generate.buf2hex(message)}`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
// winston.logger.debug(
|
// winston.logger.debug(
|
||||||
@@ -227,16 +227,16 @@ class WebSocketClient {
|
|||||||
await _sleep(10);
|
await _sleep(10);
|
||||||
}
|
}
|
||||||
let respCode = generate.getResponseCode(respData);
|
let respCode = generate.getResponseCode(respData);
|
||||||
console.log(`websocket server 1 resp data tenant: ${respCode}`);
|
// console.log(`websocket server 1 resp data tenant: ${respCode}`);
|
||||||
// log debug
|
// log debug
|
||||||
// winston.logger.debug(`websocket server 1 resp data tenant: ${respCode}`);
|
// winston.logger.debug(`websocket server 1 resp data tenant: ${respCode}`);
|
||||||
|
|
||||||
if (respCode == '0000' || respCode == '0502') {
|
if (respCode == '0000' || respCode == '0502') {
|
||||||
this.clientAuthenticated = true;
|
this.clientAuthenticated = true;
|
||||||
}
|
}
|
||||||
console.log(
|
// console.log(
|
||||||
`websocket server 1 client authenticate: ${this.clientAuthenticated}`
|
// `websocket server 1 client authenticate: ${this.clientAuthenticated}`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
// winston.logger.debug(
|
// winston.logger.debug(
|
||||||
@@ -253,7 +253,7 @@ class WebSocketClient {
|
|||||||
|
|
||||||
var client = new WebSocketClient();
|
var client = new WebSocketClient();
|
||||||
if (!client.openWebSocketStatus) {
|
if (!client.openWebSocketStatus) {
|
||||||
console.log(`first open websocket server 1`);
|
// console.log(`first open websocket server 1`);
|
||||||
|
|
||||||
// log info
|
// log info
|
||||||
// winston.logger.info(`first open websocket server 1`);
|
// winston.logger.info(`first open websocket server 1`);
|
||||||
@@ -264,7 +264,7 @@ setInterval(function () {
|
|||||||
// let statusConnection = client.clientAuthenticated;
|
// let statusConnection = client.clientAuthenticated;
|
||||||
// if (!statusConnection) {
|
// if (!statusConnection) {
|
||||||
if (!this.ws) {
|
if (!this.ws) {
|
||||||
console.log(`websocket server 1 retry call client Auth`);
|
// console.log(`websocket server 1 retry call client Auth`);
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
// winston.logger.debug(`retry call client Auth`);
|
// winston.logger.debug(`retry call client Auth`);
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ function startInterval() {
|
|||||||
interval = setInterval(function () {
|
interval = setInterval(function () {
|
||||||
checkInternetConnected(config)
|
checkInternetConnected(config)
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
console.log(`retry open websocket server 2`); //successfully connected to a server
|
// console.log(`retry open websocket server 2`); //successfully connected to a server
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
// winston.logger.debug(`retry open websocket server 2`);
|
// winston.logger.debug(`retry open websocket server 2`);
|
||||||
@@ -107,7 +107,7 @@ class WebSocketClient {
|
|||||||
// Disconnection of WebSocket
|
// Disconnection of WebSocket
|
||||||
close = () => {
|
close = () => {
|
||||||
this.ws.close();
|
this.ws.close();
|
||||||
console.log(`websocket server 2 close`);
|
// console.log(`websocket server 2 close`);
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
// winston.logger.debug(`websocket server 2 close`);
|
// winston.logger.debug(`websocket server 2 close`);
|
||||||
@@ -115,13 +115,13 @@ class WebSocketClient {
|
|||||||
|
|
||||||
// Open event
|
// Open event
|
||||||
onOpen = () => {
|
onOpen = () => {
|
||||||
console.log(`opening server 2 websocket`);
|
// console.log(`opening server 2 websocket`);
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
// winston.logger.debug(`opening server 2 websocket`);
|
// winston.logger.debug(`opening server 2 websocket`);
|
||||||
|
|
||||||
if (this.isOpened()) {
|
if (this.isOpened()) {
|
||||||
console.log(`websocket server 2 open successfully`);
|
// console.log(`websocket server 2 open successfully`);
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
// winston.logger.debug(`websocket server 2 open successfully`);
|
// winston.logger.debug(`websocket server 2 open successfully`);
|
||||||
@@ -138,7 +138,7 @@ class WebSocketClient {
|
|||||||
};
|
};
|
||||||
|
|
||||||
onClose = () => {
|
onClose = () => {
|
||||||
console.log(`websocket server 2 close`);
|
// console.log(`websocket server 2 close`);
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
// winston.logger.debug(`websocket server 2 close`);
|
// winston.logger.debug(`websocket server 2 close`);
|
||||||
@@ -210,9 +210,9 @@ class WebSocketClient {
|
|||||||
message[1] == 0
|
message[1] == 0
|
||||||
) {
|
) {
|
||||||
respData = null;
|
respData = null;
|
||||||
console.log(
|
// console.log(
|
||||||
`websocket server 2 message tenant: ${generate.buf2hex(message)}`
|
// `websocket server 2 message tenant: ${generate.buf2hex(message)}`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
// winston.logger.debug(
|
// winston.logger.debug(
|
||||||
@@ -228,7 +228,7 @@ class WebSocketClient {
|
|||||||
await _sleep(10);
|
await _sleep(10);
|
||||||
}
|
}
|
||||||
let respCode = generate.getResponseCode(respData);
|
let respCode = generate.getResponseCode(respData);
|
||||||
console.log(`websocket server 2 resp data tenant: ${respCode}`);
|
// console.log(`websocket server 2 resp data tenant: ${respCode}`);
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
// winston.logger.debug(`websocket server 2 resp data tenant: ${respCode}`);
|
// winston.logger.debug(`websocket server 2 resp data tenant: ${respCode}`);
|
||||||
@@ -236,9 +236,9 @@ class WebSocketClient {
|
|||||||
if (respCode == '0000' || respCode == '0502') {
|
if (respCode == '0000' || respCode == '0502') {
|
||||||
this.clientAuthenticated = true;
|
this.clientAuthenticated = true;
|
||||||
}
|
}
|
||||||
console.log(
|
// console.log(
|
||||||
`websocket server 2 client authenticate: ${this.clientAuthenticated}`
|
// `websocket server 2 client authenticate: ${this.clientAuthenticated}`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
// winston.logger.debug(
|
// winston.logger.debug(
|
||||||
@@ -255,7 +255,7 @@ class WebSocketClient {
|
|||||||
|
|
||||||
var client2 = new WebSocketClient();
|
var client2 = new WebSocketClient();
|
||||||
if (!client2.openWebSocketStatus) {
|
if (!client2.openWebSocketStatus) {
|
||||||
console.log(`first open websocket server 2`);
|
// console.log(`first open websocket server 2`);
|
||||||
|
|
||||||
// log info
|
// log info
|
||||||
// winston.logger.info(`first open websocket server 2`);
|
// winston.logger.info(`first open websocket server 2`);
|
||||||
@@ -266,7 +266,7 @@ setInterval(function () {
|
|||||||
// let statusConnection = client2.clientAuthenticated;
|
// let statusConnection = client2.clientAuthenticated;
|
||||||
// if (!statusConnection) {
|
// if (!statusConnection) {
|
||||||
if (!this.ws) {
|
if (!this.ws) {
|
||||||
console.log(`websocket server 2 retry call client Auth`);
|
// console.log(`websocket server 2 retry call client Auth`);
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
// winston.logger.debug(`retry call client Auth`);
|
// winston.logger.debug(`retry call client Auth`);
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ const controller = async (req, res) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// insert data load balance
|
// insert data load balance
|
||||||
let insert = await loadBalance.loadingBalanceInsert(data);
|
let insert = await loadBalance.loadingBalanceInsert(req, data);
|
||||||
if (insert) {
|
if (insert) {
|
||||||
if (insert.code == '00') {
|
if (insert.code == '00') {
|
||||||
result = {
|
result = {
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -206,18 +206,33 @@ const controller = async (req, res) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// update data load balance
|
// update data load balance
|
||||||
await loadBalance.loadingBalanceUpdate(data);
|
let update = await loadBalance.loadingBalanceUpdate(data);
|
||||||
|
if (update) {
|
||||||
result = {
|
if (update.code == '00') {
|
||||||
code: '5002',
|
result = {
|
||||||
message: 'failed from HSM',
|
code: '5002',
|
||||||
data: {
|
message: 'failed from HSM',
|
||||||
trxID: generate.buf2hex(transactionId),
|
data: {
|
||||||
responseCode: respData1.slice(6, 10),
|
trxID: generate.buf2hex(transactionId),
|
||||||
transcode: null,
|
responseCode: respData1.slice(6, 10),
|
||||||
load_balance_number: update.data.load_balance_number,
|
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 {
|
} else {
|
||||||
// jika sudah mencapai maksimum counting flag, maka reset flag ke awal
|
// jika sudah mencapai maksimum counting flag, maka reset flag ke awal
|
||||||
if (flag >= 255) {
|
if (flag >= 255) {
|
||||||
|
|||||||
@@ -2,9 +2,16 @@ const { param, body, validationResult } = require('express-validator');
|
|||||||
const helper = require('../../helpers/helper');
|
const helper = require('../../helpers/helper');
|
||||||
const winston = require('../../helpers/winston.logger');
|
const winston = require('../../helpers/winston.logger');
|
||||||
const model = require('./loadbalance.model');
|
const model = require('./loadbalance.model');
|
||||||
|
const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
|
const {
|
||||||
|
setLoadBalanceNumberSequence,
|
||||||
|
} = require('../../middlewares/redis.middleware');
|
||||||
moment.locale('id');
|
moment.locale('id');
|
||||||
|
|
||||||
|
// variable yang digunakan untuk melakukan perulangan proses generate reservation number jika reservation number yang di generate sudah digunakan orang lain
|
||||||
|
var maxLoopParameter = 1000;
|
||||||
|
|
||||||
// VALIDATION
|
// VALIDATION
|
||||||
const validate = (method) => {
|
const validate = (method) => {
|
||||||
switch (method) {
|
switch (method) {
|
||||||
@@ -61,7 +68,7 @@ const generateLoadBalanceNumber = async (data, date, counter) => {
|
|||||||
|
|
||||||
// insert to temp load balance number
|
// insert to temp load balance number
|
||||||
let insert = await model.insertLoadBalanceNumber(loadBalanceNumber);
|
let insert = await model.insertLoadBalanceNumber(loadBalanceNumber);
|
||||||
if (!insert) {
|
if (insert.rowCount < 1) {
|
||||||
loadBalanceNumber = 'XX';
|
loadBalanceNumber = 'XX';
|
||||||
}
|
}
|
||||||
return loadBalanceNumber;
|
return loadBalanceNumber;
|
||||||
@@ -218,14 +225,12 @@ const updateAllTransaction = async (
|
|||||||
// generate load balance number
|
// generate load balance number
|
||||||
let newLoadBalanceNumber;
|
let newLoadBalanceNumber;
|
||||||
let getLoadBalanceSequence;
|
let getLoadBalanceSequence;
|
||||||
let loadBalanceNoSequence;
|
let loadBalanceNoSequence = req.load_balance_number_sequence;
|
||||||
let maxLoop = 0;
|
|
||||||
do {
|
|
||||||
// log debug
|
|
||||||
winston.logger.debug(
|
|
||||||
`${uniqueCode} getting loading balance sequence...`
|
|
||||||
);
|
|
||||||
|
|
||||||
|
// log debug
|
||||||
|
winston.logger.debug(`${uniqueCode} getting loading balance sequence...`);
|
||||||
|
|
||||||
|
if (!loadBalanceNoSequence) {
|
||||||
// get loading balance
|
// get loading balance
|
||||||
getLoadBalanceSequence = await model.getLoadBalanceSequence(
|
getLoadBalanceSequence = await model.getLoadBalanceSequence(
|
||||||
getPartner,
|
getPartner,
|
||||||
@@ -234,6 +239,21 @@ const updateAllTransaction = async (
|
|||||||
loadBalanceNoSequence = getLoadBalanceSequence
|
loadBalanceNoSequence = getLoadBalanceSequence
|
||||||
? parseInt(getLoadBalanceSequence.i_load_balance_no_seq) + 1
|
? parseInt(getLoadBalanceSequence.i_load_balance_no_seq) + 1
|
||||||
: 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
|
||||||
|
);
|
||||||
|
|
||||||
// log warn
|
// log warn
|
||||||
winston.logger.warn(`${uniqueCode} generating load balance number...`);
|
winston.logger.warn(`${uniqueCode} generating load balance number...`);
|
||||||
@@ -244,15 +264,23 @@ const updateAllTransaction = async (
|
|||||||
loadBalanceNoSequence
|
loadBalanceNoSequence
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (newLoadBalanceNumber != 'XX') {
|
||||||
|
// set sequence to redis
|
||||||
|
// await setLoadBalanceNumberSequence(
|
||||||
|
// req.partner_id_token,
|
||||||
|
// loadBalanceNoSequence
|
||||||
|
// );
|
||||||
|
}
|
||||||
|
|
||||||
// log warn
|
// log warn
|
||||||
winston.logger.warn(
|
winston.logger.warn(
|
||||||
`${uniqueCode} load balance number is ${newLoadBalanceNumber}.`
|
`${uniqueCode} load balance number is ${newLoadBalanceNumber}.`
|
||||||
);
|
);
|
||||||
|
|
||||||
if (maxLoop > 20) {
|
if (maxLoop > maxLoopParameter) {
|
||||||
// create log
|
// create log
|
||||||
winston.logger.error(
|
winston.logger.error(
|
||||||
`500 internal server error (max loop) - backend server | ${error.message}`
|
`${uniqueCode} 500 internal server error. Server is busy. please try again`
|
||||||
);
|
);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -303,26 +331,26 @@ const updateAllTransaction = async (
|
|||||||
await model.createDetailLoadBalanceFromReservation(reservationNumber);
|
await model.createDetailLoadBalanceFromReservation(reservationNumber);
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} detail load balance with reservation no : ${JSON.stringify(
|
// `${uniqueCode} detail load balance with reservation no : ${JSON.stringify(
|
||||||
reservationNumber
|
// reservationNumber
|
||||||
)}`
|
// )}`
|
||||||
);
|
// );
|
||||||
|
|
||||||
if (detailLoadBalance.length > 0) {
|
if (detailLoadBalance.length > 0) {
|
||||||
// log warn
|
// log warn
|
||||||
winston.logger.warn(
|
// winston.logger.warn(
|
||||||
`${uniqueCode} AAAAAAAAAAAAAAAAAA1111 [DATA] : ${JSON.stringify(
|
// `${uniqueCode} AAAAAAAAAAAAAAAAAA1111 [DATA] : ${JSON.stringify(
|
||||||
reservationNumber
|
// reservationNumber
|
||||||
)} [LB] : ${JSON.stringify(dataLoadBalance)} [LBD] : ${JSON.stringify(
|
// )} [LB] : ${JSON.stringify(dataLoadBalance)} [LBD] : ${JSON.stringify(
|
||||||
detailLoadBalance
|
// detailLoadBalance
|
||||||
)} [NOW] : ${JSON.stringify(now)} [FLAG] : ${JSON.stringify(flag)}`
|
// )} [NOW] : ${JSON.stringify(now)} [FLAG] : ${JSON.stringify(flag)}`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} updating reservation and insert new load balance transaction...`
|
// `${uniqueCode} updating reservation and insert new load balance transaction...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// update reservation and load balance transaction
|
// update reservation and load balance transaction
|
||||||
let updateReservationAndInsertLoadingBalance =
|
let updateReservationAndInsertLoadingBalance =
|
||||||
@@ -335,11 +363,11 @@ const updateAllTransaction = async (
|
|||||||
);
|
);
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} status insert new load balance and update reservation : ${JSON.stringify(
|
// `${uniqueCode} status insert new load balance and update reservation : ${JSON.stringify(
|
||||||
updateReservationAndInsertLoadingBalance
|
// updateReservationAndInsertLoadingBalance
|
||||||
)}`
|
// )}`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// if (updateReservationAndInsertLoadingBalance > 0) {
|
// if (updateReservationAndInsertLoadingBalance > 0) {
|
||||||
// // log debug
|
// // log debug
|
||||||
@@ -428,60 +456,72 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
return res.status(200).json(result);
|
return res.status(200).json(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
let cardBlacklist = await model.getCardBlacklist(card_number);
|
||||||
winston.logger.debug(
|
if (cardBlacklist) {
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking production card number or not...`
|
if (cardBlacklist.c_status == 'B') {
|
||||||
);
|
|
||||||
|
|
||||||
// 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 = {
|
result = {
|
||||||
code: '400',
|
code: '445',
|
||||||
message: "It's not production card number.",
|
message: 'Card is Blacklisted',
|
||||||
data: {},
|
data: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
// 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: {},
|
|
||||||
};
|
|
||||||
|
|
||||||
// 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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: {},
|
||||||
|
// };
|
||||||
|
|
||||||
|
// // 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: {},
|
||||||
|
// };
|
||||||
|
|
||||||
|
// // log warn
|
||||||
|
// winston.logger.warn(
|
||||||
|
// `${uniqueCode} [ RESPONSE LOADING-BALANCE-REQUEST ]: ${JSON.stringify(
|
||||||
|
// result
|
||||||
|
// )}`
|
||||||
|
// );
|
||||||
|
|
||||||
|
// return res.status(200).json(result);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
// time
|
// time
|
||||||
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||||
let year = moment().format('Y');
|
let year = moment().format('Y');
|
||||||
let month = moment().format('M');
|
let month = moment().format('M');
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking partner...`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking partner...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// get partner, merchant, terminal from tid
|
// get partner, merchant, terminal from tid
|
||||||
let getPartner = await model.getPartner(mid, tid);
|
let getPartner = await model.getPartner(mid, tid);
|
||||||
@@ -502,6 +542,16 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
return res.status(200).json(result);
|
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
|
// get parameter setting pengecekkan nomor kartu dengan card product di CMS
|
||||||
let getCheckByCardProductStatusValue =
|
let getCheckByCardProductStatusValue =
|
||||||
await model.getCheckByCardProductStatusValue();
|
await model.getCheckByCardProductStatusValue();
|
||||||
@@ -529,9 +579,9 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
// jika settingan pengecekkan nomor kartu dengan card product CMS aktif
|
// jika settingan pengecekkan nomor kartu dengan card product CMS aktif
|
||||||
if (checkByCardProductStatusValue == 'A') {
|
if (checkByCardProductStatusValue == 'A') {
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking card number...`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking card number...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// check card number request dengan list card number yang terdaftar di CMS
|
// check card number request dengan list card number yang terdaftar di CMS
|
||||||
let checkCardNumber = await model.checkCardNumber(card_number);
|
let checkCardNumber = await model.checkCardNumber(card_number);
|
||||||
@@ -556,9 +606,9 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking flag on the card and the server...`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking flag on the card and the server...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// check last flag untuk nomor kartu dan uid yang di request di sistem CMS
|
// check last flag untuk nomor kartu dan uid yang di request di sistem CMS
|
||||||
let checkFlag = await model.checkFlag(card_number, uid.toUpperCase());
|
let checkFlag = await model.checkFlag(card_number, uid.toUpperCase());
|
||||||
@@ -570,9 +620,9 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking reservation pending...`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking reservation pending...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// get total reservation pending
|
// get total reservation pending
|
||||||
let getReservationPending = await model.getReservationPendingV2(
|
let getReservationPending = await model.getReservationPendingV2(
|
||||||
@@ -582,9 +632,9 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking fraud transaction...`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking fraud transaction...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// cek disini apakah sebelumnya topup
|
// cek disini apakah sebelumnya topup
|
||||||
let cardHistory = await model.checkCardHistory(card_number);
|
let cardHistory = await model.checkCardHistory(card_number);
|
||||||
@@ -631,7 +681,7 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
|
|
||||||
// log warn
|
// log warn
|
||||||
winston.logger.warn(
|
winston.logger.warn(
|
||||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE-REQUEST ]: ${JSON.stringify(
|
`${uniqueCode} [ RESPONSE LOADING-BALANCE-REQUEST updateFraudToReserve ]: ${JSON.stringify(
|
||||||
result
|
result
|
||||||
)}`
|
)}`
|
||||||
);
|
);
|
||||||
@@ -647,9 +697,9 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
await model.getReservationPendingWithFlagCounter(card_number, now, flag);
|
await model.getReservationPendingWithFlagCounter(card_number, now, flag);
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking reservation pending with flag...`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking reservation pending with flag...`
|
||||||
);
|
// );
|
||||||
// get total reservation pending
|
// get total reservation pending
|
||||||
// let getReservationPendingWithFlag =
|
// let getReservationPendingWithFlag =
|
||||||
// await model.getReservationPendingWithFlag(card_number, now);
|
// await model.getReservationPendingWithFlag(card_number, now);
|
||||||
@@ -674,9 +724,9 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: updating reservation and load balance transaction...`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: updating reservation and load balance transaction...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// update
|
// update
|
||||||
let insertUpdate = await updateAllTransaction(
|
let insertUpdate = await updateAllTransaction(
|
||||||
@@ -694,9 +744,9 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
|
|
||||||
if (insertUpdate) {
|
if (insertUpdate) {
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSINGE LOADING-BALANCE-REQUEST ]: updating flag to server...`
|
// `${uniqueCode} [ PROCESSINGE LOADING-BALANCE-REQUEST ]: updating flag to server...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// update flag from Server
|
// update flag from Server
|
||||||
await model.updateFlag(
|
await model.updateFlag(
|
||||||
@@ -747,9 +797,9 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
// await model.updateFlag(now, card_number, uid.toUpperCase(), balance, flag);
|
// await model.updateFlag(now, card_number, uid.toUpperCase(), balance, flag);
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking reservation pending...`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking reservation pending...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// reget total reservation pending
|
// reget total reservation pending
|
||||||
getReservationPending = await model.getReservationPendingV2(
|
getReservationPending = await model.getReservationPendingV2(
|
||||||
@@ -767,7 +817,7 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
|
|
||||||
// log warn
|
// log warn
|
||||||
winston.logger.warn(
|
winston.logger.warn(
|
||||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE-REQUEST ]: ${JSON.stringify(
|
`${uniqueCode} [ RESPONSE LOADING-BALANCE-REQUEST getReservationPending ]: ${JSON.stringify(
|
||||||
result
|
result
|
||||||
)}`
|
)}`
|
||||||
);
|
);
|
||||||
@@ -798,7 +848,7 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
|
|
||||||
// log warn
|
// log warn
|
||||||
winston.logger.warn(
|
winston.logger.warn(
|
||||||
`${uniqueCode} [ RESPONSE LOADING-BALANCE-REQUEST ]: ${JSON.stringify(
|
`${uniqueCode} [ RESPONSE LOADING-BALANCE-REQUEST totalReservation ]: ${JSON.stringify(
|
||||||
result
|
result
|
||||||
)}`
|
)}`
|
||||||
);
|
);
|
||||||
@@ -807,14 +857,14 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking the card number in list fraud transaction or not...XXXXXXXXXXXXXXXXXXXX`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking the card number in list fraud transaction or not...XXXXXXXXXXXXXXXXXXXX`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking total topup amount...`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking total topup amount...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// check total amount topup
|
// check total amount topup
|
||||||
if (parseInt(amountTopup) <= 0) {
|
if (parseInt(amountTopup) <= 0) {
|
||||||
@@ -835,9 +885,9 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking BI regulation status...`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking BI regulation status...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// get BI regulation status
|
// get BI regulation status
|
||||||
let getBIRegulationStatus = await model.getBIRegulationStatus();
|
let getBIRegulationStatus = await model.getBIRegulationStatus();
|
||||||
@@ -861,7 +911,7 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
|
|
||||||
if (getBIRegulationStatus.c_value == 'A') {
|
if (getBIRegulationStatus.c_value == 'A') {
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(`${uniqueCode} checking topup partial status...`);
|
// winston.logger.debug(`${uniqueCode} checking topup partial status...`);
|
||||||
|
|
||||||
// check topup partial status
|
// check topup partial status
|
||||||
let getTopupPartialStatus = await model.getTopupPartialStatus();
|
let getTopupPartialStatus = await model.getTopupPartialStatus();
|
||||||
@@ -884,9 +934,9 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking max balance on the card...`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking max balance on the card...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// get max saldo on the card
|
// get max saldo on the card
|
||||||
let getMaxAmountOnTheCard = await model.getMaxAmountOnTheCard();
|
let getMaxAmountOnTheCard = await model.getMaxAmountOnTheCard();
|
||||||
@@ -985,9 +1035,9 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking max topup per month...`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking max topup per month...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// get accumulated balance in this month
|
// get accumulated balance in this month
|
||||||
let accumulatedBalance = 0;
|
let accumulatedBalance = 0;
|
||||||
@@ -1099,9 +1149,9 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: updating status reservation to in progress...${reservationNumberTemp}, ${now}, ${flag}`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: updating status reservation to in progress...${reservationNumberTemp}, ${now}, ${flag}`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// update status to in progress
|
// update status to in progress
|
||||||
let updateStatusReservation = await model.updateStatusReservation(
|
let updateStatusReservation = await model.updateStatusReservation(
|
||||||
@@ -1171,7 +1221,7 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
// *Description:*
|
// *Description:*
|
||||||
// proses insert data topup atau load balance ke sistem CMS
|
// proses insert data topup atau load balance ke sistem CMS
|
||||||
|
|
||||||
const loadingBalanceInsert = async (param) => {
|
const loadingBalanceInsert = async (req, param) => {
|
||||||
try {
|
try {
|
||||||
// param
|
// param
|
||||||
let mid = param.mid;
|
let mid = param.mid;
|
||||||
@@ -1223,10 +1273,20 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
return result;
|
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
|
// log warn
|
||||||
winston.logger.warn(
|
// winston.logger.warn(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: checking reservation status...`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: checking reservation status...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// check reservation status
|
// check reservation status
|
||||||
for (let index = 0; index < reservation_number.length; index++) {
|
for (let index = 0; index < reservation_number.length; index++) {
|
||||||
@@ -1285,9 +1345,9 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log warn
|
// log warn
|
||||||
winston.logger.warn(
|
// winston.logger.warn(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: checking last log history...`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: checking last log history...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// get last history by card number
|
// get last history by card number
|
||||||
let lastHistory = await model.getLastHistory(card_number);
|
let lastHistory = await model.getLastHistory(card_number);
|
||||||
@@ -1296,17 +1356,17 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
// if last history card is topup (21 = log name id for topup)
|
// if last history card is topup (21 = log name id for topup)
|
||||||
if (lastHistory.i_log_name == 21 && lastHistory.c_source == 'CMS') {
|
if (lastHistory.i_log_name == 21 && lastHistory.c_source == 'CMS') {
|
||||||
// log warn
|
// log warn
|
||||||
winston.logger.warn(
|
// winston.logger.warn(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: inserting fraud transaction...`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: inserting fraud transaction...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// insert reservation transaction to fraud table
|
// insert reservation transaction to fraud table
|
||||||
await model.insertFraudTransaction(reservation_number);
|
await model.insertFraudTransaction(reservation_number);
|
||||||
|
|
||||||
// log warn
|
// log warn
|
||||||
winston.logger.warn(
|
// winston.logger.warn(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: suspending reservation...`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: suspending reservation...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// update reservation with suspend status
|
// update reservation with suspend status
|
||||||
await model.suspendReservation(reservation_number, now);
|
await model.suspendReservation(reservation_number, now);
|
||||||
@@ -1329,9 +1389,9 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log warn
|
// log warn
|
||||||
winston.logger.warn(
|
// winston.logger.warn(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: checking fraud transaction...`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: checking fraud transaction...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// get data fraud by card number and status fraud is not closed
|
// get data fraud by card number and status fraud is not closed
|
||||||
let fraudTransaction = await model.getFraudTransaction(card_number);
|
let fraudTransaction = await model.getFraudTransaction(card_number);
|
||||||
@@ -1344,9 +1404,9 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log warn
|
// log warn
|
||||||
winston.logger.warn(
|
// winston.logger.warn(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: checking reservation pending...`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: checking reservation pending...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// get total reservation pending without fraud
|
// get total reservation pending without fraud
|
||||||
let getReservationPending = await model.getReservationPendingWithoutFraud(
|
let getReservationPending = await model.getReservationPendingWithoutFraud(
|
||||||
@@ -1373,9 +1433,9 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log warn
|
// log warn
|
||||||
winston.logger.warn(
|
// winston.logger.warn(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: checking total topup amount...`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: checking total topup amount...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// check total topup and request topup
|
// check total topup and request topup
|
||||||
let amountTopup = 0;
|
let amountTopup = 0;
|
||||||
@@ -1403,14 +1463,14 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
// generate load balance number
|
// generate load balance number
|
||||||
let loadBalanceNumber;
|
let loadBalanceNumber;
|
||||||
let getLoadBalanceSequence;
|
let getLoadBalanceSequence;
|
||||||
let loadBalanceNoSequence;
|
let loadBalanceNoSequence = req.load_balance_number_sequence;
|
||||||
let maxLoop = 0;
|
|
||||||
do {
|
|
||||||
// log debug
|
|
||||||
winston.logger.debug(
|
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: getting loading balance sequence...`
|
|
||||||
);
|
|
||||||
|
|
||||||
|
// log debug
|
||||||
|
// winston.logger.debug(
|
||||||
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: getting loading balance sequence...`
|
||||||
|
// );
|
||||||
|
|
||||||
|
if (!loadBalanceNoSequence) {
|
||||||
// get loading balance
|
// get loading balance
|
||||||
getLoadBalanceSequence = await model.getLoadBalanceSequence(
|
getLoadBalanceSequence = await model.getLoadBalanceSequence(
|
||||||
getPartner,
|
getPartner,
|
||||||
@@ -1419,11 +1479,26 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
loadBalanceNoSequence = getLoadBalanceSequence
|
loadBalanceNoSequence = getLoadBalanceSequence
|
||||||
? parseInt(getLoadBalanceSequence.i_load_balance_no_seq) + 1
|
? parseInt(getLoadBalanceSequence.i_load_balance_no_seq) + 1
|
||||||
: 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
|
||||||
|
);
|
||||||
|
|
||||||
// log warn
|
// log warn
|
||||||
winston.logger.warn(
|
// winston.logger.warn(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: generating load balance number...`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: generating load balance number...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
loadBalanceNumber = await generateLoadBalanceNumber(
|
loadBalanceNumber = await generateLoadBalanceNumber(
|
||||||
getPartner,
|
getPartner,
|
||||||
@@ -1431,22 +1506,30 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
loadBalanceNoSequence
|
loadBalanceNoSequence
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// if (loadBalanceNumber != 'XX') {
|
||||||
|
// set sequence to redis
|
||||||
|
// await setLoadBalanceNumberSequence(
|
||||||
|
// req.partner_id_token,
|
||||||
|
// loadBalanceNoSequence
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
// log warn
|
// log warn
|
||||||
winston.logger.warn(
|
winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: load balance number is ${loadBalanceNumber}.`
|
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: load balance number sequence is ${loadBalanceNoSequence}.`
|
||||||
);
|
);
|
||||||
|
|
||||||
if (maxLoop > 20) {
|
if (maxLoop > maxLoopParameter) {
|
||||||
// create log
|
// create log
|
||||||
winston.logger.error(
|
winston.logger.error(
|
||||||
`[ RESPONSE LOADING-BALANCE-INSERT ]: 500 internal server error (max loop) - backend server | ${error.message}`
|
`${uniqueCode} [ RESPONSE LOADING-BALANCE-INSERT ]: 500 internal server error. Server is busy. please try again`
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
code: '500',
|
code: '500',
|
||||||
message:
|
message:
|
||||||
process.env.NODE_ENV != 'production'
|
process.env.NODE_ENV != 'production'
|
||||||
? error.message
|
? '500 internal server error (max loop) - backend server.'
|
||||||
: '500 internal server error (max loop) - backend server.',
|
: '500 internal server error (max loop) - backend server.',
|
||||||
data: {},
|
data: {},
|
||||||
};
|
};
|
||||||
@@ -1494,9 +1577,9 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: getting reservation detail...`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: getting reservation detail...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
let detail = [];
|
let detail = [];
|
||||||
reservation_number = [];
|
reservation_number = [];
|
||||||
@@ -1562,14 +1645,14 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
|
|
||||||
// check data load balance by reservation_number exist or not
|
// check data load balance by reservation_number exist or not
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: checking load balance transaction has been exists or not...`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: checking load balance transaction has been exists or not...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// log warn
|
// log warn
|
||||||
winston.logger.warn(
|
// winston.logger.warn(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: inserting load balance transaction...`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: inserting load balance transaction...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// insert transaction
|
// insert transaction
|
||||||
let insertLoadingBalance = await model.insertLoadingBalance(
|
let insertLoadingBalance = await model.insertLoadingBalance(
|
||||||
@@ -1585,19 +1668,19 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// log warn
|
// log warn
|
||||||
winston.logger.warn(
|
// winston.logger.warn(
|
||||||
`${uniqueCode} [DATA] : ${JSON.stringify(
|
// `${uniqueCode} [DATA] : ${JSON.stringify(
|
||||||
data
|
// data
|
||||||
)} [DETAIL] : ${JSON.stringify(detail)} [RSV] : ${JSON.stringify(
|
// )} [DETAIL] : ${JSON.stringify(detail)} [RSV] : ${JSON.stringify(
|
||||||
reservation_number
|
// reservation_number
|
||||||
)} [NOW] : ${JSON.stringify(now)} [WRITE STATUS] : ${JSON.stringify(
|
// )} [NOW] : ${JSON.stringify(now)} [WRITE STATUS] : ${JSON.stringify(
|
||||||
write_status
|
// write_status
|
||||||
)} [CARD NUMBER] : ${JSON.stringify(
|
// )} [CARD NUMBER] : ${JSON.stringify(
|
||||||
card_number
|
// card_number
|
||||||
)} [UID] : ${JSON.stringify(uid)} [BALANCE] : ${JSON.stringify(
|
// )} [UID] : ${JSON.stringify(uid)} [BALANCE] : ${JSON.stringify(
|
||||||
balance
|
// balance
|
||||||
)} [FLAG] : ${JSON.stringify(flag)}`
|
// )} [FLAG] : ${JSON.stringify(flag)}`
|
||||||
);
|
// );
|
||||||
|
|
||||||
if (insertLoadingBalance > 0) {
|
if (insertLoadingBalance > 0) {
|
||||||
result = {
|
result = {
|
||||||
@@ -1687,9 +1770,9 @@ const loadingBalanceUpdate = async (param) => {
|
|||||||
let today = moment().format('YYYY-MM-DD');
|
let today = moment().format('YYYY-MM-DD');
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-UPDATE ]: checking partner...`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-UPDATE ]: checking partner...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// get partner, merchant, terminal from tid
|
// get partner, merchant, terminal from tid
|
||||||
let getPartner = await model.getPartner(mid, tid);
|
let getPartner = await model.getPartner(mid, tid);
|
||||||
@@ -1710,6 +1793,16 @@ const loadingBalanceUpdate = async (param) => {
|
|||||||
return result;
|
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 = {
|
let data = {
|
||||||
d_load_balance: now,
|
d_load_balance: now,
|
||||||
c_ref_no: ref_no,
|
c_ref_no: ref_no,
|
||||||
@@ -1724,9 +1817,9 @@ const loadingBalanceUpdate = async (param) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-UPDATE ]: updating load balance transaction...`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-UPDATE ]: updating load balance transaction...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// update transaction
|
// update transaction
|
||||||
await model.updateLoadingBalance(
|
await model.updateLoadingBalance(
|
||||||
@@ -1741,9 +1834,9 @@ const loadingBalanceUpdate = async (param) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-UPDATE ]: inserting load balance transaction history ${loadBalanceNumber}...`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-UPDATE ]: inserting load balance transaction history ${loadBalanceNumber}...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
let findDataLoadBalance = await model.findLoadBalance(loadBalanceNumber);
|
let findDataLoadBalance = await model.findLoadBalance(loadBalanceNumber);
|
||||||
let dataLoadBalance = {};
|
let dataLoadBalance = {};
|
||||||
@@ -1827,9 +1920,9 @@ const loadingBalanceUpdate = async (param) => {
|
|||||||
|
|
||||||
if (!write_status) {
|
if (!write_status) {
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING LOADING-BALANCE-UPDATE ]: inserting log for card history...`
|
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-UPDATE ]: inserting log for card history...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// log card history
|
// log card history
|
||||||
await model.createLoadBalanceLog({
|
await model.createLoadBalanceLog({
|
||||||
|
|||||||
@@ -56,6 +56,15 @@ const getIssuer = (id) => {
|
|||||||
return result;
|
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
|
// GET CHECKING CARD PRODUCT FROM GLOBAL PARAMETER
|
||||||
const getCheckByCardProductStatusValue = () => {
|
const getCheckByCardProductStatusValue = () => {
|
||||||
let result = knex('t_m_global_parameter')
|
let result = knex('t_m_global_parameter')
|
||||||
@@ -861,6 +870,7 @@ const getLastHistory = (cardNumber) => {
|
|||||||
.where('c_source', 'CMS')
|
.where('c_source', 'CMS')
|
||||||
.where('c_status', 'S')
|
.where('c_status', 'S')
|
||||||
.orderBy('d_log', 'desc')
|
.orderBy('d_log', 'desc')
|
||||||
|
.orderBy('i_log_card', 'desc')
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
@@ -880,15 +890,31 @@ const insertFraudTransaction = (reservationNumber) => {
|
|||||||
|
|
||||||
let result = knex
|
let result = knex
|
||||||
.into(
|
.into(
|
||||||
knex.raw('?? (??, ??, ??, ??, ??, ??)', [
|
knex.raw(
|
||||||
'trx.t_d_fraud',
|
'?? (??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??)',
|
||||||
'c_card_number',
|
[
|
||||||
'c_reservation_no',
|
'trx.t_d_fraud',
|
||||||
'i_reservation_amount',
|
'c_card_number',
|
||||||
'c_reservation_status',
|
'c_reservation_no',
|
||||||
'c_reservation_flag',
|
'i_reservation_amount',
|
||||||
'c_reservation_ref_no',
|
'c_reservation_status',
|
||||||
])
|
'c_reservation_flag',
|
||||||
|
'c_reservation_ref_no',
|
||||||
|
'd_reservation',
|
||||||
|
'c_reservation_status_name',
|
||||||
|
'i_partner',
|
||||||
|
'c_partner_code',
|
||||||
|
'c_partner_name',
|
||||||
|
'i_merchant',
|
||||||
|
'c_merchant_code',
|
||||||
|
'c_merchant_name',
|
||||||
|
'c_mid',
|
||||||
|
'i_terminal',
|
||||||
|
'c_terminal_code',
|
||||||
|
'c_terminal_name',
|
||||||
|
'c_tid',
|
||||||
|
]
|
||||||
|
)
|
||||||
)
|
)
|
||||||
.insert(function () {
|
.insert(function () {
|
||||||
this.select(
|
this.select(
|
||||||
@@ -897,7 +923,20 @@ const insertFraudTransaction = (reservationNumber) => {
|
|||||||
'i_reservation_amount',
|
'i_reservation_amount',
|
||||||
'c_status',
|
'c_status',
|
||||||
'c_flag',
|
'c_flag',
|
||||||
'c_ref_no'
|
'c_ref_no',
|
||||||
|
'd_reservation',
|
||||||
|
'c_status_name',
|
||||||
|
'i_partner',
|
||||||
|
'c_partner_code',
|
||||||
|
'c_partner_name',
|
||||||
|
'i_merchant',
|
||||||
|
'c_merchant_code',
|
||||||
|
'c_merchant_name',
|
||||||
|
'c_mid',
|
||||||
|
'i_terminal',
|
||||||
|
'c_terminal_code',
|
||||||
|
'c_terminal_name',
|
||||||
|
'c_tid'
|
||||||
)
|
)
|
||||||
.from('trx.t_d_reservation_balance')
|
.from('trx.t_d_reservation_balance')
|
||||||
.whereIn(
|
.whereIn(
|
||||||
@@ -1047,6 +1086,7 @@ module.exports = {
|
|||||||
checkCardNumber,
|
checkCardNumber,
|
||||||
getPartner,
|
getPartner,
|
||||||
getIssuer,
|
getIssuer,
|
||||||
|
getCardBlacklist,
|
||||||
getCheckByCardProductStatusValue,
|
getCheckByCardProductStatusValue,
|
||||||
getReservationPending,
|
getReservationPending,
|
||||||
getReservationPendingWithFlagCounter,
|
getReservationPendingWithFlagCounter,
|
||||||
|
|||||||
@@ -115,9 +115,9 @@ const paymentRecon = async (req, res) => {
|
|||||||
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING PAYMENT-RECON ]: checking partner...`
|
// `${uniqueCode} [ PROCESSING PAYMENT-RECON ]: checking partner...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// get partner, merchant, terminal from tid
|
// get partner, merchant, terminal from tid
|
||||||
let getPartner = await model.getPartnerByID(partner_id);
|
let getPartner = await model.getPartnerByID(partner_id);
|
||||||
@@ -136,6 +136,58 @@ const paymentRecon = async (req, res) => {
|
|||||||
return res.status(200).json(result);
|
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
|
// check reservation number yang di request sudah berhasil di recon atau belum sebelumnnya
|
||||||
let checkReservationNumberAndAmountAlreadyRecon =
|
let checkReservationNumberAndAmountAlreadyRecon =
|
||||||
await model.checkReservationNumberAndAmountAlreadyRecon(
|
await model.checkReservationNumberAndAmountAlreadyRecon(
|
||||||
@@ -167,9 +219,9 @@ const paymentRecon = async (req, res) => {
|
|||||||
let PaymentReconNumber;
|
let PaymentReconNumber;
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING PAYMENT-RECON ]: generating payment recon number...`
|
// `${uniqueCode} [ PROCESSING PAYMENT-RECON ]: generating payment recon number...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// loop 1
|
// loop 1
|
||||||
await _sleep(helper.randomNumberInt());
|
await _sleep(helper.randomNumberInt());
|
||||||
@@ -221,9 +273,9 @@ const paymentRecon = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING PAYMENT-RECON ]: checking reservation status has been cancelled or not...`
|
// `${uniqueCode} [ PROCESSING PAYMENT-RECON ]: checking reservation status has been cancelled or not...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// check reservation number yang di request apakah masih aktif atau sudah di cancel
|
// check reservation number yang di request apakah masih aktif atau sudah di cancel
|
||||||
let checkReservationCanceledStatus =
|
let checkReservationCanceledStatus =
|
||||||
@@ -241,9 +293,9 @@ const paymentRecon = async (req, res) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING PAYMENT-RECON ]: inserting payment recon transaction...`
|
// `${uniqueCode} [ PROCESSING PAYMENT-RECON ]: inserting payment recon transaction...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// insert payment recon transaction
|
// insert payment recon transaction
|
||||||
await model.insertPaymentReconTransaction(
|
await model.insertPaymentReconTransaction(
|
||||||
@@ -270,9 +322,9 @@ const paymentRecon = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING PAYMENT-RECON ]: checking reservation number in CMS...`
|
// `${uniqueCode} [ PROCESSING PAYMENT-RECON ]: checking reservation number in CMS...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// cek reservation number tercatat di sistem CMS atau tidak
|
// cek reservation number tercatat di sistem CMS atau tidak
|
||||||
let check = await model.checkReservationNumberAndAmount(reservation_number);
|
let check = await model.checkReservationNumberAndAmount(reservation_number);
|
||||||
@@ -289,9 +341,9 @@ const paymentRecon = async (req, res) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING PAYMENT-RECON ]: inserting payment recon transaction...`
|
// `${uniqueCode} [ PROCESSING PAYMENT-RECON ]: inserting payment recon transaction...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// insert payment recon transaction
|
// insert payment recon transaction
|
||||||
await model.insertPaymentReconTransaction(
|
await model.insertPaymentReconTransaction(
|
||||||
@@ -331,9 +383,9 @@ const paymentRecon = async (req, res) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING PAYMENT-RECON ]: inserting payment recon transaction...`
|
// `${uniqueCode} [ PROCESSING PAYMENT-RECON ]: inserting payment recon transaction...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// insert payment recon transaction
|
// insert payment recon transaction
|
||||||
await model.insertPaymentReconTransaction(
|
await model.insertPaymentReconTransaction(
|
||||||
@@ -373,9 +425,9 @@ const paymentRecon = async (req, res) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING PAYMENT-RECON ]: inserting payment recon transaction...`
|
// `${uniqueCode} [ PROCESSING PAYMENT-RECON ]: inserting payment recon transaction...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// insert payment recon transaction
|
// insert payment recon transaction
|
||||||
await model.insertPaymentReconTransaction(
|
await model.insertPaymentReconTransaction(
|
||||||
@@ -409,9 +461,9 @@ const paymentRecon = async (req, res) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING PAYMENT-RECON ]: updating payment recon number...`
|
// `${uniqueCode} [ PROCESSING PAYMENT-RECON ]: updating payment recon number...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
let update = await model.updatePaymentReconNo(data);
|
let update = await model.updatePaymentReconNo(data);
|
||||||
if (!update) {
|
if (!update) {
|
||||||
@@ -434,9 +486,9 @@ const paymentRecon = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
// winston.logger.debug(
|
||||||
`${uniqueCode} [ PROCESSING PAYMENT-RECON ]: inserting payment recon transaction...`
|
// `${uniqueCode} [ PROCESSING PAYMENT-RECON ]: inserting payment recon transaction...`
|
||||||
);
|
// );
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
code: '00',
|
code: '00',
|
||||||
|
|||||||
@@ -1,33 +1,34 @@
|
|||||||
const knex = require("../../../infrastructure/database/knex");
|
const knex = require('../../../infrastructure/database/knex');
|
||||||
|
|
||||||
// GET PARTNER, MERCHANT, TERMINAL FROM TID
|
// GET PARTNER, MERCHANT, TERMINAL FROM TID
|
||||||
const getPartner = (mid, tid) => {
|
const getPartner = (mid, tid) => {
|
||||||
let result = knex
|
let result = knex
|
||||||
.select(
|
.select(
|
||||||
"t_m_partner.i_partner",
|
't_m_partner.i_partner',
|
||||||
"t_m_partner.c_code as partner_code",
|
't_m_partner.c_code as partner_code',
|
||||||
"t_m_partner.c_name as partner_name",
|
't_m_partner.c_name as partner_name',
|
||||||
"t_m_merchant.i_merchant",
|
't_m_partner.b_payment_recon',
|
||||||
"t_m_merchant.c_code as merchant_code",
|
't_m_merchant.i_merchant',
|
||||||
"t_m_merchant.c_name as merchant_name",
|
't_m_merchant.c_code as merchant_code',
|
||||||
"t_m_merchant.e_mid as mid",
|
't_m_merchant.c_name as merchant_name',
|
||||||
"t_m_terminal.i_terminal",
|
't_m_merchant.e_mid as mid',
|
||||||
"t_m_terminal.c_code as terminal_code",
|
't_m_terminal.i_terminal',
|
||||||
"t_m_terminal.c_name as terminal_name",
|
't_m_terminal.c_code as terminal_code',
|
||||||
"t_m_terminal.e_tid as tid"
|
't_m_terminal.c_name as terminal_name',
|
||||||
|
't_m_terminal.e_tid as tid'
|
||||||
)
|
)
|
||||||
.from("t_m_terminal")
|
.from('t_m_terminal')
|
||||||
.leftJoin(
|
.leftJoin(
|
||||||
"t_m_merchant",
|
't_m_merchant',
|
||||||
"t_m_terminal.i_merchant",
|
't_m_terminal.i_merchant',
|
||||||
"t_m_merchant.i_merchant"
|
't_m_merchant.i_merchant'
|
||||||
)
|
)
|
||||||
.leftJoin("t_m_partner", "t_m_merchant.i_partner", "t_m_partner.i_partner")
|
.leftJoin('t_m_partner', 't_m_merchant.i_partner', 't_m_partner.i_partner')
|
||||||
.where("t_m_merchant.e_mid", mid)
|
.where('t_m_merchant.e_mid', mid)
|
||||||
.where("t_m_terminal.e_tid", tid)
|
.where('t_m_terminal.e_tid', tid)
|
||||||
.where("t_m_terminal.c_status", "A")
|
.where('t_m_terminal.c_status', 'A')
|
||||||
.where("t_m_merchant.c_status", "A")
|
.where('t_m_merchant.c_status', 'A')
|
||||||
.where("t_m_partner.c_status", "A")
|
.where('t_m_partner.c_status', 'A')
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
@@ -35,57 +36,66 @@ const getPartner = (mid, tid) => {
|
|||||||
const getPartnerByID = (partner_id) => {
|
const getPartnerByID = (partner_id) => {
|
||||||
let result = knex
|
let result = knex
|
||||||
.select(
|
.select(
|
||||||
"t_m_partner.i_partner",
|
't_m_partner.i_partner',
|
||||||
"t_m_partner.c_code as partner_code",
|
't_m_partner.c_code as partner_code',
|
||||||
"t_m_partner.c_name as partner_name"
|
't_m_partner.c_name as partner_name',
|
||||||
|
't_m_partner.b_payment_recon'
|
||||||
)
|
)
|
||||||
.from("t_m_partner")
|
.from('t_m_partner')
|
||||||
.where("t_m_partner.i_partner", partner_id)
|
.where('t_m_partner.i_partner', partner_id)
|
||||||
.where("t_m_partner.c_status", "A")
|
.where('t_m_partner.c_status', 'A')
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkReservationNumberAndAmount = (reservationNumber) => {
|
const checkReservationNumberAndAmount = (reservationNumber) => {
|
||||||
let result = knex("trx.t_d_reservation_balance")
|
let result = knex('trx.t_d_reservation_balance')
|
||||||
.count("* as total_transaction")
|
.count('* as total_transaction')
|
||||||
.sum("i_reservation_amount as total_amount")
|
.sum('i_reservation_amount as total_amount')
|
||||||
.groupBy("c_ref_no")
|
.groupBy('c_ref_no')
|
||||||
.where("c_reservation_no", reservationNumber)
|
.where('c_reservation_no', reservationNumber)
|
||||||
// .where("c_status", "A")
|
// .where("c_status", "A")
|
||||||
.whereNull("c_payment_recon_no")
|
.whereNull('c_payment_recon_no')
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkReservationCanceledStatus = (reservationNumber) => {
|
const checkReservationCanceledStatus = (reservationNumber) => {
|
||||||
let result = knex("trx.t_d_reservation_balance")
|
let result = knex('trx.t_d_reservation_balance')
|
||||||
.where("c_reservation_no", reservationNumber)
|
.where('c_reservation_no', reservationNumber)
|
||||||
.where("c_status", "X")
|
.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();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkReservationNumberAndAmountAlreadyRecon = (reservationNumber) => {
|
const checkReservationNumberAndAmountAlreadyRecon = (reservationNumber) => {
|
||||||
let result = knex("trx.t_d_reservation_balance")
|
let result = knex('trx.t_d_reservation_balance')
|
||||||
.select("c_payment_recon_no", "d_payment_recon")
|
.select('c_payment_recon_no', 'd_payment_recon')
|
||||||
.where("c_reservation_no", reservationNumber)
|
.where('c_reservation_no', reservationNumber)
|
||||||
// .where("c_status", "A")
|
// .where("c_status", "A")
|
||||||
.whereNotNull("c_payment_recon_no")
|
.whereNotNull('c_payment_recon_no')
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// UPDATE PAYMENT RECON
|
// UPDATE PAYMENT RECON
|
||||||
const updatePaymentReconNo = (data) => {
|
const updatePaymentReconNo = (data) => {
|
||||||
let result = knex("trx.t_d_reservation_balance")
|
let result = knex('trx.t_d_reservation_balance')
|
||||||
.update({
|
.update({
|
||||||
c_payment_recon_no: data.payment_recon_no,
|
c_payment_recon_no: data.payment_recon_no,
|
||||||
d_payment: data.date,
|
d_payment: data.date,
|
||||||
d_payment_recon: data.time,
|
d_payment_recon: data.time,
|
||||||
})
|
})
|
||||||
.whereNull("c_payment_recon_no")
|
.whereNull('c_payment_recon_no')
|
||||||
.where("c_reservation_no", data.reservation_number);
|
.where('c_reservation_no', data.reservation_number);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -104,7 +114,7 @@ const insertPaymentReconTransaction = (
|
|||||||
responseMessage,
|
responseMessage,
|
||||||
responseData
|
responseData
|
||||||
) => {
|
) => {
|
||||||
let result = knex("payment.t_d_payment_recon").insert({
|
let result = knex('payment.t_d_payment_recon').insert({
|
||||||
d_payment: date,
|
d_payment: date,
|
||||||
d_payment_recon: now,
|
d_payment_recon: now,
|
||||||
c_partner_code: partnerCode,
|
c_partner_code: partnerCode,
|
||||||
@@ -123,34 +133,34 @@ const insertPaymentReconTransaction = (
|
|||||||
|
|
||||||
// INSERT TEMP PAYMENT RECON NUMBER
|
// INSERT TEMP PAYMENT RECON NUMBER
|
||||||
const insertPaymentReconNumber = (paymentReconNumber) => {
|
const insertPaymentReconNumber = (paymentReconNumber) => {
|
||||||
let result = knex("payment.t_d_payment_recon_no_validate")
|
let result = knex('payment.t_d_payment_recon_no_validate')
|
||||||
.insert({
|
.insert({
|
||||||
c_payment_recon_no: paymentReconNumber,
|
c_payment_recon_no: paymentReconNumber,
|
||||||
})
|
})
|
||||||
.onConflict("c_payment_recon_no")
|
.onConflict('c_payment_recon_no')
|
||||||
.ignore();
|
.ignore();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// GET LAST COUNTER PAYMENT RECON NO
|
// GET LAST COUNTER PAYMENT RECON NO
|
||||||
const getLastCounterPaymentReconNo = (partnerCode, reconDate) => {
|
const getLastCounterPaymentReconNo = (partnerCode, reconDate) => {
|
||||||
let result = knex("payment.t_d_payment_recon")
|
let result = knex('payment.t_d_payment_recon')
|
||||||
.select("c_payment_recon_no", "d_payment_recon")
|
.select('c_payment_recon_no', 'd_payment_recon')
|
||||||
.whereRaw("??::date = ?", ["d_payment_recon", reconDate])
|
.whereRaw('??::date = ?', ['d_payment_recon', reconDate])
|
||||||
.where("c_partner_code", partnerCode)
|
.where('c_partner_code', partnerCode)
|
||||||
// .orderBy("d_payment_recon", "desc")
|
// .orderBy("d_payment_recon", "desc")
|
||||||
.orderBy("c_payment_recon_no", "desc")
|
.orderBy('c_payment_recon_no', 'desc')
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getReservationToRecon = (date) => {
|
const getReservationToRecon = (date) => {
|
||||||
let result = knex("trx.t_d_reservation_balance")
|
let result = knex('trx.t_d_reservation_balance')
|
||||||
.select("c_reservation_no", "i_reservation_amount")
|
.select('c_reservation_no', 'i_reservation_amount')
|
||||||
.whereNull("d_cancel")
|
.whereNull('d_cancel')
|
||||||
.whereNull("c_payment_recon_no")
|
.whereNull('c_payment_recon_no')
|
||||||
.whereRaw("??::date = ?", ["d_reservation", date])
|
.whereRaw('??::date = ?', ['d_reservation', date])
|
||||||
.orderBy("c_reservation_no", "asc");
|
.orderBy('c_reservation_no', 'asc');
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -159,6 +169,7 @@ module.exports = {
|
|||||||
getPartnerByID,
|
getPartnerByID,
|
||||||
checkReservationNumberAndAmount,
|
checkReservationNumberAndAmount,
|
||||||
checkReservationCanceledStatus,
|
checkReservationCanceledStatus,
|
||||||
|
checkReservation,
|
||||||
checkReservationNumberAndAmountAlreadyRecon,
|
checkReservationNumberAndAmountAlreadyRecon,
|
||||||
updatePaymentReconNo,
|
updatePaymentReconNo,
|
||||||
insertPaymentReconTransaction,
|
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,214 @@
|
|||||||
|
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.toLowerCase();
|
||||||
|
// 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 unixTimeZero = Date.parse(last_updated_date);
|
||||||
|
const date_reimbursement = moment(unixTimeZero).format(
|
||||||
|
'YYYY-MM-DD HH:mm:ss'
|
||||||
|
);
|
||||||
|
|
||||||
|
//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,48 @@
|
|||||||
|
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"
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
checkRedeem,
|
||||||
|
updateReplacementComplete
|
||||||
|
};
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -72,6 +72,15 @@ const getIssuer = (id, time) => {
|
|||||||
return result;
|
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
|
// GET RESERVATION EXPIRATION DATE FROM GLOBAL PARAMETER
|
||||||
const getReservationExpirationDateValue = () => {
|
const getReservationExpirationDateValue = () => {
|
||||||
let result = knex('t_m_global_parameter')
|
let result = knex('t_m_global_parameter')
|
||||||
@@ -540,6 +549,7 @@ module.exports = {
|
|||||||
getReservationNumberSequence,
|
getReservationNumberSequence,
|
||||||
getPartner,
|
getPartner,
|
||||||
getIssuer,
|
getIssuer,
|
||||||
|
getCardBlacklist,
|
||||||
getReservationExpirationDateValue,
|
getReservationExpirationDateValue,
|
||||||
getReservationExpirationDateMeasure,
|
getReservationExpirationDateMeasure,
|
||||||
getCheckByCardProductStatusValue,
|
getCheckByCardProductStatusValue,
|
||||||
|
|||||||
@@ -10,6 +10,13 @@ router.get(
|
|||||||
controller.apiGenerateCahsIn
|
controller.apiGenerateCahsIn
|
||||||
);
|
);
|
||||||
|
|
||||||
|
router.get(
|
||||||
|
"/online/cash-in-sales",
|
||||||
|
// auth.authenticateToken,
|
||||||
|
// controller.validate("generateInvoice"),
|
||||||
|
controller.apiGenerateCashInSales
|
||||||
|
);
|
||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
"/online/cash-in/posting",
|
"/online/cash-in/posting",
|
||||||
// auth.authenticateToken,
|
// auth.authenticateToken,
|
||||||
|
|||||||
@@ -1,43 +1,82 @@
|
|||||||
const { Router } = require("express");
|
const { Router } = require('express');
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
const auth = require("../middlewares/jwt.middleware");
|
const auth = require('../middlewares/jwt.middleware');
|
||||||
const _readData = require("../modules/hsm/readData");
|
|
||||||
const _readDataResp = require("../modules/hsm/readDataResp");
|
|
||||||
|
|
||||||
const _auth1 = require("../modules/hsm/authenticate1");
|
// Topup
|
||||||
const _auth2 = require("../modules/hsm/authenticate2");
|
const _auth1 = require('../modules/hsm/topup/topup_1');
|
||||||
const _authResp = require("../modules/hsm/authenticateResp");
|
const _auth2 = require('../modules/hsm/topup/topup_2');
|
||||||
|
const _authResp = require('../modules/hsm/topup/topup_3');
|
||||||
|
|
||||||
const _topup = require("../modules/hsm/topup");
|
const _readData = require('../modules/hsm/topup/topup_4');
|
||||||
const _topupResp = require("../modules/hsm/topupResp");
|
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('/topup1', auth.authenticateToken, _auth1);
|
||||||
router.post("/topup2", auth.authenticateToken, _auth2);
|
router.post('/topup2', auth.authenticateToken, _auth2);
|
||||||
router.post("/topup3", auth.authenticateToken, _authResp);
|
router.post('/topup3', auth.authenticateToken, _authResp);
|
||||||
router.post("/topup4", auth.authenticateToken, _readData);
|
router.post('/topup4', auth.authenticateToken, _readData);
|
||||||
router.post("/topup5", auth.authenticateToken, _readDataResp);
|
router.post('/topup5', auth.authenticateToken, _readDataResp);
|
||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
"/topup6",
|
'/topup6',
|
||||||
auth.authenticateToken,
|
auth.authenticateToken,
|
||||||
_topup.validate("topup"),
|
_topup.validate('topup'),
|
||||||
_topup.controller
|
_topup.controller
|
||||||
);
|
);
|
||||||
router.post(
|
router.post(
|
||||||
"/topup7",
|
'/topup7',
|
||||||
auth.authenticateToken,
|
auth.authenticateToken,
|
||||||
_topupResp.validate("topupResponse"),
|
_topupResp.validate('topupResponse'),
|
||||||
_topupResp.controller
|
_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;
|
module.exports = router;
|
||||||
|
|||||||
@@ -2,10 +2,14 @@ const express = require('express');
|
|||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const auth = require('../middlewares/jwt.middleware');
|
const auth = require('../middlewares/jwt.middleware');
|
||||||
const controller = require('../modules/loadbalance/loadbalance.controller');
|
const controller = require('../modules/loadbalance/loadbalance.controller');
|
||||||
|
const {
|
||||||
|
getLoadBalanceNumberSequence,
|
||||||
|
} = require('../middlewares/redis.middleware');
|
||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
'/loadbalance/request',
|
'/loadbalance/request',
|
||||||
auth.authenticateToken,
|
auth.authenticateToken,
|
||||||
|
getLoadBalanceNumberSequence,
|
||||||
controller.validate('loadingBalanceRequest'),
|
controller.validate('loadingBalanceRequest'),
|
||||||
controller.loadingBalanceRequest
|
controller.loadingBalanceRequest
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -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
|
controller.getFeeSharing
|
||||||
);
|
);
|
||||||
|
|
||||||
|
router.post(
|
||||||
|
'/reservation/decrypt',
|
||||||
|
auth.authenticateToken,
|
||||||
|
controller.decrpytRequest
|
||||||
|
);
|
||||||
|
|
||||||
// router.post(
|
// router.post(
|
||||||
// '/reservation/cancel/v2.1',
|
// '/reservation/cancel/v2.1',
|
||||||
// auth.authenticateToken,
|
// auth.authenticateToken,
|
||||||
|
|||||||
@@ -1,8 +1,22 @@
|
|||||||
# ================================= ENVIRONMENT =================================
|
# ================================= ENVIRONMENT =================================
|
||||||
#NODE_ENV=production
|
#NODE_ENV=production
|
||||||
NODE_ENV=development
|
NODE_ENV=development
|
||||||
|
CUSTOM_MODE_NODE_ENV=devprod
|
||||||
#NODE_ENV=testing
|
#NODE_ENV=testing
|
||||||
PORT=3000
|
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 ===========================
|
# =========================== KONFIGURASI UNTUK SERVER ===========================
|
||||||
# SERVER_FOR=development
|
# SERVER_FOR=development
|
||||||
@@ -31,7 +45,10 @@ DB_PASSWORD_POOLING=inhc0mmute_cms
|
|||||||
# ==================================== LOKI =====================================
|
# ==================================== LOKI =====================================
|
||||||
LOKI_URL=http://10.20.14.30:3100
|
LOKI_URL=http://10.20.14.30:3100
|
||||||
|
|
||||||
# ==================================== APP PROMETHEUS =====================================
|
# ==================================== LOKI =====================================
|
||||||
|
LOKI_URL=http://localhost:3100
|
||||||
|
|
||||||
|
# =============================== APP PROMETHEUS =================================
|
||||||
PROM_APP = topuponline
|
PROM_APP = topuponline
|
||||||
|
|
||||||
# ================================== SECRET KEY ==================================
|
# ================================== SECRET KEY ==================================
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
|
// var http = require('http');
|
||||||
const cluster = require('node:cluster');
|
const cluster = require('node:cluster');
|
||||||
const totalCPUs = require('node:os').cpus().length;
|
const totalCPUs = require('node:os').cpus().length;
|
||||||
const process = require('node:process');
|
const process = require('node:process');
|
||||||
const winston = require('./application/helpers/winston.logger');
|
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';
|
var serverHSMStatus = 'HSM SERVER NOT CONNECTED';
|
||||||
if (process.env.NUMBER_SERVER_ACTIVE == '1') {
|
if (process.env.NUMBER_SERVER_ACTIVE == '1') {
|
||||||
serverHSMStatus = `SERVER 1 CONNECTED on ip ${process.env.IP_HSM_SERVER_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) {
|
// jika mau di cluster gunakan script berikut:
|
||||||
console.log(`Number of CPUs is ${totalCPUs}`);
|
if (process.env.CLUSTER_NODE.toUpperCase() == 'YES') {
|
||||||
console.log(`Master ${process.pid} is running`);
|
if (cluster.isMaster) {
|
||||||
|
console.log(`Number of CPUs is ${totalCPUs}`);
|
||||||
|
console.log(`Master ${process.pid} is running`);
|
||||||
|
|
||||||
// Fork workers.
|
// Fork workers.
|
||||||
for (let i = 0; i < totalCPUs; i++) {
|
for (let i = 0; i < totalCPUs; i++) {
|
||||||
cluster.fork();
|
cluster.fork();
|
||||||
|
}
|
||||||
|
|
||||||
|
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}`);
|
||||||
|
} else {
|
||||||
|
startExpress();
|
||||||
}
|
}
|
||||||
|
|
||||||
cluster.on('exit', (worker, code, signal) => {
|
|
||||||
console.log(`worker ${worker.process.pid} died`);
|
|
||||||
console.log("Let's fork another worker!");
|
|
||||||
cluster.fork();
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
|
// jika tidak mau di cluster langsung call function startExpress
|
||||||
startExpress();
|
startExpress();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`worker pid=${process.pid}`);
|
|
||||||
|
|
||||||
function startExpress() {
|
function startExpress() {
|
||||||
server.listen(PORT, () => {
|
// set port, listen for requests
|
||||||
winston.logger.info(
|
const PORT = process.env.PORT || 3000;
|
||||||
`Server is running on version ${
|
|
||||||
process.env.VERSION
|
// jika settingan running on multiple
|
||||||
} environment: ${process.env.NODE_ENV.toUpperCase()} port: ${PORT} on ${serverActive}. HSM STATUS : ${serverHSMStatus} `
|
if (
|
||||||
|
process.env.RUNNING_ON_MULTIPLE_PORT.toUpperCase() == 'YES' &&
|
||||||
|
process.env.CLUSTER_NODE.toUpperCase() == 'NO'
|
||||||
|
) {
|
||||||
|
const PORTS = process.env.PORTS;
|
||||||
|
|
||||||
|
if (!PORTS) {
|
||||||
|
winston.logger.warn(
|
||||||
|
`Running on multiple port is active but the ports not yet set in .env`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
let ports = PORTS.split(',');
|
||||||
|
|
||||||
|
for (let index = 0; index < ports.length; index++) {
|
||||||
|
const port = ports[index];
|
||||||
|
|
||||||
|
app.listen(port, () => {
|
||||||
|
winston.logger.info(
|
||||||
|
`Server is running on version ${
|
||||||
|
process.env.VERSION
|
||||||
|
} environment: ${process.env.NODE_ENV.toUpperCase()} port: ${port} on ${serverActive}. HSM STATUS : ${serverHSMStatus} `
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (
|
||||||
|
process.env.RUNNING_ON_MULTIPLE_PORT.toUpperCase() == 'YES' &&
|
||||||
|
process.env.CLUSTER_NODE.toUpperCase() == 'YES'
|
||||||
|
) {
|
||||||
|
winston.logger.warn(
|
||||||
|
`If you want running the service on multiple port, please set CLUSTER_NODE = NO in .env file `
|
||||||
);
|
);
|
||||||
});
|
} else if (
|
||||||
|
process.env.CLUSTER_NODE_STICKY_SESSION.toUpperCase() == 'YES' &&
|
||||||
|
process.env.CLUSTER_NODE.toUpperCase() == 'YES'
|
||||||
|
) {
|
||||||
|
winston.logger.warn(
|
||||||
|
`If you want running the service with sticky session, please set CLUSTER_NODE = NO in .env file `
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let message = `Server is running on version ${
|
||||||
|
process.env.VERSION
|
||||||
|
} environment: ${process.env.NODE_ENV.toUpperCase()} port: ${PORT} on ${serverActive}. HSM STATUS : ${serverHSMStatus} `;
|
||||||
|
|
||||||
|
if (process.env.CLUSTER_NODE.toUpperCase() == 'YES') {
|
||||||
|
message = `Server is running with cluster node on version ${
|
||||||
|
process.env.VERSION
|
||||||
|
} environment: ${process.env.NODE_ENV.toUpperCase()} port: ${PORT} on ${serverActive}. HSM STATUS : ${serverHSMStatus} `;
|
||||||
|
} else if (process.env.CLUSTER_NODE_STICKY_SESSION.toUpperCase() == 'YES') {
|
||||||
|
message = `Server is running with sticky session on version ${
|
||||||
|
process.env.VERSION
|
||||||
|
} environment: ${process.env.NODE_ENV.toUpperCase()} port: ${PORT} on ${serverActive}. HSM STATUS : ${serverHSMStatus} `;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.env.CLUSTER_NODE_STICKY_SESSION.toUpperCase() == 'YES') {
|
||||||
|
const server = app.listen(PORT, () => {
|
||||||
|
console.log(
|
||||||
|
`Worker ${process.pid} started. Listening on port ${
|
||||||
|
server.address().port
|
||||||
|
}`
|
||||||
|
);
|
||||||
|
winston.logger.info(message);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Use sticky-session with the server instance
|
||||||
|
sticky.listen(server);
|
||||||
|
} else {
|
||||||
|
app.listen(PORT, () => {
|
||||||
|
winston.logger.info(message);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use sticky-session to handle sticky sessions
|
||||||
|
// if (!sticky.listen(cluster, port)) {
|
||||||
|
// // This is the master process, and it should not be listening to the port
|
||||||
|
// cluster.on('listening', (worker, address) => {
|
||||||
|
// console.log(
|
||||||
|
// `Worker ${worker.id} is now connected to ${address.address}:${address.port}`
|
||||||
|
// );
|
||||||
|
// });
|
||||||
|
|
||||||
|
// cluster.on('exit', (worker) => {
|
||||||
|
// console.log(`Worker ${worker.id} has exited`);
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|||||||
+42
-18
@@ -6,24 +6,48 @@ let port;
|
|||||||
let user;
|
let user;
|
||||||
let password;
|
let password;
|
||||||
|
|
||||||
if (process.env.SERVER_FOR == 'local') {
|
if (process.env.CUSTOM_MODE_NODE_ENV == 'devprod') {
|
||||||
host = process.env.DB_HOST_LOCAL;
|
// blok ini hanya digunakan untuk kebutuhan testing
|
||||||
database = process.env.DB_NAME_LOCAL;
|
if (process.env.SERVER_FOR == 'local') {
|
||||||
port = process.env.DB_PORT_LOCAL;
|
host = process.env.DB_HOST_LOCAL;
|
||||||
user = process.env.DB_USER_LOCAL;
|
database = process.env.DB_NAME_LOCAL;
|
||||||
password = process.env.DB_PASSWORD_LOCAL;
|
port = process.env.DB_PORT_LOCAL;
|
||||||
} else if (process.env.SERVER_FOR == 'development') {
|
user = process.env.DB_USER_LOCAL;
|
||||||
host = '10.20.14.14';
|
password = process.env.DB_PASSWORD_LOCAL;
|
||||||
database = 'postgres';
|
} else if (process.env.SERVER_FOR == 'development') {
|
||||||
port = 5432;
|
host = '10.20.14.14';
|
||||||
user = 'postgres';
|
database = 'postgres';
|
||||||
password = 'inhc0mmute_cms';
|
port = 5432;
|
||||||
} else if (process.env.SERVER_FOR == 'production') {
|
user = 'postgres';
|
||||||
host = '10.1.201.75';
|
password = 'inhc0mmute_cms';
|
||||||
database = 'postgres';
|
} else if (process.env.SERVER_FOR == 'production') {
|
||||||
port = 5432;
|
host = '10.20.14.14';
|
||||||
user = 'postgres';
|
database = 'postgres';
|
||||||
password = 'inhc0mmute_cms';
|
port = 5432;
|
||||||
|
user = 'postgres';
|
||||||
|
password = 'inhc0mmute_cms';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// setting an normal harusnya masuk blok ini
|
||||||
|
if (process.env.SERVER_FOR == 'local') {
|
||||||
|
host = process.env.DB_HOST_LOCAL;
|
||||||
|
database = process.env.DB_NAME_LOCAL;
|
||||||
|
port = process.env.DB_PORT_LOCAL;
|
||||||
|
user = process.env.DB_USER_LOCAL;
|
||||||
|
password = process.env.DB_PASSWORD_LOCAL;
|
||||||
|
} else if (process.env.SERVER_FOR == 'development') {
|
||||||
|
host = '10.20.14.14';
|
||||||
|
database = 'postgres';
|
||||||
|
port = 5432;
|
||||||
|
user = 'postgres';
|
||||||
|
password = 'inhc0mmute_cms';
|
||||||
|
} else if (process.env.SERVER_FOR == 'production') {
|
||||||
|
host = '10.1.201.75';
|
||||||
|
database = 'postgres';
|
||||||
|
port = 5432;
|
||||||
|
user = 'postgres';
|
||||||
|
password = 'inhc0mmute_cms';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
Generated
+1528
-1568
File diff suppressed because it is too large
Load Diff
+5
-4
@@ -22,7 +22,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/mohamadihsan/topuponline#readme",
|
"homepage": "https://github.com/mohamadihsan/topuponline#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.27.2",
|
"axios": "^1.7.7",
|
||||||
"bcrypt": "^5.0.1",
|
"bcrypt": "^5.0.1",
|
||||||
"body-parser": "^1.19.0",
|
"body-parser": "^1.19.0",
|
||||||
"check-internet-connected": "^2.0.6",
|
"check-internet-connected": "^2.0.6",
|
||||||
@@ -32,8 +32,8 @@
|
|||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"express-validator": "^6.10.0",
|
"express-validator": "^6.10.0",
|
||||||
"express-winston": "^4.2.0",
|
"express-winston": "^4.2.0",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^9.0.2",
|
||||||
"knex": "^0.95.4",
|
"knex": "^3.1.0",
|
||||||
"moment": "^2.29.3",
|
"moment": "^2.29.3",
|
||||||
"node-cron": "^3.0.1",
|
"node-cron": "^3.0.1",
|
||||||
"pg": "^8.6.0",
|
"pg": "^8.6.0",
|
||||||
@@ -41,11 +41,12 @@
|
|||||||
"prom-client": "^14.2.0",
|
"prom-client": "^14.2.0",
|
||||||
"redis": "^4.6.5",
|
"redis": "^4.6.5",
|
||||||
"response-time": "^2.3.2",
|
"response-time": "^2.3.2",
|
||||||
|
"sticky-session": "^0.1.0",
|
||||||
"winston": "^3.7.2",
|
"winston": "^3.7.2",
|
||||||
"winston-daily-rotate-file": "^4.7.1",
|
"winston-daily-rotate-file": "^4.7.1",
|
||||||
"winston-loki": "^6.0.6",
|
"winston-loki": "^6.0.6",
|
||||||
"ws": "^8.5.0",
|
"ws": "^8.5.0",
|
||||||
"xml2js": "^0.4.23"
|
"xml2js": "^0.6.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"jest": "^29.0.2",
|
"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 paymentReconRoute = require('../application/routes/paymentrecon.routes');
|
||||||
const invoiceRoute = require('../application/routes/invoiceonline.routes');
|
const invoiceRoute = require('../application/routes/invoiceonline.routes');
|
||||||
const cashinRoute = require('../application/routes/cahsin.routes');
|
const cashinRoute = require('../application/routes/cahsin.routes');
|
||||||
|
const posRoute = require('../application/routes/pos.routes');
|
||||||
const pooling = require('../application/routes/pooling.routes');
|
const pooling = require('../application/routes/pooling.routes');
|
||||||
|
const refundkmtRoute = require('../application/routes/refundkmt.routes');
|
||||||
const cron = require('node-cron');
|
const cron = require('node-cron');
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
@@ -51,6 +53,9 @@ var corsOptions = {
|
|||||||
// app.use(cors(corsOptions));
|
// app.use(cors(corsOptions));
|
||||||
app.use(cors(corsOptions));
|
app.use(cors(corsOptions));
|
||||||
|
|
||||||
|
// add static file
|
||||||
|
app.use(express.static('public'));
|
||||||
|
|
||||||
// parse requests of content-type - application/json
|
// parse requests of content-type - application/json
|
||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
|
|
||||||
@@ -79,7 +84,9 @@ app.use('/api/', paymentReconRoute);
|
|||||||
app.use('/api/', reservationRoute);
|
app.use('/api/', reservationRoute);
|
||||||
app.use('/api/', invoiceRoute);
|
app.use('/api/', invoiceRoute);
|
||||||
app.use('/api/', cashinRoute);
|
app.use('/api/', cashinRoute);
|
||||||
|
app.use('/api/', posRoute);
|
||||||
app.use('/api/', pooling);
|
app.use('/api/', pooling);
|
||||||
|
app.use('/api/', refundkmtRoute);
|
||||||
|
|
||||||
// ============================== SAP SCHEDULLER =============================
|
// ============================== SAP SCHEDULLER =============================
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user