mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-06 11:56:27 +00:00
Compare commits
337 Commits
develop_v1.4.3
...
teddy
| Author | SHA1 | Date | |
|---|---|---|---|
| 4140360736 | |||
| f4fc8cd147 | |||
| f5f75381ca | |||
| 5cbdccca11 | |||
| fd386788f8 | |||
| 6ddf225485 | |||
| 1645aa54aa | |||
| 797bf97bf8 | |||
| a7f5c8c8e0 | |||
| d2d44f3ba9 | |||
| 4dccbf20f5 | |||
| b888951ee3 | |||
| 87dedd241a | |||
| d4f56aacd8 | |||
| fec5209c83 | |||
| 93b6bd94ca | |||
| 39ac9e0e2d | |||
| 5037e022fd | |||
| cbb1d353a3 | |||
| f73accc275 | |||
| d7c62eda3f | |||
| a4b089ac85 | |||
| 3bf01d9059 | |||
| 8e54ebb704 | |||
| 48fb780252 | |||
| 382ccaab58 | |||
| 41444e037c | |||
| c49e4b3526 | |||
| d99882b8b9 | |||
| 45091038fe | |||
| 7c6e08a5b5 | |||
| 6e7d727b40 | |||
| 3bb2748387 | |||
| 6fea76b721 | |||
| 934e962dba | |||
| 3ccac7d220 | |||
| cede2396b7 | |||
| 9c06ec992e | |||
| 419700d6c5 | |||
| 6af2637bca | |||
| 8bb705f973 | |||
| 6755824ad0 | |||
| d93e3549ea | |||
| af697bd24d | |||
| c792a5ef15 | |||
| 282cc6372a | |||
| aea6577e38 | |||
| 6ae2de5010 | |||
| d7c3ad199a | |||
| 3808dafda7 | |||
| 14ea651b28 | |||
| 4079caa059 | |||
| 351a81a069 | |||
| 35aad851ba | |||
| e25797e091 | |||
| ac1c3c969b | |||
| 0e256ae481 | |||
| 2179a67b41 | |||
| fd3741e2ee | |||
| 2eb91dc105 | |||
| a257d50872 | |||
| fdebd4dbe9 | |||
| 745d186b3f | |||
| 0145ce5703 | |||
| a45acf1488 | |||
| bbc26c5964 | |||
| 7058143c4e | |||
| 5af2cc37d0 | |||
| 75acdc4195 | |||
| a08cedf7e8 | |||
| a16a0172a4 | |||
| 9af6f4f823 | |||
| 5259fd89ef | |||
| 0e35368e22 | |||
| 0fdc901193 | |||
| c3a458313e | |||
| 8ed7e738ab | |||
| 11b2ff8721 | |||
| 851f1b14f6 | |||
| 67c33c8e1f | |||
| ad8951c567 | |||
| 5da07d9330 | |||
| a680bc235d | |||
| 269ae0088d | |||
| fe6fe9e72e | |||
| 060c9d0b0b | |||
| 7eff55e7f3 | |||
| 810d432374 | |||
| 687521146e | |||
| e82a09187c | |||
| 3a8e2976f0 | |||
| 530b5eed7e | |||
| e9e9bbf4c8 | |||
| 29c8f60135 | |||
| cc497f606b | |||
| c17e56731f | |||
| f5574250d7 | |||
| 3a85e63c01 | |||
| 301696661d | |||
| 9fa469fc67 | |||
| 02fa5cb909 | |||
| 3dfd2a50d4 | |||
| d51325cd81 | |||
| 99ebab8591 | |||
| 92b72dbe7a | |||
| d2e1ff2274 | |||
| 5c67284a51 | |||
| b4d700e27d | |||
| d18b91edda | |||
| 3b97844c64 | |||
| 1ce4424494 | |||
| 6c5e472c4b | |||
| 57d7f260d0 | |||
| 2834265206 | |||
| 40ddf02c51 | |||
| ba20dce4d1 | |||
| aec06cb481 | |||
| 7434464106 | |||
| 01d95ae783 | |||
| d690cb2c0b | |||
| 88f82281dc | |||
| 2e5d76d97d | |||
| fc9c1a4b73 | |||
| 7d4ff6c8b3 | |||
| 8bda43d2b2 | |||
| 36139073d4 | |||
| 3c8fc4d81d | |||
| 22ce0b611a | |||
| 785e1f2542 | |||
| a6c6146933 | |||
| 0113e6dbb1 | |||
| 8d2f4bcda2 | |||
| 9aa3428620 | |||
| e8c73abf2e | |||
| 6275d8cf86 | |||
| 8af96b9a5f | |||
| d9f3516d56 | |||
| b7dec2613f | |||
| d540308d2d | |||
| 9708f81242 | |||
| 35c9fe205c | |||
| b206b50968 | |||
| 007690bcc8 | |||
| 3248d76cd6 | |||
| 1c72e98b81 | |||
| 490bc5f68a | |||
| 2480dc6ba9 | |||
| 733a39b22b | |||
| c6dffc09d9 | |||
| f4dbacd8b4 | |||
| 9dacea3399 | |||
| fdd303cb9e | |||
| 1891b551fa | |||
| 543d733820 | |||
| 9478cd4a31 | |||
| 0d2bd65350 | |||
| 8eaf79bfd1 | |||
| 9d5a0153f9 | |||
| 817832d925 | |||
| 63f4407804 | |||
| 9e876fee67 | |||
| a953df2f0f | |||
| 3e5d29e8d5 | |||
| 9cf4a717a6 | |||
| c8682214e4 | |||
| 9c8a553c30 | |||
| 388e2fc22c | |||
| f7828bccaa | |||
| adee7c1522 | |||
| 807f7f0f2e | |||
| 79e82f4581 | |||
| 503b683c16 | |||
| 944cd372a9 | |||
| 950a93ed0f | |||
| d53439f948 | |||
| a32d834a62 | |||
| 43d839ddbf | |||
| fccb28c608 | |||
| f72153d463 | |||
| 899569221c | |||
| 893a243c80 | |||
| 9e5c6ba41d | |||
| 4bd4230627 | |||
| 2e8e2586e2 | |||
| 503ecdfd6e | |||
| 79d4269b70 | |||
| 603a74a5b7 | |||
| c9a08d6832 | |||
| 308fef3ecd | |||
| 31d007dd67 | |||
| 6fe3ecc89f | |||
| b6b043b0a2 | |||
| bbdb4c2963 | |||
| 33f3b64d17 | |||
| 5ff0cae4d6 | |||
| c80b12ba53 | |||
| e3673f738c | |||
| f7d7d0efce | |||
| 30c32ca293 | |||
| 4d47090994 | |||
| 3fefaed395 | |||
| b1be54d5ba | |||
| 536d1a5c94 | |||
| 5d8369edd8 | |||
| 3c26dd6e23 | |||
| 0baf1332b6 | |||
| 5aca4559c2 | |||
| 21a45058f0 | |||
| edc70c3e6b | |||
| 4bb2facddb | |||
| 466c18fe21 | |||
| ed11c6ccc4 | |||
| 3515b5459f | |||
| e4cf444b83 | |||
| ddf01d2246 | |||
| 1fb0913eb5 | |||
| 293602bed2 | |||
| 87461a4a14 | |||
| fbcae2e596 | |||
| c7f816a449 | |||
| eeab7627ae | |||
| 9052668cbc | |||
| f615e9207f | |||
| 1ba983e745 | |||
| 8f254758dd | |||
| e7c4388956 | |||
| 3d31e6f6a5 | |||
| 1b3991c82f | |||
| 38edd07d65 | |||
| fff4915078 | |||
| 820f833844 | |||
| 1bd85ba888 | |||
| cab77e8872 | |||
| 7b52cebeb7 | |||
| 4c3496e9f2 | |||
| 529d6d7ffc | |||
| 5ca30fbfc4 | |||
| d3729ab906 | |||
| 95bfc120c5 | |||
| 9e98533ffb | |||
| 0ab80c0ac4 | |||
| ef274a483c | |||
| d129ad7a2f | |||
| 1f127807d3 | |||
| e30c78beb7 | |||
| 1014e4374a | |||
| 1d2e92b85f | |||
| 88c3b9bc4a | |||
| 51cb6c1212 | |||
| ffa6830734 | |||
| 6c93cff3bb | |||
| b24335043a | |||
| ac2ea55b5d | |||
| f3e9097bfa | |||
| 0dcec2a6ad | |||
| f8f974eb11 | |||
| 29981e9757 | |||
| a59a9090a7 | |||
| ca17c397c5 | |||
| ff1a80f3b5 | |||
| 4bda7458b4 | |||
| d4d61d1d79 | |||
| 80557a53e8 | |||
| 920a6d4ccd | |||
| ecd0cb12c4 | |||
| fe484b08af | |||
| f5a55392c9 | |||
| 2dc27ea57c | |||
| ecb78bfa29 | |||
| 74936dbe0d | |||
| b1814031b9 | |||
| b5061cf78e | |||
| a8e0376496 | |||
| 16a20faee6 | |||
| 0f34326da4 | |||
| 5a63ca6ea1 | |||
| 5d7852eff9 | |||
| 009e6caead | |||
| e61392d81a | |||
| 083e0af4a0 | |||
| 8c0b6f7e7c | |||
| b87e6cc450 | |||
| cee0352271 | |||
| afc72b73ec | |||
| dfce874ce9 | |||
| a2079a7263 | |||
| 19de123628 | |||
| b942d114ad | |||
| 69ab898bf3 | |||
| 7c66ebe702 | |||
| 84de02de26 | |||
| d5df8d4f32 | |||
| ae74b4c1bd | |||
| dab14b66c4 | |||
| 46e3cd689b | |||
| 6b0d67ee60 | |||
| 7805bc902b | |||
| 95f4a03e81 | |||
| 4c7230ba6b | |||
| 1b2eff69b4 | |||
| e3ab361b24 | |||
| 14026e8bf0 | |||
| 3c1fc92d59 | |||
| a333ddb58f | |||
| f2c5d65ec0 | |||
| bcb9225466 | |||
| 90dfdc8857 | |||
| 476235440c | |||
| 04885f22d6 | |||
| 3b68ab9ab3 | |||
| 31b581c85e | |||
| a3a4772f77 | |||
| 50008e2006 | |||
| 6ef43923e1 | |||
| c30cdcf4ed | |||
| e77a975ccc | |||
| 728a9a92c9 | |||
| 47af9992be | |||
| ede3aacef3 | |||
| a6b17139bf | |||
| 7a7f18701d | |||
| 24006105b9 | |||
| e34434f96c | |||
| c2e95ee6a5 | |||
| da1912d05d | |||
| 9cbc467904 | |||
| 0a5e82dbbb | |||
| 7171d1e3f5 | |||
| 6c7131c944 | |||
| 05098fa3ac | |||
| 131cac392b | |||
| cd3c29bee0 | |||
| 8436ea2071 | |||
| 032e12d9d0 | |||
| 5e91b9a147 | |||
| 9b8865233b | |||
| 3645bb2420 |
+16
-16
@@ -1,8 +1,8 @@
|
|||||||
const moment = require("moment");
|
const 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}`)
|
||||||
|
|||||||
@@ -27,7 +27,13 @@ var logger;
|
|||||||
const fileRotateTransport = new winston.transports.DailyRotateFile({
|
const fileRotateTransport = new winston.transports.DailyRotateFile({
|
||||||
filename: `application/logs/%DATE%-onlinetopup.log`,
|
filename: `application/logs/%DATE%-onlinetopup.log`,
|
||||||
datePattern: "YYYY-MM-DD",
|
datePattern: "YYYY-MM-DD",
|
||||||
maxFiles: "90d",
|
maxFiles: "60d",
|
||||||
|
});
|
||||||
|
|
||||||
|
const fileRotateTransportDebug = new winston.transports.DailyRotateFile({
|
||||||
|
filename: `application/logs/debug/%DATE%-onlinetopup.log`,
|
||||||
|
datePattern: "YYYY-MM-DD",
|
||||||
|
maxFiles: "30d",
|
||||||
});
|
});
|
||||||
//
|
//
|
||||||
// If we're not in production then log to the `console` with the format:
|
// If we're not in production then log to the `console` with the format:
|
||||||
@@ -54,6 +60,7 @@ if (
|
|||||||
defaultMeta: { service: "topuponline-service" },
|
defaultMeta: { service: "topuponline-service" },
|
||||||
transports: [
|
transports: [
|
||||||
fileRotateTransport,
|
fileRotateTransport,
|
||||||
|
fileRotateTransportDebug,
|
||||||
//
|
//
|
||||||
// - Write all logs with importance level of `error` or less to `error.log`
|
// - Write all logs with importance level of `error` or less to `error.log`
|
||||||
// - Write all logs with importance level of `info` or less to `onlinetopup.log`
|
// - Write all logs with importance level of `info` or less to `onlinetopup.log`
|
||||||
@@ -84,6 +91,7 @@ if (
|
|||||||
defaultMeta: { service: "topuponline-service" },
|
defaultMeta: { service: "topuponline-service" },
|
||||||
transports: [
|
transports: [
|
||||||
fileRotateTransport,
|
fileRotateTransport,
|
||||||
|
fileRotateTransportDebug,
|
||||||
//
|
//
|
||||||
// - Write all logs with importance level of `error` or less to `error.log`
|
// - Write all logs with importance level of `error` or less to `error.log`
|
||||||
// - Write all logs with importance level of `info` or less to `onlinetopup.log`
|
// - Write all logs with importance level of `info` or less to `onlinetopup.log`
|
||||||
|
|||||||
@@ -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: {},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -161,6 +161,47 @@ const getLoadBalanceNumberSequence = async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
};
|
};
|
||||||
|
const getLoadBalanceNumberSequence2 = async (req) => {
|
||||||
|
// set default load_balance_number_sequence dari partner apapun is null
|
||||||
|
let load_balance_number_sequence = null;
|
||||||
|
|
||||||
|
// cek jika redis is connect
|
||||||
|
let isRedisReady = await redisClient.isReady;
|
||||||
|
// jika tidak connect
|
||||||
|
if (isRedisReady) {
|
||||||
|
// jika connect maka cari sequence dari reservation number sesuai partner yg merequest
|
||||||
|
// format value nya harusnya seperti ini = { date: '2023-01-01', sequence: 1 }
|
||||||
|
// data req.partner_id_token di dapat dari authenticateToken di jwt middleware
|
||||||
|
let getValue = await redisClient.GET(
|
||||||
|
'load_balance_number_sequence_' + req.partner_id_token
|
||||||
|
);
|
||||||
|
|
||||||
|
if (getValue) {
|
||||||
|
// parsing data menjadi json format
|
||||||
|
let parsedValue = JSON.parse(getValue);
|
||||||
|
|
||||||
|
// cek apakah tanggal sequence yang di redis sama dengan hari ini atau bukan
|
||||||
|
if (parsedValue.date == moment().format('YYYY-MM-DD')) {
|
||||||
|
// jika tanggal nya sama dengan hari ini maka ambil sequence untuk reservation number yang di generate dari redis
|
||||||
|
load_balance_number_sequence = parseInt(parsedValue.sequence);
|
||||||
|
|
||||||
|
// langsung update sequence walaupun transaksi insert nya belum selesai
|
||||||
|
// impact menggunakan redis, untuk nomor sequence bisa saja ada yg loncat karena bisa saja ada transaksi insert reservation yang gagal
|
||||||
|
let setValue = {
|
||||||
|
date: moment().format('YYYY-MM-DD'),
|
||||||
|
sequence: parseInt(parsedValue.sequence) + 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
await redisClient.SET(
|
||||||
|
`load_balance_number_sequence_${req.partner_id_token}`,
|
||||||
|
JSON.stringify(setValue)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return load_balance_number_sequence;
|
||||||
|
// next();
|
||||||
|
};
|
||||||
|
|
||||||
const setLoadBalanceNumberSequence = async (partner_id, sequence) => {
|
const setLoadBalanceNumberSequence = async (partner_id, sequence) => {
|
||||||
// cek jika redis is connect
|
// cek jika redis is connect
|
||||||
@@ -188,4 +229,5 @@ module.exports = {
|
|||||||
setReservationNumberSequence,
|
setReservationNumberSequence,
|
||||||
getLoadBalanceNumberSequence,
|
getLoadBalanceNumberSequence,
|
||||||
setLoadBalanceNumberSequence,
|
setLoadBalanceNumberSequence,
|
||||||
|
getLoadBalanceNumberSequence2,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -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,499 @@ 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')
|
||||||
|
.whereNull('tdrb.c_cash_in_no')
|
||||||
|
// .whereRaw(
|
||||||
|
// `tdrb.c_reservation_no in (SELECT c_reservation_no FROM payment.t_d_payment_recon where c_status = 'S' ) AND tdrb.c_reservation_no NOT IN (SELECT c_reservation_no FROM payment.t_d_cash_in_detail WHERE b_reversal IS NOT TRUE)`
|
||||||
|
// );
|
||||||
|
|
||||||
const res = await trx.select([
|
return res;
|
||||||
"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([
|
|
||||||
"tdpr.c_partner_code",
|
const getSalesKMT = async (trx, code, date, invoice) => {
|
||||||
"tdrb.c_partner_name",
|
const res = await trx
|
||||||
"tdi.c_invoice_no",
|
.select([
|
||||||
"tdi.d_invoice_date",
|
'tdskm.c_sales_no',
|
||||||
trx.raw("to_char(tdpr.d_payment, 'YYYY-MM-DD') AS d_payment"),
|
'tdskm.i_total_billing',
|
||||||
trx.raw("SUM(tdrb.i_reservation_amount) AS amount"),
|
'tdpr.c_payment_recon_no',
|
||||||
"tmp.c_account_topup",
|
'tdpr.d_payment',
|
||||||
"tmp.c_account_code_topup",
|
'tdpr.d_payment_recon',
|
||||||
"i_company",
|
'tdskm.c_partner_code',
|
||||||
"i_holding",
|
'tdskm.c_partner_name',
|
||||||
trx.raw(`CASE
|
'tdsi.c_invoice_no',
|
||||||
WHEN to_char(tdpr.d_payment, 'MM') = to_char(tdi.d_invoice_date, 'MM')
|
'tdsi.m_total_billing as invoice_amount'
|
||||||
|
])
|
||||||
|
.from('kmt_mobile.t_d_sales_kmt_mobile AS tdskm')
|
||||||
|
.leftJoin('payment.t_d_payment_recon_sales_kmt_mobile as tdpr', 'tdpr.c_sales_no', 'tdskm.c_sales_no')
|
||||||
|
.leftJoin('payment.t_d_sales_invoice as tdsi', 'tdsi.i_sales_invoice', 'tdskm.i_sales_invoice')
|
||||||
|
|
||||||
|
.where('tdskm.c_sales_status', '=', 'A')
|
||||||
|
.where('tdsi.c_status', '!=', 'X')
|
||||||
|
.where('tdskm.c_partner_code', '=', code)
|
||||||
|
.where('tdpr.d_payment', '=', date)
|
||||||
|
.where('tdsi.c_invoice_no', '=', invoice)
|
||||||
|
.where('tdpr.c_status', '=', 'S')
|
||||||
|
.whereNotNull('tdsi.c_return_sap')
|
||||||
|
.whereRaw(
|
||||||
|
`tdskm.c_sales_no NOT IN (SELECT c_reservation_no FROM payment.t_d_cash_in_detail WHERE b_reversal IS NOT TRUE)`
|
||||||
|
);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getSalesInternal = async (trx, code, date, invoice) => {
|
||||||
|
const res = await trx
|
||||||
|
.select([
|
||||||
|
'tdskm.c_sales_no',
|
||||||
|
'tdskm.i_total_price',
|
||||||
|
'tdpr.c_payment_recon_no',
|
||||||
|
'tdpr.d_payment',
|
||||||
|
'tdpr.d_payment_recon',
|
||||||
|
'tmp.c_code as c_partner_code',
|
||||||
|
'tmp.c_name as c_partner_name',
|
||||||
|
'tdsi.c_invoice_no',
|
||||||
|
'tdsi.i_total_price as invoice_amount'
|
||||||
|
])
|
||||||
|
.from('trx.t_d_sales_internal AS tdskm')
|
||||||
|
.leftJoin('payment.t_d_payment_recon_sales_internal as tdpr', 'tdpr.c_sales_no', 'tdskm.c_sales_no')
|
||||||
|
.leftJoin('payment.t_d_sales_invoice_internal as tdsi', 'tdsi.i_sales_invoice_internal', 'tdskm.i_sales_invoice_internal')
|
||||||
|
.leftJoin('public.t_m_partner as tmp', 'tmp.i_partner', 'tdskm.i_partner')
|
||||||
|
.where('tdsi.c_status', '!=', 'X')
|
||||||
|
.where('tmp.c_code', '=', code)
|
||||||
|
.where('tdpr.d_payment', '=', date)
|
||||||
|
.where('tdsi.c_invoice_no', '=', invoice)
|
||||||
|
.where('tdpr.c_status', '=', 'S')
|
||||||
|
.whereNotNull('tdsi.c_return_sap_fi')
|
||||||
|
.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 getTopUpCashlessInternal = async (trx, code, date, invoice) => {
|
||||||
|
const res = await trx
|
||||||
|
.select([
|
||||||
|
'tdskm.c_topup_no',
|
||||||
|
'tdskm.i_amount',
|
||||||
|
'tdpr.c_payment_recon_no',
|
||||||
|
'tdpr.d_payment',
|
||||||
|
'tdpr.d_payment_recon',
|
||||||
|
'tmp.c_code as c_partner_code',
|
||||||
|
'tmp.c_name as c_partner_name',
|
||||||
|
'tdsi.c_invoice_no',
|
||||||
|
'tdsi.i_total_amount as invoice_amount'
|
||||||
|
])
|
||||||
|
.from('trx.t_d_topup_cashless_internal AS tdskm')
|
||||||
|
.leftJoin('payment.t_d_payment_recon_topup_cashless_internal as tdpr', 'tdpr.c_topup_no', 'tdskm.c_topup_no')
|
||||||
|
.leftJoin('payment.t_d_topup_cashless_invoice_internal as tdsi', 'tdsi.i_topup_cashless_invoice_internal', 'tdskm.i_topup_cashless_invoice_internal')
|
||||||
|
.leftJoin('public.t_m_partner as tmp', 'tmp.i_partner', 'tdskm.i_partner')
|
||||||
|
.where('tdsi.c_status', '!=', 'X')
|
||||||
|
.where('tmp.c_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_topup_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 getPartnerReconSalesInternal = async (trx) => {
|
||||||
|
|
||||||
|
const res = await trx
|
||||||
|
.select([
|
||||||
|
'tmp.c_code as c_partner_code',
|
||||||
|
'tmp.c_name as 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_price),0) AS amount'),
|
||||||
|
'tmp.c_account_sales_revenue',
|
||||||
|
'tmp.c_account_code_sales_ar',
|
||||||
|
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('trx.t_d_sales_internal AS tdskm')
|
||||||
|
|
||||||
|
.leftJoin('payment.t_d_sales_invoice_internal as tdsi', function () {
|
||||||
|
this.on('tdsi.i_sales_invoice_internal', '=', 'tdskm.i_sales_invoice_internal');
|
||||||
|
})
|
||||||
|
.leftJoin('payment.t_d_payment_recon_sales_internal 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('tdsi.c_status', '!=', 'X')
|
||||||
|
.where('tdpr.c_status', '=', 'S')
|
||||||
|
.whereNotNull('tdsi.c_return_sap_fi')
|
||||||
|
.whereNull('tdskm.i_cash_in')
|
||||||
|
.groupBy([
|
||||||
|
'tmp.c_code',
|
||||||
|
'tmp.c_name',
|
||||||
|
'tdsi.c_invoice_no',
|
||||||
|
'tdsi.d_invoice_date',
|
||||||
|
'tdpr.d_payment',
|
||||||
|
'tmp.c_account_sales_revenue',
|
||||||
|
'tmp.c_account_code_sales_ar'
|
||||||
|
]);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getPartnerReconTopUpCashlessInternal = async (trx) => {
|
||||||
|
|
||||||
|
const res = await trx
|
||||||
|
.select([
|
||||||
|
'tmp.c_code as c_partner_code',
|
||||||
|
'tmp.c_name as 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_amount),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('trx.t_d_topup_cashless_internal AS tdskm')
|
||||||
|
|
||||||
|
.leftJoin('payment.t_d_topup_cashless_invoice_internal as tdsi', function () {
|
||||||
|
this.on('tdsi.i_topup_cashless_invoice_internal', '=', 'tdskm.i_topup_cashless_invoice_internal');
|
||||||
|
})
|
||||||
|
.leftJoin('payment.t_d_payment_recon_topup_cashless_internal as tdpr', function () {
|
||||||
|
this.on('tdpr.c_topup_no', '=', 'tdskm.c_topup_no');
|
||||||
|
})
|
||||||
|
.leftJoin('public.t_m_partner as tmp', function () {
|
||||||
|
this.on('tmp.i_partner', '=', 'tdskm.i_partner');
|
||||||
|
})
|
||||||
|
.where('tdsi.c_status', '!=', 'X')
|
||||||
|
.where('tdpr.c_status', '=', 'S')
|
||||||
|
.whereNotNull('tdsi.c_return_sap')
|
||||||
|
.whereNull('tdskm.i_cash_in')
|
||||||
|
.groupBy([
|
||||||
|
'tmp.c_code',
|
||||||
|
'tmp.c_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 updateIntoSalesInternal = async (trx, dataSales, salesNo) => {
|
||||||
|
let result = await trx('trx.t_d_sales_internal')
|
||||||
|
.update(dataSales, ['*'])
|
||||||
|
.where({ c_sales_no: salesNo });
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateIntoTopUpCashlessInternal = async (trx, dataTopup, topupNo) => {
|
||||||
|
let result = await trx('trx.t_d_topup_cashless_internal')
|
||||||
|
.update(dataTopup, ['*'])
|
||||||
|
.where({ c_topup_no: topupNo });
|
||||||
|
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 +757,20 @@ module.exports = {
|
|||||||
setReturnSAP,
|
setReturnSAP,
|
||||||
getPostingEt,
|
getPostingEt,
|
||||||
writePaynentHistory,
|
writePaynentHistory,
|
||||||
|
|
||||||
getRecon,
|
getRecon,
|
||||||
generateCode,
|
generateCode,
|
||||||
insertCashInDetail,
|
insertCashInDetail,
|
||||||
getReserve,
|
|
||||||
getPartnerRecon,
|
getPartnerRecon,
|
||||||
|
getPartnerReconSales,
|
||||||
|
getPartnerReconSalesInternal,
|
||||||
|
getPartnerReconTopUpCashlessInternal,
|
||||||
|
getReserve,
|
||||||
|
getSalesKMT,
|
||||||
|
getSalesInternal,
|
||||||
|
getTopUpCashlessInternal,
|
||||||
insertCashIn,
|
insertCashIn,
|
||||||
updateIntoReserve
|
updateIntoReserve,
|
||||||
|
updateIntoSalesKMT,
|
||||||
|
updateIntoSalesInternal,
|
||||||
|
updateIntoTopUpCashlessInternal,
|
||||||
};
|
};
|
||||||
@@ -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`);
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -1,38 +1,38 @@
|
|||||||
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('./invoice.model');
|
const model = require("./invoice.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");
|
||||||
|
|
||||||
// VALIDATION
|
// VALIDATION
|
||||||
const validate = (method) => {
|
const validate = (method) => {
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case 'generateInvoice':
|
case "generateInvoice":
|
||||||
return [
|
return [
|
||||||
body('trx_date')
|
body("trx_date")
|
||||||
.notEmpty()
|
.notEmpty()
|
||||||
.withMessage('trx_date is required!')
|
.withMessage("trx_date is required!")
|
||||||
.isISO8601()
|
.isISO8601()
|
||||||
.withMessage('invalid trx_date format YYYY-MM-DD !')
|
.withMessage("invalid trx_date format YYYY-MM-DD !")
|
||||||
.escape()
|
.escape()
|
||||||
.trim(),
|
.trim(),
|
||||||
body('repost')
|
body("repost")
|
||||||
.notEmpty()
|
.notEmpty()
|
||||||
.withMessage('repost is required!')
|
.withMessage("repost is required!")
|
||||||
.isBoolean()
|
.isBoolean()
|
||||||
.withMessage('repost must boolean!')
|
.withMessage("repost must boolean!")
|
||||||
.escape()
|
.escape()
|
||||||
.trim(),
|
.trim(),
|
||||||
];
|
];
|
||||||
case 'postingInvoice':
|
case "postingInvoice":
|
||||||
return [
|
return [
|
||||||
body('trx_date')
|
body("trx_date")
|
||||||
.notEmpty()
|
.notEmpty()
|
||||||
.withMessage('trx_date is required!')
|
.withMessage("trx_date is required!")
|
||||||
.isISO8601()
|
.isISO8601()
|
||||||
.withMessage('invalid trx_date format YYYY-MM-DD !')
|
.withMessage("invalid trx_date format YYYY-MM-DD !")
|
||||||
.escape()
|
.escape()
|
||||||
.trim(),
|
.trim(),
|
||||||
];
|
];
|
||||||
@@ -57,7 +57,7 @@ const apiGenerateInvoice = async (req, res) => {
|
|||||||
let err = validationResult(req, res);
|
let 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: {},
|
||||||
};
|
};
|
||||||
@@ -71,7 +71,7 @@ const apiGenerateInvoice = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// time
|
// time
|
||||||
let invoiceDate = moment(req.body.trx_date).format('YYYY-MM-DD');
|
let invoiceDate = moment(req.body.trx_date).format("YYYY-MM-DD");
|
||||||
|
|
||||||
let invoice = await _generateInvoice(
|
let invoice = await _generateInvoice(
|
||||||
invoiceDate,
|
invoiceDate,
|
||||||
@@ -80,8 +80,8 @@ const apiGenerateInvoice = async (req, res) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
code: '200',
|
code: "200",
|
||||||
message: 'Succes posting',
|
message: "Succes posting",
|
||||||
data: invoice,
|
data: invoice,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -93,11 +93,11 @@ const apiGenerateInvoice = async (req, res) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
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: {},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -119,7 +119,7 @@ const apiPostingInvoice = async (req, res) => {
|
|||||||
let err = validationResult(req, res);
|
let 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: {},
|
||||||
};
|
};
|
||||||
@@ -137,10 +137,15 @@ const apiPostingInvoice = async (req, res) => {
|
|||||||
|
|
||||||
let invoice = await _postingInvoice(uniqueCode);
|
let invoice = await _postingInvoice(uniqueCode);
|
||||||
|
|
||||||
|
let errorCount = invoice[0].error;
|
||||||
|
|
||||||
|
invoice.splice(0, 1);
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
code: '200',
|
code: "200",
|
||||||
message: 'Succes',
|
message: "Succes",
|
||||||
data: invoice,
|
data: invoice,
|
||||||
|
error: errorCount,
|
||||||
};
|
};
|
||||||
|
|
||||||
return res.status(200).json(result);
|
return res.status(200).json(result);
|
||||||
@@ -151,11 +156,11 @@ const apiPostingInvoice = async (req, res) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
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: {},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -200,29 +205,29 @@ const _generateInvoice = async (invoiceDate, uniqueCode, repost) => {
|
|||||||
|
|
||||||
let credUsername = await model.getParameterSetting(
|
let credUsername = await model.getParameterSetting(
|
||||||
knex,
|
knex,
|
||||||
'SAP_AUTH_USERNAME'
|
"SAP_AUTH_USERNAME"
|
||||||
);
|
);
|
||||||
let credPassword = await model.getParameterSetting(
|
let credPassword = await model.getParameterSetting(
|
||||||
knex,
|
knex,
|
||||||
'SAP_AUTH_PASSWORD'
|
"SAP_AUTH_PASSWORD"
|
||||||
);
|
);
|
||||||
let parameter = await model.getParameterSetting(
|
let parameter = await model.getParameterSetting(
|
||||||
knex,
|
knex,
|
||||||
'SAP_FI_URL_FOR_FB70'
|
"SAP_FI_URL_FOR_FB70"
|
||||||
);
|
);
|
||||||
|
|
||||||
for (let key in invoice) {
|
for (let key in invoice) {
|
||||||
let prepare = {
|
let prepare = {
|
||||||
status: true,
|
status: true,
|
||||||
cms: true,
|
cms: true,
|
||||||
message: 'Success',
|
message: "Success",
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!credUsername) {
|
if (!credUsername) {
|
||||||
prepare = {
|
prepare = {
|
||||||
status: false,
|
status: false,
|
||||||
cms: false,
|
cms: false,
|
||||||
message: '[CMS] FAILED GET SETTING FOR SAP_AUTH_USERNAME',
|
message: "[CMS] FAILED GET SETTING FOR SAP_AUTH_USERNAME",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,7 +235,7 @@ const _generateInvoice = async (invoiceDate, uniqueCode, repost) => {
|
|||||||
prepare = {
|
prepare = {
|
||||||
status: false,
|
status: false,
|
||||||
cms: false,
|
cms: false,
|
||||||
message: '[CMS] FAILED GET SETTING FOR SAP_AUTH_PASSWORD',
|
message: "[CMS] FAILED GET SETTING FOR SAP_AUTH_PASSWORD",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,7 +243,7 @@ const _generateInvoice = async (invoiceDate, uniqueCode, repost) => {
|
|||||||
prepare = {
|
prepare = {
|
||||||
status: false,
|
status: false,
|
||||||
cms: false,
|
cms: false,
|
||||||
message: '[CMS] FAILED GET SETTING FOR SAP_AUTH_PASSWORD',
|
message: "[CMS] FAILED GET SETTING FOR SAP_AUTH_PASSWORD",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,49 +260,49 @@ const _generateInvoice = async (invoiceDate, uniqueCode, repost) => {
|
|||||||
status: false,
|
status: false,
|
||||||
cms: false,
|
cms: false,
|
||||||
message:
|
message:
|
||||||
'[CMS] FAILED GET PARTNER ACCOUNT CODE TOPUP / ACCOUNT TOPUP',
|
"[CMS] FAILED GET PARTNER ACCOUNT CODE TOPUP / ACCOUNT TOPUP",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
invoice[key].c_account_code_topup == '' ||
|
invoice[key].c_account_code_topup == "" ||
|
||||||
invoice[key].c_account_topup == ''
|
invoice[key].c_account_topup == ""
|
||||||
) {
|
) {
|
||||||
prepare = {
|
prepare = {
|
||||||
status: false,
|
status: false,
|
||||||
cms: false,
|
cms: false,
|
||||||
message:
|
message:
|
||||||
'[CMS] FAILED GET PARTNER ACCOUNT CODE TOPUP / ACCOUNT TOPUP',
|
"[CMS] FAILED GET PARTNER ACCOUNT CODE TOPUP / ACCOUNT TOPUP",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let xmlHeader = {
|
let xmlHeader = {
|
||||||
doc_header_text: invoice[key].doc_header_text
|
doc_header_text: invoice[key].doc_header_text
|
||||||
? invoice[key].doc_header_text
|
? invoice[key].doc_header_text
|
||||||
: '',
|
: "",
|
||||||
ba: invoice[key].ba ? invoice[key].ba : '',
|
ba: invoice[key].ba ? invoice[key].ba : "",
|
||||||
doc_date: invoice[key].doc_date ? invoice[key].doc_date : '',
|
doc_date: invoice[key].doc_date ? invoice[key].doc_date : "",
|
||||||
posting_date: invoice[key].posting_date
|
posting_date: invoice[key].posting_date
|
||||||
? invoice[key].posting_date
|
? invoice[key].posting_date
|
||||||
: '',
|
: "",
|
||||||
fisc_year: invoice[key].fisc_year ? invoice[key].fisc_year : '',
|
fisc_year: invoice[key].fisc_year ? invoice[key].fisc_year : "",
|
||||||
fisc_period: invoice[key].fisc_period ? invoice[key].fisc_period : '',
|
fisc_period: invoice[key].fisc_period ? invoice[key].fisc_period : "",
|
||||||
doc_type: invoice[key].doc_type ? invoice[key].doc_type : '',
|
doc_type: invoice[key].doc_type ? invoice[key].doc_type : "",
|
||||||
c_invoice_no: invoice[key].c_invoice_no
|
c_invoice_no: invoice[key].c_invoice_no
|
||||||
? invoice[key].c_invoice_no
|
? invoice[key].c_invoice_no
|
||||||
: '',
|
: "",
|
||||||
};
|
};
|
||||||
|
|
||||||
let xmlItem = ['S', 'H'].map((item) => {
|
let xmlItem = ["S", "H"].map((item) => {
|
||||||
return {
|
return {
|
||||||
c_account_code_topup:
|
c_account_code_topup:
|
||||||
item == 'S' ? invoice[key].c_account_code_topup : '',
|
item == "S" ? invoice[key].c_account_code_topup : "",
|
||||||
c_account_topup: item == 'H' ? invoice[key].c_account_topup : '',
|
c_account_topup: item == "H" ? invoice[key].c_account_topup : "",
|
||||||
ba: invoice[key].ba,
|
ba: invoice[key].ba,
|
||||||
amount: invoice[key].amount,
|
amount: invoice[key].amount,
|
||||||
posting_date: invoice[key].posting_date,
|
posting_date: invoice[key].posting_date,
|
||||||
c_invoice_no: invoice[key].c_invoice_no,
|
c_invoice_no: invoice[key].c_invoice_no,
|
||||||
item_text: `${item == 'S' ? 'DEBIT' : 'KREDIT'} INVOICE CMS ${
|
item_text: `${item == "S" ? "DEBIT" : "KREDIT"} INVOICE CMS ${
|
||||||
invoice[key].doc_header_text
|
invoice[key].doc_header_text
|
||||||
}`,
|
}`,
|
||||||
de_cre: item,
|
de_cre: item,
|
||||||
@@ -305,7 +310,7 @@ const _generateInvoice = async (invoiceDate, uniqueCode, repost) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let xmlRequest = helper.generateXMLRequest(
|
let xmlRequest = helper.generateXMLRequest(
|
||||||
'ZFMCMS_FI_001',
|
"ZFMCMS_FI_001",
|
||||||
xmlHeader,
|
xmlHeader,
|
||||||
xmlItem
|
xmlItem
|
||||||
);
|
);
|
||||||
@@ -338,8 +343,8 @@ const _generateInvoice = async (invoiceDate, uniqueCode, repost) => {
|
|||||||
resSAP = helper.getXMLData(response);
|
resSAP = helper.getXMLData(response);
|
||||||
} else {
|
} else {
|
||||||
resSAP = {
|
resSAP = {
|
||||||
type: 'E',
|
type: "E",
|
||||||
message: prepare?.message || 'FAILED GET PARAMETER SETTING',
|
message: prepare?.message || "FAILED GET PARAMETER SETTING",
|
||||||
data: {},
|
data: {},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -382,33 +387,33 @@ const _postingInvoice = async (uniqueCode) => {
|
|||||||
)}`
|
)}`
|
||||||
);
|
);
|
||||||
|
|
||||||
let credUsername = await model.getParameterSetting(knex, 'SAP_AUTH_USERNAME');
|
let credUsername = await model.getParameterSetting(knex, "SAP_AUTH_USERNAME");
|
||||||
let credPassword = await model.getParameterSetting(knex, 'SAP_AUTH_PASSWORD');
|
let credPassword = await model.getParameterSetting(knex, "SAP_AUTH_PASSWORD");
|
||||||
let parameter = await model.getParameterSetting(knex, 'SAP_FI_URL_FOR_FB70');
|
let parameter = await model.getParameterSetting(knex, "SAP_FI_URL_FOR_FB70");
|
||||||
|
|
||||||
let prepare = {
|
let prepare = {
|
||||||
status: true,
|
status: true,
|
||||||
message: 'Success',
|
message: "Success",
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!credUsername) {
|
if (!credUsername) {
|
||||||
prepare = {
|
prepare = {
|
||||||
status: false,
|
status: false,
|
||||||
message: 'FAILED GET SETTING FOR SAP_AUTH_USERNAME',
|
message: "FAILED GET SETTING FOR SAP_AUTH_USERNAME",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!credPassword) {
|
if (!credPassword) {
|
||||||
prepare = {
|
prepare = {
|
||||||
status: false,
|
status: false,
|
||||||
message: 'FAILED GET SETTING FOR SAP_AUTH_PASSWORD',
|
message: "FAILED GET SETTING FOR SAP_AUTH_PASSWORD",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!parameter) {
|
if (!parameter) {
|
||||||
prepare = {
|
prepare = {
|
||||||
status: false,
|
status: false,
|
||||||
message: 'FAILED GET SETTING FOR SAP_AUTH_PASSWORD',
|
message: "FAILED GET SETTING FOR SAP_AUTH_PASSWORD",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -417,6 +422,7 @@ const _postingInvoice = async (uniqueCode) => {
|
|||||||
password: credPassword.c_value,
|
password: credPassword.c_value,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let errorCount = 0;
|
||||||
for (let item of postingEt) {
|
for (let item of postingEt) {
|
||||||
await knex.transaction(async (trx) => {
|
await knex.transaction(async (trx) => {
|
||||||
let response = {};
|
let response = {};
|
||||||
@@ -425,31 +431,31 @@ const _postingInvoice = async (uniqueCode) => {
|
|||||||
|
|
||||||
if (prepare.status) {
|
if (prepare.status) {
|
||||||
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(
|
let xmlRequest = helper.generateXMLRequest(
|
||||||
'ZFMCMS_FI_001',
|
"ZFMCMS_FI_001",
|
||||||
xmlHeader,
|
xmlHeader,
|
||||||
xmlItem
|
xmlItem
|
||||||
);
|
);
|
||||||
@@ -471,10 +477,13 @@ const _postingInvoice = async (uniqueCode) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
resSAP = helper.getXMLData(response);
|
resSAP = helper.getXMLData(response);
|
||||||
|
if (resSAP.type == "E") {
|
||||||
|
errorCount++;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
resSAP = {
|
resSAP = {
|
||||||
type: 'E',
|
type: "E",
|
||||||
message: prepare?.message || 'FAILED GET PARAMETER SETTING',
|
message: prepare?.message || "FAILED GET PARAMETER SETTING",
|
||||||
data: {},
|
data: {},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -511,6 +520,8 @@ const _postingInvoice = async (uniqueCode) => {
|
|||||||
`SCHEDULER-RETRY-${uniqueCode} RESULT CMS : ${JSON.stringify(cms)}`
|
`SCHEDULER-RETRY-${uniqueCode} RESULT CMS : ${JSON.stringify(cms)}`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
collection.push({ error: errorCount });
|
||||||
|
|
||||||
collection.push(cms.invoice[0]);
|
collection.push(cms.invoice[0]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
|
|
||||||
// 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 (invoice, trx) => {
|
const insertPostingEt = async (invoice, trx) => {
|
||||||
console.log("invoice : ", invoice)
|
console.log("invoice : ", invoice);
|
||||||
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: invoice.file_name,
|
file_name: invoice.file_name,
|
||||||
@@ -26,222 +27,293 @@ const insertPostingEt = async (invoice, trx) => {
|
|||||||
reference: invoice.c_invoice_no,
|
reference: invoice.c_invoice_no,
|
||||||
amount: invoice.amount,
|
amount: invoice.amount,
|
||||||
ba: invoice.ba,
|
ba: invoice.ba,
|
||||||
indeks: (index+1),
|
indeks: index + 1,
|
||||||
totalidx: type.length,
|
totalidx: type.length,
|
||||||
doc_header_text: invoice.c_invoice_no,
|
doc_header_text: invoice.c_invoice_no,
|
||||||
pos_status : 3
|
pos_status: 3,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (item == "H") {
|
||||||
|
data = {
|
||||||
|
...data,
|
||||||
|
...{
|
||||||
|
text: `Posting Invoice CMS ${invoice.c_invoice_no}`,
|
||||||
|
debit_kredit: item,
|
||||||
|
account: invoice.c_account_topup,
|
||||||
|
customer: null,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
data = {
|
||||||
|
...data,
|
||||||
|
...{
|
||||||
|
text: `Posting Invoice CMS ${invoice.c_invoice_no}`,
|
||||||
|
debit_kredit: item,
|
||||||
|
account: null,
|
||||||
|
customer: invoice.c_account_code_topup,
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if(item == 'H'){
|
et.push(data);
|
||||||
data = {...data, ...{
|
|
||||||
text: `Posting Invoice CMS ${invoice.c_invoice_no}`,
|
|
||||||
debit_kredit: item,
|
|
||||||
account: invoice.c_account_topup,
|
|
||||||
customer: null
|
|
||||||
}}
|
|
||||||
}else{
|
|
||||||
data = {...data, ...{
|
|
||||||
text: `Posting Invoice CMS ${invoice.c_invoice_no}`,
|
|
||||||
debit_kredit: item,
|
|
||||||
account: null,
|
|
||||||
customer: invoice.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",
|
||||||
|
"customer",
|
||||||
|
"account",
|
||||||
|
"ba",
|
||||||
|
"fiscal_year",
|
||||||
|
"amount",
|
||||||
|
"no_dok",
|
||||||
|
"text",
|
||||||
|
"debit_kredit",
|
||||||
|
]);
|
||||||
|
|
||||||
return posting_et[0]
|
return posting_et[0];
|
||||||
|
};
|
||||||
|
|
||||||
}
|
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",
|
||||||
|
"tcode",
|
||||||
|
"amount",
|
||||||
|
trx.raw(`'IDR' AS currency`),
|
||||||
|
trx.raw(
|
||||||
|
`(select pe2.customer from posting_et pe2 where pe2.reference = pe.reference and debit_kredit = 'S' LIMIT 1) as customer`
|
||||||
|
),
|
||||||
|
trx.raw(
|
||||||
|
`(select pe2.account from posting_et pe2 where pe2.reference = pe.reference and debit_kredit = 'H' LIMIT 1) as account`
|
||||||
|
),
|
||||||
|
trx.raw(
|
||||||
|
`(select pe2.text from posting_et pe2 where pe2.reference = pe.reference and debit_kredit = 'S' LIMIT 1) as text1`
|
||||||
|
),
|
||||||
|
trx.raw(
|
||||||
|
`(select pe2.text from posting_et pe2 where pe2.reference = pe.reference and debit_kredit = 'H' LIMIT 1) as text2`
|
||||||
|
),
|
||||||
|
])
|
||||||
|
.where("tcode", "=", "FB70")
|
||||||
|
.whereIn("pos_status", ["3"])
|
||||||
|
// .limit(1)
|
||||||
|
.groupBy([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12]);
|
||||||
|
|
||||||
const getPostingEt = async(trx) => {
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
const result = await trx('public.posting_et AS pe').select([
|
const setReturnSAP = async (
|
||||||
'doc_header_text',
|
invoice,
|
||||||
'ba',
|
resSAP,
|
||||||
'doc_date',
|
trx,
|
||||||
'posting_date',
|
posting = false,
|
||||||
'fiscal_year',
|
c_invoice_no
|
||||||
trx.raw(`TO_CHAR(doc_date::DATE, 'MM') AS fis_period`),
|
) => {
|
||||||
'doc_type',
|
let t_invoice = {};
|
||||||
'reference',
|
let t_load_balance = {};
|
||||||
'tcode',
|
let posting_et = {};
|
||||||
'amount',
|
if (resSAP.type == "S") {
|
||||||
trx.raw(`'IDR' AS currency`),
|
|
||||||
trx.raw(`(select pe2.customer from posting_et pe2 where pe2.reference = pe.reference and debit_kredit = 'S' LIMIT 1) as customer`),
|
|
||||||
trx.raw(`(select pe2.account from posting_et pe2 where pe2.reference = pe.reference and debit_kredit = 'H' LIMIT 1) as account`),
|
|
||||||
trx.raw(`(select pe2.text from posting_et pe2 where pe2.reference = pe.reference and debit_kredit = 'S' LIMIT 1) as text1`),
|
|
||||||
trx.raw(`(select pe2.text from posting_et pe2 where pe2.reference = pe.reference and debit_kredit = 'H' LIMIT 1) as text2`),
|
|
||||||
])
|
|
||||||
.where('tcode', '=', "FB70")
|
|
||||||
.whereIn('pos_status', ["3"])
|
|
||||||
.groupBy([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12])
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
const setReturnSAP = async (invoice, resSAP, trx, posting = false, c_invoice_no) => {
|
|
||||||
let t_invoice = {}
|
|
||||||
let t_load_balance = {}
|
|
||||||
let posting_et = {}
|
|
||||||
if(resSAP.type == 'S'){
|
|
||||||
// update invoice
|
// update invoice
|
||||||
t_invoice = await trx('payment.t_d_invoice').update({
|
t_invoice = await trx("payment.t_d_invoice")
|
||||||
c_return_sap: resSAP.data.E_DOCUMENTNUMBER
|
.update(
|
||||||
}, ["*"])
|
{
|
||||||
.where({
|
c_return_sap: resSAP.data.E_DOCUMENTNUMBER,
|
||||||
c_invoice_no: c_invoice_no
|
},
|
||||||
});
|
["*"]
|
||||||
|
)
|
||||||
|
.where({
|
||||||
|
c_invoice_no: c_invoice_no,
|
||||||
|
});
|
||||||
|
|
||||||
// update load balance
|
// update load balance
|
||||||
t_load_balance = await trx('trx.t_d_load_balance').update({
|
t_load_balance = await trx("trx.t_d_load_balance")
|
||||||
c_return_sap: resSAP.data.E_DOCUMENTNUMBER
|
.update(
|
||||||
}, ['c_load_balance_no', 'c_return_sap'])
|
{
|
||||||
.whereRaw(`c_load_balance_no IN (SELECT c_load_balance_no FROM payment.t_d_payment_request_topup_online WHERE c_payment = '${c_invoice_no}')`)
|
c_return_sap: resSAP.data.E_DOCUMENTNUMBER,
|
||||||
|
},
|
||||||
|
["c_load_balance_no", "c_return_sap"]
|
||||||
|
)
|
||||||
|
.whereRaw(
|
||||||
|
`c_load_balance_no IN (SELECT c_load_balance_no FROM payment.t_d_payment_request_topup_online WHERE c_payment = '${c_invoice_no}')`
|
||||||
|
);
|
||||||
|
|
||||||
posting_et = await trx('public.posting_et').update({
|
posting_et = await trx("public.posting_et")
|
||||||
pos_status : 0,
|
.update(
|
||||||
status0 : resSAP.type,
|
{
|
||||||
no_doksap : resSAP.data.E_DOCUMENTNUMBER ? resSAP.data.E_DOCUMENTNUMBER : null,
|
pos_status: 0,
|
||||||
status1 : resSAP.message ? resSAP.message : null
|
status0: resSAP.type,
|
||||||
}, ['file_name','status0']).where({
|
no_doksap: resSAP.data.E_DOCUMENTNUMBER
|
||||||
reference: c_invoice_no
|
? resSAP.data.E_DOCUMENTNUMBER
|
||||||
})
|
: null,
|
||||||
|
status1: resSAP.message ? resSAP.message : null,
|
||||||
|
},
|
||||||
|
["file_name", "status0"]
|
||||||
|
)
|
||||||
|
.where({
|
||||||
|
reference: c_invoice_no,
|
||||||
|
});
|
||||||
|
|
||||||
if(posting) {
|
if (posting) {
|
||||||
await writePaynentHistory(t_invoice[0], "SUCCESSFULLY", 102, trx)
|
await writePaynentHistory(t_invoice[0], "SUCCESSFULLY", 102, trx);
|
||||||
} else {
|
} else {
|
||||||
await writePaynentHistory(t_invoice[0], "SUCCESS TO RETRY SAP", 118, trx)
|
await writePaynentHistory(t_invoice[0], "SUCCESS TO RETRY SAP", 118, trx);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
}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();
|
||||||
|
|
||||||
posting_et = await trx('public.posting_et').update({
|
posting_et = await trx("public.posting_et")
|
||||||
pos_status : 0,
|
.update(
|
||||||
status0 : 'S',
|
{
|
||||||
no_doksap : doc_number,
|
pos_status: 0,
|
||||||
status1 : resSAP.message ? resSAP.message : null
|
status0: "S",
|
||||||
}, ['file_name','status0']).where({
|
no_doksap: doc_number,
|
||||||
reference: c_invoice_no
|
status1: resSAP.message ? resSAP.message : null,
|
||||||
})
|
},
|
||||||
|
["file_name", "status0"]
|
||||||
|
)
|
||||||
|
.where({
|
||||||
|
reference: c_invoice_no,
|
||||||
|
});
|
||||||
|
|
||||||
// update invoice
|
// update invoice
|
||||||
t_invoice = await trx('payment.t_d_invoice').update({
|
t_invoice = await trx("payment.t_d_invoice")
|
||||||
c_return_sap: doc_number
|
.update(
|
||||||
}, ['*'])
|
{
|
||||||
.where({
|
c_return_sap: doc_number,
|
||||||
c_invoice_no: c_invoice_no
|
},
|
||||||
});
|
["*"]
|
||||||
|
)
|
||||||
|
.where({
|
||||||
|
c_invoice_no: c_invoice_no,
|
||||||
|
});
|
||||||
|
|
||||||
// update load balance
|
// update load balance
|
||||||
t_load_balance = await trx('trx.t_d_load_balance').update({
|
t_load_balance = await trx("trx.t_d_load_balance")
|
||||||
c_return_sap: doc_number
|
.update(
|
||||||
}, ['c_load_balance_no', 'c_return_sap'])
|
{
|
||||||
.whereRaw(`c_load_balance_no IN (SELECT c_load_balance_no FROM payment.t_d_payment_request_topup_online WHERE c_payment = '${c_invoice_no}')`)
|
c_return_sap: doc_number,
|
||||||
|
},
|
||||||
|
["c_load_balance_no", "c_return_sap"]
|
||||||
|
)
|
||||||
|
.whereRaw(
|
||||||
|
`c_load_balance_no IN (SELECT c_load_balance_no FROM payment.t_d_payment_request_topup_online WHERE c_payment = '${c_invoice_no}')`
|
||||||
|
);
|
||||||
|
|
||||||
if(posting) {
|
if (posting) {
|
||||||
await writePaynentHistory(t_invoice[0], "SUCCESSFULLY", 102, trx)
|
await writePaynentHistory(t_invoice[0], "SUCCESSFULLY", 102, trx);
|
||||||
} else {
|
} else {
|
||||||
await writePaynentHistory(t_invoice[0], "SUCCESS TO RETRY SAP", 118, trx)
|
await writePaynentHistory(
|
||||||
|
t_invoice[0],
|
||||||
|
"SUCCESS TO RETRY SAP",
|
||||||
|
118,
|
||||||
|
trx
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
}else{
|
|
||||||
// update posting et
|
// update posting et
|
||||||
posting_et = await trx('public.posting_et').update({
|
posting_et = await trx("public.posting_et")
|
||||||
pos_status : resSAP.type == 'S' ? 0 : 3,
|
.update(
|
||||||
status0 : resSAP.type,
|
{
|
||||||
no_doksap : resSAP.data.E_DOCUMENTNUMBER ? resSAP.data.E_DOCUMENTNUMBER : null,
|
pos_status: resSAP.type == "S" ? 0 : 3,
|
||||||
status1 : resSAP.message ? resSAP.message : null
|
status0: resSAP.type,
|
||||||
}, ['file_name','status0']).where({
|
no_doksap: resSAP.data.E_DOCUMENTNUMBER
|
||||||
reference: c_invoice_no
|
? resSAP.data.E_DOCUMENTNUMBER
|
||||||
})
|
: null,
|
||||||
|
status1: resSAP.message ? resSAP.message : null,
|
||||||
|
},
|
||||||
|
["file_name", "status0"]
|
||||||
|
)
|
||||||
|
.where({
|
||||||
|
reference: c_invoice_no,
|
||||||
|
});
|
||||||
|
|
||||||
// update invoice
|
// update invoice
|
||||||
t_invoice = await trx('payment.t_d_invoice').select(['*'])
|
t_invoice = await trx("payment.t_d_invoice").select(["*"]).where({
|
||||||
.where({
|
c_invoice_no: c_invoice_no,
|
||||||
c_invoice_no: c_invoice_no
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if(posting) {
|
if (posting) {
|
||||||
await writePaynentHistory(t_invoice[0], `SUCCESS WITH SAP ERR: ${resSAP.message}`,102, trx)
|
await writePaynentHistory(
|
||||||
|
t_invoice[0],
|
||||||
|
`SUCCESS WITH SAP ERR: ${resSAP.message}`,
|
||||||
|
102,
|
||||||
|
trx
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
await writePaynentHistory(t_invoice[0], `FAIL TO RETRY WITH SAP ERR: ${resSAP.message}`,118, trx)
|
await writePaynentHistory(
|
||||||
|
t_invoice[0],
|
||||||
|
`FAIL TO RETRY WITH SAP ERR: ${resSAP.message}`,
|
||||||
|
118,
|
||||||
|
trx
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// update posting et
|
// update posting et
|
||||||
|
|
||||||
return {
|
return {
|
||||||
invoice : t_invoice,
|
invoice: t_invoice,
|
||||||
load_balance : t_load_balance,
|
load_balance: t_load_balance,
|
||||||
posting_et : posting_et
|
posting_et: posting_et,
|
||||||
}
|
};
|
||||||
|
};
|
||||||
}
|
|
||||||
|
|
||||||
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 : i_log_name,
|
// i_log_name : 102,
|
||||||
d_log : trx.raw('NOW()'),
|
i_log_name: i_log_name,
|
||||||
c_invoice_no : data?.c_invoice_no || '',
|
d_log: trx.raw("NOW()"),
|
||||||
c_partner_name : data?.c_partner_name || '',
|
c_invoice_no: data?.c_invoice_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 || 0,
|
d_created: trx.raw("NOW()"),
|
||||||
m_mdr_amount : 0,
|
m_amount: data?.amount || 0,
|
||||||
m_mdr_net : data?.amount || 0
|
m_mdr_amount: 0,
|
||||||
|
m_mdr_net: data?.amount || 0,
|
||||||
|
},
|
||||||
|
["i_log_name", "c_note"]
|
||||||
|
);
|
||||||
|
|
||||||
}, ['i_log_name', 'c_note'])
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
return result
|
const getParameterSetting = async (trx, code) => {
|
||||||
|
const result = await trx("public.t_m_global_parameter_sap AS tmgps")
|
||||||
|
.select(["c_value"])
|
||||||
|
.where("c_code", "=", code)
|
||||||
|
.where("c_status", "=", "A")
|
||||||
|
.first();
|
||||||
|
|
||||||
}
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
const getParameterSetting = async(trx, code) => {
|
const getInvoice = async (code, trx) => {
|
||||||
|
const result = await trx("payment.t_d_invoice")
|
||||||
|
.where("c_invoice_no", "=", code)
|
||||||
|
.first();
|
||||||
|
|
||||||
const result = await trx('public.t_m_global_parameter_sap AS tmgps').select([
|
return result;
|
||||||
"c_value"
|
};
|
||||||
])
|
|
||||||
.where('c_code', '=', code)
|
|
||||||
.where('c_status', '=', "A")
|
|
||||||
.first()
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
const getInvoice = async(code, trx) => {
|
|
||||||
|
|
||||||
const result = await trx('payment.t_d_invoice')
|
|
||||||
.where('c_invoice_no', '=', code)
|
|
||||||
.first()
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
generateInvoice,
|
generateInvoice,
|
||||||
@@ -250,5 +322,5 @@ module.exports = {
|
|||||||
getPostingEt,
|
getPostingEt,
|
||||||
writePaynentHistory,
|
writePaynentHistory,
|
||||||
getParameterSetting,
|
getParameterSetting,
|
||||||
getInvoice
|
getInvoice,
|
||||||
};
|
};
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,5 @@
|
|||||||
const knex = require('../../../infrastructure/database/knex');
|
const knex = require('../../../infrastructure/database/knex');
|
||||||
|
const winston = require('../../helpers/winston.logger');
|
||||||
|
|
||||||
// CHECK CARD NUMBER
|
// CHECK CARD NUMBER
|
||||||
const checkCardNumber = (cardNumber) => {
|
const checkCardNumber = (cardNumber) => {
|
||||||
@@ -56,6 +57,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')
|
||||||
@@ -109,7 +119,24 @@ const getReservationPendingV2 = (cardNumber, time, flag) => {
|
|||||||
|
|
||||||
// GET RESERVATION PENDING WITH COMPARE FLAG COUNTER
|
// GET RESERVATION PENDING WITH COMPARE FLAG COUNTER
|
||||||
const getReservationPendingWithFlagCounter = (cardNumber, time, flag) => {
|
const getReservationPendingWithFlagCounter = (cardNumber, time, flag) => {
|
||||||
let result = knex('trx.t_d_reservation_balance')
|
let result
|
||||||
|
if (flag == '0' || flag == 0) {
|
||||||
|
result = knex('trx.t_d_reservation_balance')
|
||||||
|
// .sum("i_reservation_amount as total_reservation_amount")
|
||||||
|
// .count("* as total_reservation")
|
||||||
|
.select(
|
||||||
|
'i_reservation_amount',
|
||||||
|
'c_reservation_no',
|
||||||
|
'c_flag',
|
||||||
|
'c_load_balance_no'
|
||||||
|
)
|
||||||
|
.where('c_card_number', cardNumber)
|
||||||
|
.whereIn('c_status', ['P', 'I'])
|
||||||
|
.whereRaw('??::INT <= ??', ['c_flag', parseInt(255)])
|
||||||
|
// .where("d_expired", ">=", time)
|
||||||
|
.where('c_flag', '!=', '-1');
|
||||||
|
} else {
|
||||||
|
result = knex('trx.t_d_reservation_balance')
|
||||||
// .sum("i_reservation_amount as total_reservation_amount")
|
// .sum("i_reservation_amount as total_reservation_amount")
|
||||||
// .count("* as total_reservation")
|
// .count("* as total_reservation")
|
||||||
.select(
|
.select(
|
||||||
@@ -123,6 +150,8 @@ const getReservationPendingWithFlagCounter = (cardNumber, time, flag) => {
|
|||||||
.whereRaw('??::INT < ??', ['c_flag', parseInt(flag)])
|
.whereRaw('??::INT < ??', ['c_flag', parseInt(flag)])
|
||||||
// .where("d_expired", ">=", time)
|
// .where("d_expired", ">=", time)
|
||||||
.where('c_flag', '!=', '-1');
|
.where('c_flag', '!=', '-1');
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -291,11 +320,11 @@ const insertLoadingBalance = async (
|
|||||||
.insert(data)
|
.insert(data)
|
||||||
.returning('i_load_balance')
|
.returning('i_load_balance')
|
||||||
.then((resp) => {
|
.then((resp) => {
|
||||||
let id = resp[0];
|
let id = typeof resp[0] === 'object' ? resp[0].i_load_balance : resp[0];
|
||||||
let loadDetail = [];
|
let loadDetail = [];
|
||||||
detail.forEach((element) => {
|
detail.forEach((element) => {
|
||||||
loadDetail.push({
|
loadDetail.push({
|
||||||
i_load_balance: id,
|
i_load_balance: id ? id : id.i_load_balance,
|
||||||
i_reservation_balance: element.i_reservation_balance,
|
i_reservation_balance: element.i_reservation_balance,
|
||||||
c_reservation_no: element.c_reservation_no,
|
c_reservation_no: element.c_reservation_no,
|
||||||
i_amount: element.i_amount,
|
i_amount: element.i_amount,
|
||||||
@@ -323,11 +352,11 @@ const insertLoadingBalance = async (
|
|||||||
.insert(data);
|
.insert(data);
|
||||||
})
|
})
|
||||||
.then((history) => {
|
.then((history) => {
|
||||||
let id = history[0];
|
let id = typeof history[0] === 'object' ? history[0].i_load_balance : history[0];
|
||||||
let loadDetail = [];
|
let loadDetail = [];
|
||||||
detail.forEach((element) => {
|
detail.forEach((element) => {
|
||||||
loadDetail.push({
|
loadDetail.push({
|
||||||
i_load_balance: id,
|
i_load_balance: id ? id : id.i_load_balance,
|
||||||
i_reservation_balance: element.i_reservation_balance,
|
i_reservation_balance: element.i_reservation_balance,
|
||||||
c_reservation_no: element.c_reservation_no,
|
c_reservation_no: element.c_reservation_no,
|
||||||
i_amount: element.i_amount,
|
i_amount: element.i_amount,
|
||||||
@@ -384,14 +413,23 @@ const insertLoadingBalance = async (
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(trx.commit)
|
.then(trx.commit)
|
||||||
.catch(trx.rollback);
|
.catch((error) => {
|
||||||
|
console.log("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS");
|
||||||
|
console.log(error);
|
||||||
|
|
||||||
|
trx.rollback
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
// console.log(result);
|
// console.log("result insertLoadingBalance", result);
|
||||||
|
winston.logger.debug(`XXXXXXXXXXX1 : ${result}`);
|
||||||
|
winston.logger.debug(`XXXXXXXXXXX2 : ${JSON.stringify(result)}`);
|
||||||
return result.rowCount;
|
return result.rowCount;
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
// console.log(error.message);
|
// console.log("error.message insertLoadingBalance", error.message);
|
||||||
|
winston.logger.debug(`YYYYYYYYYYY1 : ${error}`);
|
||||||
|
winston.logger.debug(`YYYYYYYYYYY2 : ${JSON.stringify(error)}`);
|
||||||
return error.message;
|
return error.message;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -490,7 +528,7 @@ const insertLoadingBalanceHistoryOnly = async (
|
|||||||
let loadDetail = [];
|
let loadDetail = [];
|
||||||
detail.forEach((element) => {
|
detail.forEach((element) => {
|
||||||
loadDetail.push({
|
loadDetail.push({
|
||||||
i_load_balance: id,
|
i_load_balance: id.i_load_balance,
|
||||||
i_reservation_balance: element.i_reservation_balance,
|
i_reservation_balance: element.i_reservation_balance,
|
||||||
c_reservation_no: element.c_reservation_no,
|
c_reservation_no: element.c_reservation_no,
|
||||||
i_amount: element.i_amount,
|
i_amount: element.i_amount,
|
||||||
@@ -614,17 +652,34 @@ const updateReservationAndLoadingBalance = async (
|
|||||||
.where('c_load_balance_no', data.c_load_balance_no)
|
.where('c_load_balance_no', data.c_load_balance_no)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// insert load balance history
|
// insert load balance history
|
||||||
|
// winston.logger.debug(
|
||||||
|
// `${reservationNumber} proses insert t_d_load_balance_history updateReservationAndLoadingBalance`
|
||||||
|
// );
|
||||||
return knex('trx.t_d_load_balance_history')
|
return knex('trx.t_d_load_balance_history')
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
.returning('i_load_balance')
|
.returning('i_load_balance')
|
||||||
.insert(data);
|
.insert(data);
|
||||||
})
|
})
|
||||||
.then((history) => {
|
.then((history) => {
|
||||||
|
// winston.logger.debug(
|
||||||
|
// `${JSON.stringify(history)} history t_d_load_balance_history_detail`
|
||||||
|
// );
|
||||||
|
// winston.logger.debug(
|
||||||
|
// `${JSON.stringify(
|
||||||
|
// history[0]
|
||||||
|
// )} id t_d_load_balance_history_detail before parseint`
|
||||||
|
// );
|
||||||
let id = history[0];
|
let id = history[0];
|
||||||
|
// winston.logger.debug(
|
||||||
|
// `${id} id t_d_load_balance_history_detail id only`
|
||||||
|
// );
|
||||||
|
// winston.logger.debug(
|
||||||
|
// `${id.i_load_balance} id t_d_load_balance_history_detail id.i_load_balance`
|
||||||
|
// );
|
||||||
let loadDetail = [];
|
let loadDetail = [];
|
||||||
detail.forEach((element) => {
|
detail.forEach((element) => {
|
||||||
loadDetail.push({
|
loadDetail.push({
|
||||||
i_load_balance: id,
|
i_load_balance: id.i_load_balance,
|
||||||
i_reservation_balance: element.i_reservation_balance,
|
i_reservation_balance: element.i_reservation_balance,
|
||||||
c_reservation_no: element.c_reservation_no,
|
c_reservation_no: element.c_reservation_no,
|
||||||
i_amount: element.i_amount,
|
i_amount: element.i_amount,
|
||||||
@@ -639,6 +694,11 @@ const updateReservationAndLoadingBalance = async (
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// winston.logger.debug(
|
||||||
|
// `${reservationNumber} proses insert t_d_load_balance_history_detail updateReservationAndLoadingBalance: ${JSON.stringify(
|
||||||
|
// loadDetail
|
||||||
|
// )}`
|
||||||
|
// );
|
||||||
// insert detail load balance
|
// insert detail load balance
|
||||||
return knex('trx.t_d_load_balance_history_detail')
|
return knex('trx.t_d_load_balance_history_detail')
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
@@ -646,6 +706,9 @@ const updateReservationAndLoadingBalance = async (
|
|||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// update reservation
|
// update reservation
|
||||||
|
// winston.logger.debug(
|
||||||
|
// `${reservationNumber} proses update t_d_reservation_balance updateReservationAndLoadingBalance`
|
||||||
|
// );
|
||||||
return knex('trx.t_d_reservation_balance')
|
return knex('trx.t_d_reservation_balance')
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
.update({
|
.update({
|
||||||
@@ -662,16 +725,31 @@ const updateReservationAndLoadingBalance = async (
|
|||||||
})
|
})
|
||||||
.whereIn('c_reservation_no', reservationNumber);
|
.whereIn('c_reservation_no', reservationNumber);
|
||||||
})
|
})
|
||||||
.then(trx.commit)
|
.then(() => {
|
||||||
.catch(trx.rollback);
|
// winston.logger.debug(`${reservationNumber} commit transaction`);
|
||||||
|
trx.commit();
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
winston.logger.debug(
|
||||||
|
`${reservationNumber} rollback transaction: ${error.message}`
|
||||||
|
);
|
||||||
|
trx.rollback(); // Rollback transaction
|
||||||
|
// throw error; // Rethrow error to outer catch
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
|
// winston.logger.debug(
|
||||||
|
// `${reservationNumber} result success ${JSON.stringify(result)}}`
|
||||||
|
// );
|
||||||
// console.log(result);
|
// console.log(result);
|
||||||
return result.rowCount;
|
return true;
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
winston.logger.debug(
|
||||||
|
`${reservationNumber} result error: ${error.message}`
|
||||||
|
);
|
||||||
// console.log(error.message);
|
// console.log(error.message);
|
||||||
return error.message;
|
return false;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -861,6 +939,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 +959,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 +992,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(
|
||||||
@@ -982,7 +1090,7 @@ const updateReservationAndInsertLoadingBalance = async (
|
|||||||
let loadDetail = [];
|
let loadDetail = [];
|
||||||
detailLoadBalance.forEach((element) => {
|
detailLoadBalance.forEach((element) => {
|
||||||
loadDetail.push({
|
loadDetail.push({
|
||||||
i_load_balance: id,
|
i_load_balance: id.i_load_balance,
|
||||||
i_reservation_balance: element.i_reservation_balance,
|
i_reservation_balance: element.i_reservation_balance,
|
||||||
c_reservation_no: element.c_reservation_no,
|
c_reservation_no: element.c_reservation_no,
|
||||||
i_amount: element.i_reservation_amount,
|
i_amount: element.i_reservation_amount,
|
||||||
@@ -1047,6 +1155,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,369 @@
|
|||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getCardReplacementScheduler = async () => {
|
||||||
|
const today = new Date().toISOString().split('T')[0]; // Format: 'YYYY-MM-DD'
|
||||||
|
|
||||||
|
const result = await knex('trx.t_d_card_replacement')
|
||||||
|
.select('c_card_no')
|
||||||
|
.where('i_last_balance', null)
|
||||||
|
.where('d_valid_date', '>=', today);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
// GET IS CARD SALES
|
||||||
|
const getCardSales = (card_number) => {
|
||||||
|
let result = knex('trx.t_d_sales_kmt_temp')
|
||||||
|
.select()
|
||||||
|
.where('card_number', card_number)
|
||||||
|
.orderBy('i_sales_kmt_temp', '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;
|
||||||
|
};
|
||||||
|
|
||||||
|
// UPDATE CARD REPLACEMENT BY CARD NUMBER
|
||||||
|
const updateReplacementByCardNumber = async (card_number, dataReplacement) => {
|
||||||
|
let result = await knex('trx.t_d_card_replacement')
|
||||||
|
.update(dataReplacement, ['*'])
|
||||||
|
.where({ c_card_no: card_number });
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
// UPDATE CARD SALES
|
||||||
|
const updateSales = async (i_sales_kmt_temp, dataSales) => {
|
||||||
|
let result = await knex('trx.t_d_sales_kmt_temp')
|
||||||
|
.update(dataSales, ['*'])
|
||||||
|
.where({ i_sales_kmt_temp: i_sales_kmt_temp });
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
const insertReplacementDetail = async (dataReplacement) => {
|
||||||
|
let result = await knex("trx.t_d_card_replacement_detail").insert(dataReplacement);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
const insertSales = async (dataSales) => {
|
||||||
|
let result = await knex("trx.t_d_sales_kmt_temp").insert(dataSales);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getPPNCardSales = async () => {
|
||||||
|
let result = await knex('public.t_m_global_parameter')
|
||||||
|
.select('c_value')
|
||||||
|
.where('c_code', 'CARD_SALES_TAX')
|
||||||
|
.where('c_status', 'A')
|
||||||
|
.first();
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
const completingDataSalesInternal = async (ppn) => {
|
||||||
|
let result
|
||||||
|
await knex.transaction(async (trx) => {
|
||||||
|
try {
|
||||||
|
await trx.raw(`
|
||||||
|
UPDATE trx.t_d_sales_internal AS trx
|
||||||
|
SET
|
||||||
|
c_material_number_sap = subquery.c_material_number_sap,
|
||||||
|
i_card_theme = subquery.i_card_theme,
|
||||||
|
i_tax_amount = subquery.tax,
|
||||||
|
is_complete = subquery.is_complete
|
||||||
|
FROM (
|
||||||
|
SELECT DISTINCT ON (trx.t_d_sales_internal.c_card_number, t_m_card_theme.c_card_type_code, t_m_card_theme.c_card_digit_key, t_m_card_theme.c_variant_code)
|
||||||
|
trx.t_d_sales_internal.c_card_number,
|
||||||
|
t_m_card_theme.i_card_theme,
|
||||||
|
t_m_card_theme.c_material_number_sap,
|
||||||
|
trx.t_d_sales_internal.i_card_price AS card_selling_price,
|
||||||
|
ROUND(trx.t_d_sales_internal.i_card_price * 100 / (100 + ${ppn}::float)) AS card_price_before_tax,
|
||||||
|
ROUND((${ppn}::float / 100::float) * (ROUND(trx.t_d_sales_internal.i_card_price * 100 / (100 + ${ppn}::float)))) AS tax,
|
||||||
|
CASE
|
||||||
|
WHEN trx.t_d_sales_internal.c_category = 'S' THEN true
|
||||||
|
ELSE false
|
||||||
|
END is_complete
|
||||||
|
FROM trx.t_d_sales_internal
|
||||||
|
JOIN public.t_m_card_theme ON
|
||||||
|
SUBSTRING(trx.t_d_sales_internal.c_card_number, 1, 1) = t_m_card_theme.c_card_type_code
|
||||||
|
AND SUBSTRING(trx.t_d_sales_internal.c_card_number, 2, 2) = t_m_card_theme.c_card_digit_key
|
||||||
|
AND SUBSTRING(trx.t_d_sales_internal.c_card_number, 4, 1) = t_m_card_theme.c_variant_code
|
||||||
|
AND SUBSTRING(trx.t_d_sales_internal.c_card_number, 7, 2) = RIGHT(t_m_card_theme.i_year::text, 2)
|
||||||
|
WHERE
|
||||||
|
trx.t_d_sales_internal.is_complete is not true
|
||||||
|
AND trx.t_d_sales_internal.i_card_price > 0
|
||||||
|
AND trx.t_d_sales_internal.i_sales_invoice_internal is null
|
||||||
|
ORDER BY
|
||||||
|
trx.t_d_sales_internal.c_card_number,
|
||||||
|
t_m_card_theme.c_card_type_code,
|
||||||
|
t_m_card_theme.c_card_digit_key,
|
||||||
|
t_m_card_theme.c_variant_code,
|
||||||
|
t_m_card_theme.i_year DESC,
|
||||||
|
trx.t_d_sales_internal.d_create ASC
|
||||||
|
) AS subquery
|
||||||
|
WHERE
|
||||||
|
trx.c_card_number = subquery.c_card_number
|
||||||
|
AND trx.i_sales_invoice_internal IS NULL
|
||||||
|
`);
|
||||||
|
|
||||||
|
await trx.raw(`
|
||||||
|
UPDATE trx.t_d_sales_internal AS trx
|
||||||
|
SET
|
||||||
|
c_old_material_number_sap = subquery.c_material_number_sap,
|
||||||
|
i_old_card_theme = subquery.i_card_theme,
|
||||||
|
i_old_tax_amount = subquery.tax,
|
||||||
|
is_complete = subquery.is_complete
|
||||||
|
FROM (
|
||||||
|
SELECT DISTINCT ON (trx.t_d_sales_internal.c_old_card_number, t_m_card_theme.c_card_type_code, t_m_card_theme.c_card_digit_key, t_m_card_theme.c_variant_code)
|
||||||
|
trx.t_d_sales_internal.c_old_card_number,
|
||||||
|
t_m_card_theme.i_card_theme,
|
||||||
|
t_m_card_theme.c_material_number_sap,
|
||||||
|
trx.t_d_sales_internal.i_old_card_price AS card_selling_price,
|
||||||
|
ROUND(trx.t_d_sales_internal.i_old_card_price * 100 / (100 + ${ppn}::float)) AS card_price_before_tax,
|
||||||
|
ROUND((${ppn}::float / 100::float) * (ROUND(trx.t_d_sales_internal.i_old_card_price * 100 / (100 + ${ppn}::float)))) AS tax,
|
||||||
|
CASE
|
||||||
|
WHEN trx.t_d_sales_internal.c_category = 'S' THEN true
|
||||||
|
WHEN trx.t_d_sales_internal.c_category IN ('N', 'W') THEN true
|
||||||
|
ELSE false
|
||||||
|
END is_complete
|
||||||
|
FROM trx.t_d_sales_internal
|
||||||
|
JOIN public.t_m_card_theme ON
|
||||||
|
SUBSTRING(trx.t_d_sales_internal.c_old_card_number, 1, 1) = t_m_card_theme.c_card_type_code
|
||||||
|
AND SUBSTRING(trx.t_d_sales_internal.c_old_card_number, 2, 2) = t_m_card_theme.c_card_digit_key
|
||||||
|
AND SUBSTRING(trx.t_d_sales_internal.c_old_card_number, 4, 1) = t_m_card_theme.c_variant_code
|
||||||
|
AND SUBSTRING(trx.t_d_sales_internal.c_old_card_number, 7, 2) = RIGHT(t_m_card_theme.i_year::text, 2)
|
||||||
|
WHERE
|
||||||
|
trx.t_d_sales_internal.is_complete is not true
|
||||||
|
AND trx.t_d_sales_internal.i_old_card_price > 0
|
||||||
|
AND trx.t_d_sales_internal.c_category IN ('N', 'W')
|
||||||
|
AND trx.t_d_sales_internal.i_sales_invoice_internal is null
|
||||||
|
ORDER BY
|
||||||
|
trx.t_d_sales_internal.c_old_card_number,
|
||||||
|
t_m_card_theme.c_card_type_code,
|
||||||
|
t_m_card_theme.c_card_digit_key,
|
||||||
|
t_m_card_theme.c_variant_code,
|
||||||
|
t_m_card_theme.i_year DESC,
|
||||||
|
trx.t_d_sales_internal.d_create ASC
|
||||||
|
) AS subquery
|
||||||
|
WHERE
|
||||||
|
trx.c_old_card_number = subquery.c_old_card_number
|
||||||
|
AND trx.i_sales_invoice_internal IS NULL
|
||||||
|
`);
|
||||||
|
|
||||||
|
await trx.commit();
|
||||||
|
|
||||||
|
result = {
|
||||||
|
success: true,
|
||||||
|
message: 'Berhasil update data sales internal.'
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
await trx.rollback();
|
||||||
|
result = {
|
||||||
|
success: false,
|
||||||
|
message: `Gagal update data sales internal: ${error.message}`
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
const completingDataSalesNewCard = async (ppn) => {
|
||||||
|
return await knex.raw(`
|
||||||
|
UPDATE trx.t_d_sales_internal AS trx
|
||||||
|
SET
|
||||||
|
c_material_number_sap = subquery.c_material_number_sap,
|
||||||
|
i_card_theme = subquery.i_card_theme,
|
||||||
|
i_tax_amount = subquery.tax,
|
||||||
|
is_complete = subquery.is_complete
|
||||||
|
FROM (
|
||||||
|
SELECT DISTINCT ON (trx.t_d_sales_internal.c_card_number, t_m_card_theme.c_card_type_code, t_m_card_theme.c_card_digit_key, t_m_card_theme.c_variant_code)
|
||||||
|
trx.t_d_sales_internal.c_card_number,
|
||||||
|
t_m_card_theme.i_card_theme,
|
||||||
|
t_m_card_theme.c_material_number_sap,
|
||||||
|
trx.t_d_sales_internal.i_card_price AS card_selling_price,
|
||||||
|
ROUND(trx.t_d_sales_internal.i_card_price * 100 / (100 + ${ppn}::float)) AS card_price_before_tax,
|
||||||
|
ROUND((${ppn}::float / 100::float) * (ROUND(trx.t_d_sales_internal.i_card_price * 100 / (100 + ${ppn}::float)))) AS tax,
|
||||||
|
CASE
|
||||||
|
WHEN trx.t_d_sales_internal.c_category = 'S' THEN true
|
||||||
|
ELSE false
|
||||||
|
END is_complete
|
||||||
|
FROM trx.t_d_sales_internal
|
||||||
|
JOIN public.t_m_card_theme ON
|
||||||
|
SUBSTRING(trx.t_d_sales_internal.c_card_number, 1, 1) = t_m_card_theme.c_card_type_code
|
||||||
|
AND SUBSTRING(trx.t_d_sales_internal.c_card_number, 2, 2) = t_m_card_theme.c_card_digit_key
|
||||||
|
AND SUBSTRING(trx.t_d_sales_internal.c_card_number, 4, 1) = t_m_card_theme.c_variant_code
|
||||||
|
AND SUBSTRING(trx.t_d_sales_internal.c_card_number, 7, 2) = RIGHT(t_m_card_theme.i_year::text, 2)
|
||||||
|
WHERE
|
||||||
|
trx.t_d_sales_internal.is_complete is not true
|
||||||
|
AND trx.t_d_sales_internal.i_card_price > 0
|
||||||
|
AND trx.t_d_sales_internal.i_sales_invoice_internal is null
|
||||||
|
ORDER BY
|
||||||
|
trx.t_d_sales_internal.c_card_number,
|
||||||
|
t_m_card_theme.c_card_type_code,
|
||||||
|
t_m_card_theme.c_card_digit_key,
|
||||||
|
t_m_card_theme.c_variant_code,
|
||||||
|
t_m_card_theme.i_year DESC,
|
||||||
|
trx.t_d_sales_internal.d_create ASC
|
||||||
|
) AS subquery
|
||||||
|
WHERE
|
||||||
|
trx.c_card_number = subquery.c_card_number
|
||||||
|
AND trx.i_sales_invoice_internal IS NULL
|
||||||
|
`);
|
||||||
|
};
|
||||||
|
|
||||||
|
const completingDataSalesOldCard = async (ppn) => {
|
||||||
|
return await knex.raw(`
|
||||||
|
UPDATE trx.t_d_sales_internal AS trx
|
||||||
|
SET
|
||||||
|
c_old_material_number_sap = subquery.c_material_number_sap,
|
||||||
|
i_old_card_theme = subquery.i_card_theme,
|
||||||
|
i_old_tax_amount = subquery.tax
|
||||||
|
FROM (
|
||||||
|
SELECT DISTINCT ON (trx.t_d_sales_internal.c_old_card_number, t_m_card_theme.c_card_type_code, t_m_card_theme.c_card_digit_key, t_m_card_theme.c_variant_code)
|
||||||
|
trx.t_d_sales_internal.c_old_card_number,
|
||||||
|
t_m_card_theme.i_card_theme,
|
||||||
|
t_m_card_theme.c_material_number_sap,
|
||||||
|
trx.t_d_sales_internal.i_old_card_price AS card_selling_price,
|
||||||
|
ROUND(trx.t_d_sales_internal.i_old_card_price * 100 / (100 + ${ppn}::float)) AS card_price_before_tax,
|
||||||
|
ROUND((${ppn}::float / 100::float) * (ROUND(trx.t_d_sales_internal.i_old_card_price * 100 / (100 + ${ppn}::float)))) AS tax,
|
||||||
|
CASE
|
||||||
|
WHEN trx.t_d_sales_internal.c_category = 'S' THEN true
|
||||||
|
WHEN trx.t_d_sales_internal.c_category IN ('N', 'W') THEN true
|
||||||
|
ELSE false
|
||||||
|
END is_complete
|
||||||
|
FROM trx.t_d_sales_internal
|
||||||
|
JOIN public.t_m_card_theme ON
|
||||||
|
SUBSTRING(trx.t_d_sales_internal.c_old_card_number, 1, 1) = t_m_card_theme.c_card_type_code
|
||||||
|
AND SUBSTRING(trx.t_d_sales_internal.c_old_card_number, 2, 2) = t_m_card_theme.c_card_digit_key
|
||||||
|
AND SUBSTRING(trx.t_d_sales_internal.c_old_card_number, 4, 1) = t_m_card_theme.c_variant_code
|
||||||
|
AND SUBSTRING(trx.t_d_sales_internal.c_old_card_number, 7, 2) = RIGHT(t_m_card_theme.i_year::text, 2)
|
||||||
|
WHERE
|
||||||
|
trx.t_d_sales_internal.is_complete is not true
|
||||||
|
AND trx.t_d_sales_internal.i_old_card_price > 0
|
||||||
|
AND trx.t_d_sales_internal.c_category IN ('N', 'W')
|
||||||
|
AND trx.t_d_sales_internal.i_sales_invoice_internal is null
|
||||||
|
ORDER BY
|
||||||
|
trx.t_d_sales_internal.c_old_card_number,
|
||||||
|
t_m_card_theme.c_card_type_code,
|
||||||
|
t_m_card_theme.c_card_digit_key,
|
||||||
|
t_m_card_theme.c_variant_code,
|
||||||
|
t_m_card_theme.i_year DESC,
|
||||||
|
trx.t_d_sales_internal.d_create ASC
|
||||||
|
) AS subquery
|
||||||
|
WHERE
|
||||||
|
trx.c_old_card_number = subquery.c_old_card_number
|
||||||
|
AND trx.i_sales_invoice_internal IS NULL
|
||||||
|
`);
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateDataSalesIsComplete = async () => {
|
||||||
|
return await knex.raw(`
|
||||||
|
UPDATE trx.t_d_sales_internal SET is_complete = true
|
||||||
|
WHERE
|
||||||
|
is_complete is not true
|
||||||
|
AND c_material_number_sap is not null
|
||||||
|
AND i_tax_amount is not null
|
||||||
|
AND c_old_material_number_sap is not null
|
||||||
|
AND i_old_tax_amount is not null
|
||||||
|
AND c_category IN ('N', 'W')
|
||||||
|
`);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getCardBlacklist,
|
||||||
|
getCardReplacement,
|
||||||
|
getCardProduct,
|
||||||
|
getGlobalParameterData,
|
||||||
|
getLastBalanceFromCardHistory,
|
||||||
|
getAccumulationBalanceInThisMonthFromCardHistory,
|
||||||
|
updateReplacement,
|
||||||
|
insertReplacementDetail,
|
||||||
|
insertSales,
|
||||||
|
getCardSales,
|
||||||
|
updateSales,
|
||||||
|
getCardReplacementScheduler,
|
||||||
|
updateReplacementByCardNumber,
|
||||||
|
getPPNCardSales,
|
||||||
|
completingDataSalesInternal,
|
||||||
|
completingDataSalesNewCard,
|
||||||
|
completingDataSalesOldCard,
|
||||||
|
updateDataSalesIsComplete,
|
||||||
|
};
|
||||||
@@ -0,0 +1,219 @@
|
|||||||
|
const { param, body, validationResult } = require('express-validator');
|
||||||
|
const helper = require('../../helpers/helper');
|
||||||
|
const winston = require('../../helpers/winston.logger');
|
||||||
|
const model = require('./refundkmt.model');
|
||||||
|
const moment = require('moment');
|
||||||
|
moment.locale('id');
|
||||||
|
|
||||||
|
// VALIDATION
|
||||||
|
const validate = (method) => {
|
||||||
|
switch (method) {
|
||||||
|
case 'callbackOy':
|
||||||
|
return [
|
||||||
|
body('partner_trx_id')
|
||||||
|
.not()
|
||||||
|
.isEmpty()
|
||||||
|
.withMessage('Partner Trx Id is required'),
|
||||||
|
body('trx_id').not().isEmpty().withMessage('Trx Id is required'),
|
||||||
|
body('amount').not().isEmpty().withMessage('Amount is required'),
|
||||||
|
body('recipient_bank')
|
||||||
|
.not()
|
||||||
|
.isEmpty()
|
||||||
|
.withMessage('Recipient Bank is required'),
|
||||||
|
body('recipient_account')
|
||||||
|
.not()
|
||||||
|
.isEmpty()
|
||||||
|
.withMessage('Recipient Account is required'),
|
||||||
|
];
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const callbackOy = async (req, res) => {
|
||||||
|
try {
|
||||||
|
// generate unique code
|
||||||
|
// unique code ini digunakan untuk keperluan log agar mudah untuk dibaca
|
||||||
|
let uniqueCode = helper.getUniqueCode();
|
||||||
|
let result = {};
|
||||||
|
|
||||||
|
// param
|
||||||
|
let {
|
||||||
|
status,
|
||||||
|
amount,
|
||||||
|
recipient_name,
|
||||||
|
recipient_bank,
|
||||||
|
recipient_account,
|
||||||
|
trx_id,
|
||||||
|
partner_trx_id,
|
||||||
|
timestamp,
|
||||||
|
created_date,
|
||||||
|
last_updated_date,
|
||||||
|
} = req.body;
|
||||||
|
|
||||||
|
// log info
|
||||||
|
winston.logger.info(
|
||||||
|
`${uniqueCode} [ REQUEST REFUND-KMT ]: ${JSON.stringify(req.body)}`
|
||||||
|
);
|
||||||
|
|
||||||
|
// check validator
|
||||||
|
let err = validationResult(req, res);
|
||||||
|
if (!err.isEmpty()) {
|
||||||
|
result = {
|
||||||
|
code: '400',
|
||||||
|
message: err.errors[0].msg,
|
||||||
|
data: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
// log warn
|
||||||
|
winston.logger.warn(
|
||||||
|
`${uniqueCode} [ RESPONSE REFUND-KMT ]: ${JSON.stringify(result)}`
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.status(200).json(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// time
|
||||||
|
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||||
|
winston.logger.warn(
|
||||||
|
`${uniqueCode} [ RESPONSE REFUND-KMT ]: ${JSON.stringify(result)}`
|
||||||
|
);
|
||||||
|
|
||||||
|
let recipient_bank_code = recipient_bank.toUpperCase();
|
||||||
|
// check trx_id yang di request match
|
||||||
|
let checkRequest = await model.checkRedeem(
|
||||||
|
partner_trx_id,
|
||||||
|
trx_id,
|
||||||
|
amount,
|
||||||
|
recipient_bank_code,
|
||||||
|
recipient_account
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!checkRequest) {
|
||||||
|
result = {
|
||||||
|
code: '400',
|
||||||
|
message: 'Refund Request Transaction is not found.',
|
||||||
|
data: {},
|
||||||
|
};
|
||||||
|
winston.logger.warn(
|
||||||
|
`${uniqueCode} [ RESPONSE REFUND-KMT ]: ${JSON.stringify(result)}`
|
||||||
|
);
|
||||||
|
return res.status(200).json(result);
|
||||||
|
} else if (checkRequest.c_status?.trim() == 'A') {
|
||||||
|
result = {
|
||||||
|
code: '400',
|
||||||
|
message: 'Refund transaction is already completed.',
|
||||||
|
data: {},
|
||||||
|
};
|
||||||
|
winston.logger.warn(
|
||||||
|
`${uniqueCode} [ RESPONSE REFUND-KMT ]: ${JSON.stringify(result)}`
|
||||||
|
);
|
||||||
|
return res.status(200).json(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
winston.logger.warn(
|
||||||
|
`${uniqueCode} [ checkRequest ]: ${JSON.stringify(checkRequest)}`
|
||||||
|
);
|
||||||
|
|
||||||
|
if (status.code != '000') {
|
||||||
|
result = {
|
||||||
|
code: '400',
|
||||||
|
message: status.message,
|
||||||
|
data: {
|
||||||
|
trx_id: trx_id,
|
||||||
|
partner_trx_id: partner_trx_id,
|
||||||
|
amount: amount,
|
||||||
|
recipient_bank: recipient_bank_code,
|
||||||
|
recipient_account: recipient_account,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const date_reimbursement = moment(last_updated_date, 'DD-MM-YYYY HH:mm:ss').format(
|
||||||
|
'YYYY-MM-DD HH:mm:ss'
|
||||||
|
);
|
||||||
|
|
||||||
|
winston.logger.warn(
|
||||||
|
`${uniqueCode} [ log date_reimbusement ]: ${JSON.stringify(date_reimbursement)}`
|
||||||
|
);
|
||||||
|
|
||||||
|
//Update Card Replacement
|
||||||
|
await model.updateReplacementComplete(
|
||||||
|
checkRequest.i_card_replacement,
|
||||||
|
checkRequest.c_request_no,
|
||||||
|
date_reimbursement
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
//Notif Email
|
||||||
|
let urlCMS = '';
|
||||||
|
if (process.env.SERVER_FOR == 'production') {
|
||||||
|
urlCMS = 'https://cms.kci.id';
|
||||||
|
} else if (process.env.SERVER_FOR == 'development') {
|
||||||
|
urlCMS = 'http://10.20.14.69';
|
||||||
|
} else {
|
||||||
|
urlCMS = 'http://localhost:8000';
|
||||||
|
}
|
||||||
|
|
||||||
|
let axios = require('axios');
|
||||||
|
|
||||||
|
const url = urlCMS + '/api/redeem/notifemail';
|
||||||
|
console.log('urlCMS', url);
|
||||||
|
|
||||||
|
// let resp = await axios.post(url, body, config);
|
||||||
|
const responseMail = await axios({
|
||||||
|
method: 'post',
|
||||||
|
url: url,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
i_card_replacement: checkRequest.i_card_replacement?.trim(),
|
||||||
|
c_request_no: checkRequest.c_request_no?.trim(),
|
||||||
|
c_card_no: checkRequest.c_card_no?.trim(),
|
||||||
|
status: 'complete',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
// console.log('urlCMS', url)
|
||||||
|
|
||||||
|
result = {
|
||||||
|
code: '00',
|
||||||
|
message: 'success',
|
||||||
|
data: {
|
||||||
|
trx_id: trx_id,
|
||||||
|
partner_trx_id: partner_trx_id,
|
||||||
|
amount: amount,
|
||||||
|
recipient_bank: recipient_bank,
|
||||||
|
recipient_account: recipient_account,
|
||||||
|
last_updated_date: last_updated_date,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// log info
|
||||||
|
winston.logger.info(
|
||||||
|
`${uniqueCode} [ RESPONSE REFUND-KMT ]: ${JSON.stringify(result)}`
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.status(200).json(result);
|
||||||
|
} catch (error) {
|
||||||
|
// create log
|
||||||
|
winston.logger.error(
|
||||||
|
`[ RESPONSE REFUND-KMT ]: 500 internal server error - backend server | ${error.message}`
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.status(200).json({
|
||||||
|
code: '500',
|
||||||
|
message:
|
||||||
|
process.env.NODE_ENV != 'production'
|
||||||
|
? error.message
|
||||||
|
: '500 internal server error - backend server.',
|
||||||
|
data: {},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
validate,
|
||||||
|
callbackOy,
|
||||||
|
};
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
const knex = require("../../../infrastructure/database/knex");
|
||||||
|
|
||||||
|
const checkRedeem = (partner_trx_id, trx_id, amount, recipient_bank, recipient_account) => {
|
||||||
|
let result = knex
|
||||||
|
.select(
|
||||||
|
"t_d_card_replacement.i_card_replacement",
|
||||||
|
"t_d_card_replacement.c_request_no",
|
||||||
|
"t_d_card_replacement.c_card_no",
|
||||||
|
"t_d_card_replacement.i_request_disburse",
|
||||||
|
"t_d_card_replacement.c_refund_trx_id",
|
||||||
|
"t_d_card_replacement.c_status"
|
||||||
|
)
|
||||||
|
.from("trx.t_d_card_replacement")
|
||||||
|
// .leftJoin(
|
||||||
|
// "t_m_merchant", "t_m_terminal.c_card_no", "t_m_merchant.i_merchant"
|
||||||
|
// )
|
||||||
|
// .leftJoin("t_m_partner", "t_m_merchant.i_partner", "t_m_partner.i_partner")
|
||||||
|
.where("t_d_card_replacement.c_method", "CASHLESS")
|
||||||
|
// .where("t_d_card_replacement.c_status", "OP")
|
||||||
|
.where("t_d_card_replacement.i_last_balance", amount)
|
||||||
|
.where("t_d_card_replacement.c_request_no", partner_trx_id)
|
||||||
|
.where("t_d_card_replacement.c_refund_trx_id", trx_id)
|
||||||
|
.where("t_d_card_replacement.c_bank_code", recipient_bank)
|
||||||
|
.where("t_d_card_replacement.c_account_number", recipient_account)
|
||||||
|
// .whereNull("t_d_card_replacement.c_status", "OP")
|
||||||
|
.first();
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
// UPDATE REPLACEMENT
|
||||||
|
const updateReplacementComplete = (i_replacement, request_no, date_disburse) => {
|
||||||
|
let result = knex("trx.t_d_card_replacement")
|
||||||
|
.where("i_card_replacement", i_replacement)
|
||||||
|
.where("c_request_no", request_no)
|
||||||
|
// .update({
|
||||||
|
// c_status: "A",
|
||||||
|
// c_status_name: "COMPLETED",
|
||||||
|
// d_disburse: date_disburse,
|
||||||
|
// c_response_code: "000",
|
||||||
|
// c_response_message: "Success"
|
||||||
|
// });
|
||||||
|
.update({
|
||||||
|
c_status: "A",
|
||||||
|
c_status_name: "COMPLETED",
|
||||||
|
d_disburse: date_disburse,
|
||||||
|
c_response_code: "000",
|
||||||
|
c_response_message: "Success"
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
checkRedeem,
|
||||||
|
updateReplacementComplete
|
||||||
|
};
|
||||||
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,27 @@ router.get(
|
|||||||
controller.apiGenerateCahsIn
|
controller.apiGenerateCahsIn
|
||||||
);
|
);
|
||||||
|
|
||||||
|
router.get(
|
||||||
|
"/online/cash-in-sales",
|
||||||
|
// auth.authenticateToken,
|
||||||
|
// controller.validate("generateInvoice"),
|
||||||
|
controller.apiGenerateCashInSales
|
||||||
|
);
|
||||||
|
|
||||||
|
router.get(
|
||||||
|
"/online/cash-in-sales-internal",
|
||||||
|
// auth.authenticateToken,
|
||||||
|
// controller.validate("generateInvoice"),
|
||||||
|
controller.apiGenerateCashInSalesInternal
|
||||||
|
);
|
||||||
|
|
||||||
|
router.get(
|
||||||
|
"/online/cash-in-topup-cashless-internal",
|
||||||
|
// auth.authenticateToken,
|
||||||
|
// controller.validate("generateInvoice"),
|
||||||
|
controller.apiGenerateCashInTopUpCashlessInternal
|
||||||
|
);
|
||||||
|
|
||||||
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;
|
||||||
|
|||||||
@@ -0,0 +1,111 @@
|
|||||||
|
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 Validate Replacement New Card
|
||||||
|
router.post(
|
||||||
|
"/pos/cardreplacement/validatenewcard",
|
||||||
|
auth.authenticateToken,
|
||||||
|
controller.validate("validateNewCardReplacement"),
|
||||||
|
controller.validateNewCardReplacement
|
||||||
|
);
|
||||||
|
|
||||||
|
// API Replacement Confirm
|
||||||
|
router.post(
|
||||||
|
"/pos/cardreplacement/confirm",
|
||||||
|
auth.authenticateToken,
|
||||||
|
controller.validate("cardReplacementConfirm"),
|
||||||
|
controller.replacementConfirm
|
||||||
|
);
|
||||||
|
|
||||||
|
// API Redeem Confirm
|
||||||
|
router.post(
|
||||||
|
"/pos/cardredeem/confirm",
|
||||||
|
auth.authenticateToken,
|
||||||
|
controller.validate("confirmCardRedeem"),
|
||||||
|
controller.confirmRedeem
|
||||||
|
);
|
||||||
|
|
||||||
|
// API Sales Confirm
|
||||||
|
router.post(
|
||||||
|
"/pos/cardsales/confirm",
|
||||||
|
auth.authenticateToken,
|
||||||
|
controller.validate("confirmCardSales"),
|
||||||
|
controller.confirmSales
|
||||||
|
);
|
||||||
|
|
||||||
|
// API Sales Confirm
|
||||||
|
router.post(
|
||||||
|
"/pos/schedulerCTS/lastbalance",
|
||||||
|
auth.authenticateToken,
|
||||||
|
controller.getLastBalanceCTS
|
||||||
|
);
|
||||||
|
|
||||||
|
// API Scheduler Lengkapi Data Sales Internal
|
||||||
|
router.post(
|
||||||
|
"/pos/sales/complete-data",
|
||||||
|
controller.completeDataSalesInternal
|
||||||
|
);
|
||||||
|
|
||||||
|
// API Scheduler Lengkapi Data Sales Internal V2
|
||||||
|
router.post(
|
||||||
|
"/pos/sales/complete-data-v2",
|
||||||
|
controller.completeDataSalesInternalV2
|
||||||
|
);
|
||||||
|
|
||||||
|
// API Test
|
||||||
|
router.post(
|
||||||
|
"/pos/test",
|
||||||
|
controller.testAPI
|
||||||
|
);
|
||||||
|
|
||||||
|
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 = parseInt(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 = parseInt(ports[index]);
|
||||||
|
|
||||||
|
app.listen(port, () => {
|
||||||
|
winston.logger.info(
|
||||||
|
`Server is running on version ${
|
||||||
|
process.env.VERSION
|
||||||
|
} environment: ${process.env.NODE_ENV.toUpperCase()} port: ${port} on ${serverActive}. HSM STATUS : ${serverHSMStatus} `
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (
|
||||||
|
process.env.RUNNING_ON_MULTIPLE_PORT.toUpperCase() == 'YES' &&
|
||||||
|
process.env.CLUSTER_NODE.toUpperCase() == 'YES'
|
||||||
|
) {
|
||||||
|
winston.logger.warn(
|
||||||
|
`If you want running the service on multiple port, please set CLUSTER_NODE = NO in .env file `
|
||||||
);
|
);
|
||||||
});
|
} else if (
|
||||||
|
process.env.CLUSTER_NODE_STICKY_SESSION.toUpperCase() == 'YES' &&
|
||||||
|
process.env.CLUSTER_NODE.toUpperCase() == 'YES'
|
||||||
|
) {
|
||||||
|
winston.logger.warn(
|
||||||
|
`If you want running the service with sticky session, please set CLUSTER_NODE = NO in .env file `
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let message = `Server is running on version ${
|
||||||
|
process.env.VERSION
|
||||||
|
} environment: ${process.env.NODE_ENV.toUpperCase()} port: ${PORT} on ${serverActive}. HSM STATUS : ${serverHSMStatus} `;
|
||||||
|
|
||||||
|
if (process.env.CLUSTER_NODE.toUpperCase() == 'YES') {
|
||||||
|
message = `Server is running with cluster node on version ${
|
||||||
|
process.env.VERSION
|
||||||
|
} environment: ${process.env.NODE_ENV.toUpperCase()} port: ${PORT} on ${serverActive}. HSM STATUS : ${serverHSMStatus} `;
|
||||||
|
} else if (process.env.CLUSTER_NODE_STICKY_SESSION.toUpperCase() == 'YES') {
|
||||||
|
message = `Server is running with sticky session on version ${
|
||||||
|
process.env.VERSION
|
||||||
|
} environment: ${process.env.NODE_ENV.toUpperCase()} port: ${PORT} on ${serverActive}. HSM STATUS : ${serverHSMStatus} `;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.env.CLUSTER_NODE_STICKY_SESSION.toUpperCase() == 'YES') {
|
||||||
|
const server = app.listen(PORT, () => {
|
||||||
|
console.log(
|
||||||
|
`Worker ${process.pid} started. Listening on port ${
|
||||||
|
server.address().port
|
||||||
|
}`
|
||||||
|
);
|
||||||
|
winston.logger.info(message);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Use sticky-session with the server instance
|
||||||
|
sticky.listen(server);
|
||||||
|
} else {
|
||||||
|
app.listen(PORT, () => {
|
||||||
|
winston.logger.info(message);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use sticky-session to handle sticky sessions
|
||||||
|
// if (!sticky.listen(cluster, port)) {
|
||||||
|
// // This is the master process, and it should not be listening to the port
|
||||||
|
// cluster.on('listening', (worker, address) => {
|
||||||
|
// console.log(
|
||||||
|
// `Worker ${worker.id} is now connected to ${address.address}:${address.port}`
|
||||||
|
// );
|
||||||
|
// });
|
||||||
|
|
||||||
|
// cluster.on('exit', (worker) => {
|
||||||
|
// console.log(`Worker ${worker.id} has exited`);
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|||||||
+50
-20
@@ -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 = {
|
||||||
@@ -46,7 +70,10 @@ module.exports = {
|
|||||||
// connection: process.env.DB_URL,
|
// connection: process.env.DB_URL,
|
||||||
pool: {
|
pool: {
|
||||||
min: 2,
|
min: 2,
|
||||||
max: 30,
|
max: 100,
|
||||||
|
idleTimeoutMillis: 30000, // ← Contoh: 30 detik idle timeout
|
||||||
|
acquireTimeoutMillis: 20000, // Maksimal waktu tunggu koneksi dari pool
|
||||||
|
// maxLifetimeMillis: 300000 // maksimal umur koneksi: 5 menit (300.000 ms)
|
||||||
},
|
},
|
||||||
migrations: {
|
migrations: {
|
||||||
directory: './infrastructure/database/migrations',
|
directory: './infrastructure/database/migrations',
|
||||||
@@ -73,7 +100,10 @@ module.exports = {
|
|||||||
// connection: process.env.DB_URL,
|
// connection: process.env.DB_URL,
|
||||||
pool: {
|
pool: {
|
||||||
min: 2,
|
min: 2,
|
||||||
max: 20,
|
max: 100,
|
||||||
|
idleTimeoutMillis: 30000, // ← Contoh: 30 detik idle timeout
|
||||||
|
acquireTimeoutMillis: 20000, // Maksimal waktu tunggu koneksi dari pool
|
||||||
|
// maxLifetimeMillis: 300000 // maksimal umur koneksi: 5 menit (300.000 ms)
|
||||||
},
|
},
|
||||||
migrations: {
|
migrations: {
|
||||||
directory: './infrastructure/database/migrations',
|
directory: './infrastructure/database/migrations',
|
||||||
|
|||||||
Generated
+3177
-9023
File diff suppressed because it is too large
Load Diff
+13
-10
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "topuponline",
|
"name": "onlinetopup-v1",
|
||||||
"version": "1.0.0",
|
"version": "1.6.3",
|
||||||
"description": "",
|
"description": "update packages",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "nodemon index",
|
"start": "nodemon index",
|
||||||
@@ -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,25 +32,28 @@
|
|||||||
"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",
|
||||||
"pm2": "^5.2.0",
|
"pm2": "^6.0.13",
|
||||||
"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",
|
||||||
|
"simple-update-notifier": "^2.0.0",
|
||||||
|
"sticky-session": "^0.1.0",
|
||||||
|
"superagent": "^10.2.3",
|
||||||
"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",
|
||||||
"nodemon": "^2.0.7",
|
"nodemon": "^3.1.10",
|
||||||
"supertest": "^6.2.4"
|
"supertest": "^7.1.3"
|
||||||
},
|
},
|
||||||
"jest": {
|
"jest": {
|
||||||
"testEnvironment": "node",
|
"testEnvironment": "node",
|
||||||
|
|||||||
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