mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-06 02:36:27 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ba9345e0a5 |
@@ -1,25 +1,23 @@
|
||||
require('dotenv').config();
|
||||
const redis = require('redis');
|
||||
const moment = require('moment');
|
||||
moment.locale('id');
|
||||
require("dotenv").config();
|
||||
const redis = require("redis");
|
||||
|
||||
let redisClient;
|
||||
(async () => {
|
||||
let redisUrl = process.env.REDIS_URL || 'redis://127.0.0.1:6379';
|
||||
let redisPass = process.env.REDIS_PASSWORD || '';
|
||||
let redisUrl = process.env.REDIS_URL || "redis://127.0.0.1:6379";
|
||||
let redisPass = process.env.REDIS_PASSWORD || "redispassword";
|
||||
|
||||
redisClient = redis.createClient({
|
||||
url: redisUrl,
|
||||
password: '',
|
||||
password: redisPass,
|
||||
});
|
||||
|
||||
redisClient.on('error', (error) => console.error(`Error : ${error}`));
|
||||
redisClient.on("error", (error) => console.error(`Error : ${error}`));
|
||||
|
||||
redisClient.on('connect', () => console.log('Redis is Connected'));
|
||||
redisClient.on("connect", () => console.log("Redis is Connected"));
|
||||
|
||||
redisClient.on('ready', () => console.log('Redis is Ready'));
|
||||
redisClient.on("ready", () => console.log("Redis is Ready"));
|
||||
|
||||
redisClient.on('reconnecting', () => console.log('Redis is Reconnecting'));
|
||||
redisClient.on("reconnecting", () => console.log("Redis is Reconnecting"));
|
||||
|
||||
await redisClient.connect();
|
||||
})();
|
||||
@@ -29,18 +27,18 @@ const redisMiddleware = async (req, res, next) => {
|
||||
if (!isRedisReady) {
|
||||
next();
|
||||
} else {
|
||||
let getValue = await redisClient.get('cardproduct');
|
||||
let getValue = await redisClient.get("cardproduct");
|
||||
let parsedValue = JSON.parse(getValue);
|
||||
|
||||
if (getValue) {
|
||||
res.status(200).json({
|
||||
code: 200,
|
||||
message: 'Success get from redis',
|
||||
message: "Success get from redis",
|
||||
data: parsedValue,
|
||||
});
|
||||
} else {
|
||||
res.on('finish', async () => {
|
||||
await redisClient.set('cardproduct', JSON.stringify(res.body), {
|
||||
res.on("finish", async () => {
|
||||
await redisClient.set("cardproduct", JSON.stringify(res.body), {
|
||||
EX: 10,
|
||||
NX: false,
|
||||
});
|
||||
@@ -50,69 +48,4 @@ const redisMiddleware = async (req, res, next) => {
|
||||
}
|
||||
};
|
||||
|
||||
const getReservationNumberSequence = async (req, res, next) => {
|
||||
// set default reservation_number_sequence dari partner apapun is null
|
||||
req.reservation_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(
|
||||
'reservation_number_sequence_' + req.partner_id_token
|
||||
);
|
||||
|
||||
if (getValue) {
|
||||
// parsing data menjadi json format
|
||||
let parsedValue = JSON.parse(getValue);
|
||||
|
||||
// cek apakah tanggal sequence yang di redis sama dengan hari ini atau bukan
|
||||
if (parsedValue.date == moment().format('YYYY-MM-DD')) {
|
||||
// jika tanggal nya sama dengan hari ini maka ambil sequence untuk reservation number yang di generate dari redis
|
||||
req.reservation_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(
|
||||
`reservation_number_sequence_${req.partner_id_token}`,
|
||||
JSON.stringify(setValue)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
next();
|
||||
};
|
||||
|
||||
const setReservationNumberSequence = async (partner_id, sequence) => {
|
||||
// cek jika redis is connect
|
||||
let isRedisReady = await redisClient.isReady;
|
||||
// jika tidak connect
|
||||
if (isRedisReady) {
|
||||
// jika connect maka cari sequence dari reservation number sesuai partner yg merequest
|
||||
// format value nya harusnya seperti ini = { date: '2023-01-01', sequence: 1 }
|
||||
|
||||
let setValue = {
|
||||
date: moment().format('YYYY-MM-DD'),
|
||||
sequence: parseInt(sequence),
|
||||
};
|
||||
|
||||
await redisClient.SET(
|
||||
`reservation_number_sequence_${partner_id}`,
|
||||
JSON.stringify(setValue)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
redisMiddleware,
|
||||
getReservationNumberSequence,
|
||||
setReservationNumberSequence,
|
||||
};
|
||||
module.exports = redisMiddleware;
|
||||
|
||||
@@ -1,55 +1,55 @@
|
||||
const { param, body, validationResult } = require("express-validator");
|
||||
const winston = require("../../helpers/winston.logger");
|
||||
const generate = require("./utils/utils");
|
||||
const loadBalance = require("../loadbalance/loadbalance.controller");
|
||||
const { param, body, validationResult } = require('express-validator');
|
||||
const winston = require('../../helpers/winston.logger');
|
||||
const generate = require('./utils/utils');
|
||||
const loadBalance = require('../loadbalance/loadbalance.controller');
|
||||
const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
require("dotenv").config();
|
||||
require('dotenv').config();
|
||||
|
||||
let useClient;
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == "1") {
|
||||
var { client } = require("./services/webSocket");
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '1') {
|
||||
var { client } = require('./services/webSocket');
|
||||
|
||||
useClient = client;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == "2") {
|
||||
var { client2 } = require("./services/webSocket2");
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '2') {
|
||||
var { client2 } = require('./services/webSocket2');
|
||||
|
||||
useClient = client2;
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == "12") {
|
||||
var { client } = require("./services/webSocket");
|
||||
var { client2 } = require("./services/webSocket2");
|
||||
} else if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
var { client } = require('./services/webSocket');
|
||||
var { client2 } = require('./services/webSocket2');
|
||||
}
|
||||
|
||||
// VALIDATION
|
||||
const validate = (method) => {
|
||||
switch (method) {
|
||||
case "topupResponse":
|
||||
case 'topupResponse':
|
||||
return [
|
||||
body("mid").not().isEmpty().withMessage("MID is required"),
|
||||
body("tid").not().isEmpty().withMessage("TID is required"),
|
||||
body("uid").not().isEmpty().withMessage("UID is required"),
|
||||
body("flag").not().isEmpty().withMessage("Flag is required"),
|
||||
body("card_number")
|
||||
body('mid').not().isEmpty().withMessage('MID is required'),
|
||||
body('tid').not().isEmpty().withMessage('TID is required'),
|
||||
body('uid').not().isEmpty().withMessage('UID is required'),
|
||||
body('flag').not().isEmpty().withMessage('Flag is required'),
|
||||
body('card_number')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage("Card Number is required"),
|
||||
body("amount")
|
||||
.withMessage('Card Number is required'),
|
||||
body('amount')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage("Amount is required")
|
||||
.withMessage('Amount is required')
|
||||
.isNumeric()
|
||||
.withMessage("Amount is invalid format"),
|
||||
body("reservation_number")
|
||||
.withMessage('Amount is invalid format'),
|
||||
body('reservation_number')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage("Reservation Number is required")
|
||||
.withMessage('Reservation Number is required')
|
||||
.isArray()
|
||||
.withMessage("Reservation Number is invalid request format"),
|
||||
body("load_balance_number")
|
||||
.withMessage('Reservation Number is invalid request format'),
|
||||
body('load_balance_number')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage("Load Balance Number is required"),
|
||||
.withMessage('Load Balance Number is required'),
|
||||
];
|
||||
default:
|
||||
break;
|
||||
@@ -79,7 +79,7 @@ const controller = async (req, res) => {
|
||||
let result = {};
|
||||
|
||||
// set connection HSM server
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == "12") {
|
||||
if (process.env.NUMBER_SERVER_ACTIVE == '12') {
|
||||
// set request to HSM server 2
|
||||
if (uniqueCode) {
|
||||
if (parseInt(uniqueCode) % 2 == 0) {
|
||||
@@ -119,8 +119,8 @@ const controller = async (req, res) => {
|
||||
let _stopMessage = 1;
|
||||
if (packet[0] != 0x47) {
|
||||
result = {
|
||||
code: "03",
|
||||
message: "Respone Card Wrong",
|
||||
code: '03',
|
||||
message: 'Respone Card Wrong',
|
||||
data: {},
|
||||
};
|
||||
|
||||
@@ -140,7 +140,7 @@ const controller = async (req, res) => {
|
||||
let respData = null;
|
||||
let respData1 = null;
|
||||
|
||||
useClient.ws.on("message", (message) => {
|
||||
useClient.ws.on('message', (message) => {
|
||||
while (
|
||||
message[2] == 5 &&
|
||||
message[0] == transactionId[0] &&
|
||||
@@ -186,7 +186,7 @@ const controller = async (req, res) => {
|
||||
amount: amount,
|
||||
reservation_number: reservation_number,
|
||||
ref_no: ref_no,
|
||||
write_status: "FW",
|
||||
write_status: 'FW',
|
||||
uid: uid,
|
||||
balance: parseInt(balance) + parseInt(amount),
|
||||
flag: parseInt(flag),
|
||||
@@ -203,8 +203,8 @@ const controller = async (req, res) => {
|
||||
await loadBalance.loadingBalanceUpdate(data);
|
||||
|
||||
result = {
|
||||
code: "5002",
|
||||
message: "failed from HSM",
|
||||
code: '5002',
|
||||
message: 'failed from HSM',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respData1.slice(6, 10),
|
||||
@@ -213,6 +213,11 @@ const controller = async (req, res) => {
|
||||
},
|
||||
};
|
||||
} else {
|
||||
// jika sudah mencapai maksimum counting flag, maka reset flag ke awal
|
||||
if (flag >= 255) {
|
||||
flag = -1;
|
||||
}
|
||||
|
||||
data = {
|
||||
mid: mid,
|
||||
tid: tid,
|
||||
@@ -236,10 +241,10 @@ const controller = async (req, res) => {
|
||||
// update data load balance
|
||||
let update = await loadBalance.loadingBalanceUpdate(data);
|
||||
if (update) {
|
||||
if (update.code == "00") {
|
||||
if (update.code == '00') {
|
||||
result = {
|
||||
code: "00",
|
||||
message: "Topup Succeess",
|
||||
code: '00',
|
||||
message: 'Topup Succeess',
|
||||
data: {
|
||||
trxID: generate.buf2hex(transactionId),
|
||||
responseCode: respCode,
|
||||
@@ -257,8 +262,8 @@ const controller = async (req, res) => {
|
||||
}
|
||||
} else {
|
||||
result = {
|
||||
code: "423",
|
||||
message: "update/insert failed",
|
||||
code: '423',
|
||||
message: 'update/insert failed',
|
||||
data: {},
|
||||
};
|
||||
}
|
||||
@@ -277,11 +282,11 @@ const controller = async (req, res) => {
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
code: "5001",
|
||||
code: '5001',
|
||||
message:
|
||||
process.env.NODE_ENV != "production"
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: "500 internal server error - backend server.",
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4,9 +4,6 @@ const winston = require('../../helpers/winston.logger');
|
||||
const model = require('./reservebalance.model');
|
||||
const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
const moment = require('moment');
|
||||
const {
|
||||
setReservationNumberSequence,
|
||||
} = require('../../middlewares/redis.middleware');
|
||||
moment.locale('id');
|
||||
|
||||
// variable yang digunakan untuk melakukan perulangan proses generate reservation number jika reservation number yang di generate sudah digunakan orang lain
|
||||
@@ -73,13 +70,6 @@ const validate = (method) => {
|
||||
.isEmpty()
|
||||
.withMessage('Reservation Number is required'),
|
||||
];
|
||||
case 'cancelReservationV2':
|
||||
return [
|
||||
body('cancel_reservation_data')
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage('Cancel Reservation data is required'),
|
||||
];
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -153,21 +143,23 @@ const checkReservation = async (req, res) => {
|
||||
}
|
||||
} else {
|
||||
// jika settingan bukan diperuntukan untuk production, bisa development atau local atau yang lainnya dan kemudian kartu yang di request merupakan kartu production maka akan di tolak
|
||||
if (card_number.substring(0, 1) == '1') {
|
||||
result = {
|
||||
code: '400',
|
||||
message:
|
||||
"It's production card number. Please use the development card number.",
|
||||
data: {},
|
||||
};
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE RESERVATION-CHECK ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
// if (card_number.substring(0, 1) == '1') {
|
||||
// result = {
|
||||
// code: '400',
|
||||
// message:
|
||||
// "It's production card number. Please use the development card number.",
|
||||
// data: {},
|
||||
// };
|
||||
|
||||
// // log warn
|
||||
// winston.logger.warn(
|
||||
// `${uniqueCode} [ RESPONSE RESERVATION-CHECK ]: ${JSON.stringify(
|
||||
// result
|
||||
// )}`
|
||||
// );
|
||||
|
||||
// return res.status(200).json(result);
|
||||
// }
|
||||
}
|
||||
|
||||
// log debug
|
||||
@@ -1022,24 +1014,12 @@ const reservationValidateV2 = async (req, res) => {
|
||||
// });
|
||||
// }
|
||||
|
||||
// log debug
|
||||
// process enkripsi data reservasi dengan HMAC yang nanti nya akan di kirim ke end point reservation api sebagai pembanding bahwa data yang sudah di enkripsi tidak dimanipulasi
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING RESERVATION-VALIDATE-V2 ] generating security code from data reservation`
|
||||
);
|
||||
|
||||
// create security code yang isinya data reservasi yang akan di compare nantinya saat melakukan insert reservation
|
||||
let securityCode = await helper.createHMAC(
|
||||
mid + '|' + tid + '|' + card_number + '|' + amount
|
||||
);
|
||||
|
||||
let reservationData = {
|
||||
mid: mid,
|
||||
tid: tid,
|
||||
card_number: card_number,
|
||||
amount: amount,
|
||||
transaction_date: now,
|
||||
security_code: securityCode,
|
||||
};
|
||||
|
||||
// log debug
|
||||
@@ -1053,6 +1033,19 @@ const reservationValidateV2 = async (req, res) => {
|
||||
// enkripsi data reservasi sebelum melakukan transaksi reservasi
|
||||
let hash = helper.encryptText(JSON.stringify(reservationData));
|
||||
|
||||
// log debug
|
||||
// process enkripsi data reservasi dengan HMAC yang nanti nya akan di kirim ke end point reservation api sebagai pembanding bahwa data yang sudah di enkripsi tidak dimanipulasi
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING RESERVATION-VALIDATE-V2 ] generating security code from data reservation: ${JSON.stringify(
|
||||
reservationData
|
||||
)}`
|
||||
);
|
||||
|
||||
// create security code yang isinya data reservasi yang akan di compare nantinya saat melakukan insert reservation
|
||||
let securityCode = await helper.createHMAC(
|
||||
mid + '|' + tid + '|' + card_number + '|' + amount
|
||||
);
|
||||
|
||||
result = {
|
||||
code: '00',
|
||||
message: 'validation successfully.',
|
||||
@@ -1060,6 +1053,7 @@ const reservationValidateV2 = async (req, res) => {
|
||||
card_number: card_number,
|
||||
amount: amount,
|
||||
reservation_data: hash,
|
||||
security_code: securityCode,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1461,8 +1455,7 @@ const reservation = async (req, res) => {
|
||||
// generate reservation number
|
||||
let reservationNumber;
|
||||
let getReservationNumberSequence;
|
||||
// req.reservation_number_sequence adalah value yang di dapat dari redis middleware (cacheReservationNumberSequence)
|
||||
let reservationNoSequence = req.reservation_number_sequence;
|
||||
let reservationNoSequence;
|
||||
let maxLoop = 0;
|
||||
|
||||
do {
|
||||
@@ -1474,16 +1467,14 @@ const reservation = async (req, res) => {
|
||||
`${uniqueCode} [ PROCESSING RESERVATION ] checking reservation sequence...`
|
||||
);
|
||||
|
||||
if (!reservationNoSequence) {
|
||||
// get reservation
|
||||
getReservationNumberSequence = await model.getReservationNumberSequence(
|
||||
getPartner,
|
||||
today
|
||||
);
|
||||
reservationNoSequence = getReservationNumberSequence
|
||||
? parseInt(getReservationNumberSequence.i_reservation_no_seq) + 1
|
||||
: 1;
|
||||
}
|
||||
// get reservation
|
||||
getReservationNumberSequence = await model.getReservationNumberSequence(
|
||||
getPartner,
|
||||
today
|
||||
);
|
||||
reservationNoSequence = getReservationNumberSequence
|
||||
? parseInt(getReservationNumberSequence.i_reservation_no_seq) + 1
|
||||
: 1;
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
@@ -1705,7 +1696,7 @@ const reservationV2 = async (req, res) => {
|
||||
let result = {};
|
||||
|
||||
// param
|
||||
let { reservation_data, ref_no } = req.body;
|
||||
let { reservation_data, security_code, ref_no } = req.body;
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
@@ -1786,9 +1777,8 @@ const reservationV2 = async (req, res) => {
|
||||
let card_number = reservationData.card_number;
|
||||
let amount = reservationData.amount;
|
||||
let transactionDate = reservationData.transaction_date;
|
||||
let securityCode = reservationData.security_code;
|
||||
|
||||
if (securityCode) {
|
||||
if (security_code) {
|
||||
// log debug
|
||||
// process enkripsi data reservasi dengan HMAC sebagai pembanding bahwa data yang di decrypt valid
|
||||
winston.logger.debug(
|
||||
@@ -1796,11 +1786,11 @@ const reservationV2 = async (req, res) => {
|
||||
);
|
||||
|
||||
// create security code yang isinya data reservasi yang akan di compare nantinya saat melakukan insert reservation
|
||||
let securityCodeCompare = await helper.createHMAC(
|
||||
let securityCode = await helper.createHMAC(
|
||||
mid + '|' + tid + '|' + card_number + '|' + amount
|
||||
);
|
||||
|
||||
if (securityCode !== securityCodeCompare) {
|
||||
if (security_code !== securityCode) {
|
||||
result = {
|
||||
code: '437',
|
||||
message: 'bad request. reservation data has been changed.',
|
||||
@@ -1826,7 +1816,6 @@ const reservationV2 = async (req, res) => {
|
||||
card_number: card_number,
|
||||
amount: amount,
|
||||
transaction_date: transactionDate,
|
||||
security_code: securityCode,
|
||||
}
|
||||
)}`
|
||||
);
|
||||
@@ -2171,40 +2160,26 @@ const reservationV2 = async (req, res) => {
|
||||
// generate reservation number
|
||||
let reservationNumber;
|
||||
let getReservationNumberSequence;
|
||||
// req.reservation_number_sequence adalah value yang di dapat dari redis middleware (cacheReservationNumberSequence)
|
||||
let reservationNoSequence = req.reservation_number_sequence;
|
||||
|
||||
let reservationNoSequence;
|
||||
let maxLoop = 0;
|
||||
|
||||
do {
|
||||
await _sleep(helper.randomNumberInt());
|
||||
|
||||
if (maxLoop > 0) {
|
||||
reservationNoSequence = null;
|
||||
}
|
||||
|
||||
// log debug
|
||||
// proses pencarian sequence terakhir dari transaksi reservasi saldo berdasarkan partner di hari ini
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING RESERVATION-V2 ] checking reservation sequence...`
|
||||
);
|
||||
|
||||
if (!reservationNoSequence) {
|
||||
// get reservation
|
||||
getReservationNumberSequence = await model.getReservationNumberSequence(
|
||||
getPartner,
|
||||
today
|
||||
);
|
||||
reservationNoSequence = getReservationNumberSequence
|
||||
? parseInt(getReservationNumberSequence.i_reservation_no_seq) + 1
|
||||
: 1;
|
||||
|
||||
// set sequence to redis
|
||||
await setReservationNumberSequence(
|
||||
req.partner_id_token,
|
||||
reservationNoSequence
|
||||
);
|
||||
}
|
||||
// get reservation
|
||||
getReservationNumberSequence = await model.getReservationNumberSequence(
|
||||
getPartner,
|
||||
today
|
||||
);
|
||||
reservationNoSequence = getReservationNumberSequence
|
||||
? parseInt(getReservationNumberSequence.i_reservation_no_seq) + 1
|
||||
: 1;
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
@@ -2942,57 +2917,26 @@ const inquiryReservation = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
// ================================================================= INQUIRY RESERVATION BY REF NUMBER =================================================================
|
||||
// *Created By: Teddy Setiawan*
|
||||
// *Description:*
|
||||
//
|
||||
|
||||
const inquiryReservationByReservation = async (req, res) => {
|
||||
try {
|
||||
// param
|
||||
let { reservation_number, ref_no, load_balance_number } = req.body;
|
||||
let { reservation_number } = req.body;
|
||||
|
||||
let result;
|
||||
|
||||
if (req.query.search === 'ref-no') {
|
||||
// validation parameter inquiry
|
||||
if (!ref_no) {
|
||||
return res.status(200).json({
|
||||
code: '400',
|
||||
message: 'bad request. please add the ref number!',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
// check reservation
|
||||
result = await model.inquiryListByRefNumber(ref_no);
|
||||
} else if (req.query.search === 'load-balance-number') {
|
||||
// validation parameter inquiry
|
||||
if (!load_balance_number) {
|
||||
return res.status(200).json({
|
||||
code: '400',
|
||||
message: 'bad request. please add the load balance number!',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
// check reservation
|
||||
result = await model.inquiryListByLoadNumber(load_balance_number);
|
||||
} else {
|
||||
// validation parameter inquiry
|
||||
if (!reservation_number) {
|
||||
return res.status(200).json({
|
||||
code: '400',
|
||||
message: 'bad request. please add the reservation number!',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
// check reservation
|
||||
result = await model.inquiryByReservationNumber(reservation_number);
|
||||
// validation parameter inquiry
|
||||
if (!reservation_number) {
|
||||
return res.status(200).json({
|
||||
code: '400',
|
||||
message: 'bad request. please add the reservation number!',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
// check reservation
|
||||
let byReservationNumber = await model.inquiryByReservationNumber(
|
||||
reservation_number
|
||||
);
|
||||
|
||||
if (!byReservationNumber) {
|
||||
return res.status(200).json({
|
||||
code: '414',
|
||||
message: "reservation doesn't exist",
|
||||
@@ -3003,7 +2947,7 @@ const inquiryReservationByReservation = async (req, res) => {
|
||||
return res.json({
|
||||
code: '00',
|
||||
message: 'reservation has been found.',
|
||||
data: result,
|
||||
data: byReservationNumber,
|
||||
});
|
||||
} catch (error) {
|
||||
return res.status(200).json({
|
||||
@@ -3074,593 +3018,6 @@ const inquiryListReservationByReservation = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
// ================================================================= CANCEL RESERVATION V2 =================================================================
|
||||
// *Created By: Teddy Setiawan*
|
||||
// *Description:*
|
||||
//
|
||||
const cancelReservationValidateV2 = async (req, res) => {
|
||||
try {
|
||||
// generate unique code
|
||||
// unique code ini digunakan untuk keperluan log agar mudah untuk dibaca
|
||||
let uniqueCode = await helper.getUniqueCode();
|
||||
let result = {};
|
||||
|
||||
// param
|
||||
let { mid, tid, reservation_number } = req.body;
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ REQUEST CANCEL-RESERVATION-VALIDATE ]: ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
|
||||
// check validator
|
||||
const err = validationResult(req, res);
|
||||
if (!err.isEmpty()) {
|
||||
result = {
|
||||
code: '400',
|
||||
message: err.errors[0].msg,
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
// proses pengecekkan data partner berdasarkan mid dan tid yang di request, apakah terdaftar di sistem CMS atau tidak
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING CANCEL-RESERVATION-VALIDATE ]: checking partner...`
|
||||
);
|
||||
|
||||
// get partner, merchant, terminal from tid
|
||||
let getPartner = await model.getPartner(mid, tid);
|
||||
if (!getPartner) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'terminal id is not valid',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
// proses pengecekkan status reservation number yang di request
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING CANCEL-RESERVATION-VALIDATE ]: getting reservation by reservation number...`
|
||||
);
|
||||
|
||||
// get reservation berdasarkan reservation number yang di request
|
||||
let getReservationCanBeCanceled = await model.getReservationCanBeCanceled(
|
||||
reservation_number
|
||||
);
|
||||
|
||||
if (!getReservationCanBeCanceled) {
|
||||
result = {
|
||||
code: '414',
|
||||
message: "Reservation doesn't exist.",
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// get value global parameter
|
||||
let getGlobalParameter = await model.getGlobalParameter();
|
||||
// check value global parameter
|
||||
if (!getGlobalParameter) {
|
||||
result = {
|
||||
code: '493',
|
||||
message: 'HSM_CANCEL_RESERVATION_LEVEL in global parameter not found',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
// validasi sesuai value global parameter
|
||||
if (getGlobalParameter.c_value == 'PARTNER') {
|
||||
if (getPartner.i_partner != getReservationCanBeCanceled.i_partner) {
|
||||
result = {
|
||||
code: '438',
|
||||
message: 'Can not be canceled on different source',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
} else if (getGlobalParameter.c_value == 'MERCHANT') {
|
||||
if (getPartner.i_merchant != getReservationCanBeCanceled.i_merchant) {
|
||||
result = {
|
||||
code: '438',
|
||||
message: 'Can not be canceled on different source',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
} else if (getGlobalParameter.c_value == 'TERMINAL') {
|
||||
if (getPartner.i_terminal != getReservationCanBeCanceled.i_terminal) {
|
||||
result = {
|
||||
code: '438',
|
||||
message: 'Can not be canceled on different source',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
}
|
||||
|
||||
// jika data reservasi ditemukan
|
||||
if (getReservationCanBeCanceled) {
|
||||
// jika status dari reservation number yang di request adalah I = In Progress atau A = Loaded, maka proses cancel reservasi akan di tolak
|
||||
if (
|
||||
getReservationCanBeCanceled.c_status == 'I' ||
|
||||
getReservationCanBeCanceled.c_status == 'A'
|
||||
) {
|
||||
result = {
|
||||
code: '429',
|
||||
message: 'can not be cancelled. The transaction has been loaded.',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
} else if (getReservationCanBeCanceled.c_status == 'X') {
|
||||
// jika status dari reservation number yang di request adalah X = Deleted, maka proses cancel reservasi akan di tolak
|
||||
let cancelDate = getReservationCanBeCanceled.d_cancel
|
||||
? moment(getReservationCanBeCanceled.d_cancel).format(
|
||||
'DD-MM-YYYY HH:mm:ss'
|
||||
)
|
||||
: '';
|
||||
result = {
|
||||
code: '430',
|
||||
message: `can not be cancelled. The transaction has been canceled at ${cancelDate}.`,
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} RESPONSE cancel reservation validate: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
} else if (getReservationCanBeCanceled.c_payment_recon_no) {
|
||||
// jika reservation number yang di request sudah dilakukan payment recon, maka proses cancel reservasi akan di tolak
|
||||
result = {
|
||||
code: '430',
|
||||
message: `can not be cancelled. The transaction has been recon.`,
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
} else {
|
||||
// jika reservation number yang di request tidak ditemukan di sistem CMS
|
||||
result = {
|
||||
code: '414',
|
||||
message: "Reservation doesn't exist.",
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// time
|
||||
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||
|
||||
// create security code yang isinya data reservasi yang akan di compare nantinya saat melakukan insert reservation
|
||||
let securityCode = await helper.createHMAC(
|
||||
mid + '|' + tid + '|' + reservation_number
|
||||
);
|
||||
|
||||
let reservationData = {
|
||||
mid: mid,
|
||||
tid: tid,
|
||||
reservation_number: reservation_number,
|
||||
transaction_date: now,
|
||||
security_code: securityCode,
|
||||
};
|
||||
|
||||
// log debug
|
||||
// process enkripsi data reservasi dengan AES yang nanti nya akan di kirim ke end point reservation api untuk menyimpan data reservasi
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING RESERVATION-VALIDATE-V2 ] encrypting data reservation: ${JSON.stringify(
|
||||
reservationData
|
||||
)}`
|
||||
);
|
||||
|
||||
// enkripsi data reservasi sebelum melakukan transaksi reservasi
|
||||
let hash = helper.encryptText(JSON.stringify(reservationData));
|
||||
|
||||
result = {
|
||||
code: '00',
|
||||
message: 'reservation can be canceled.',
|
||||
data: {
|
||||
cancel_reservation_data: hash,
|
||||
},
|
||||
};
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION-VALIDATE ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`[ RESPONSE CANCEL-RESERVATION-VALIDATE ]: 500 internal server error - backend server | ${error.message}`
|
||||
);
|
||||
|
||||
return res.status(200).json({
|
||||
code: '500',
|
||||
message:
|
||||
process.env.NODE_ENV != 'production'
|
||||
? error.message
|
||||
: '500 internal server error - backend server.',
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const cancelReservationV2 = async (req, res) => {
|
||||
try {
|
||||
// generate unique code
|
||||
// unique code ini digunakan untuk keperluan log agar mudah untuk dibaca
|
||||
let uniqueCode = await helper.getUniqueCode();
|
||||
let result = {};
|
||||
|
||||
// param
|
||||
let { cancel_reservation_data } = req.body;
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ REQUEST CANCEL-RESERVATION ]: ${JSON.stringify(
|
||||
req.body
|
||||
)}`
|
||||
);
|
||||
|
||||
// check validator
|
||||
const err = validationResult(req, res);
|
||||
if (!err.isEmpty()) {
|
||||
result = {
|
||||
code: '400',
|
||||
message: err.errors[0].msg,
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
let cancelReservationData;
|
||||
|
||||
try {
|
||||
cancelReservationData = helper.decryptText(cancel_reservation_data);
|
||||
} catch (error) {}
|
||||
|
||||
if (!cancelReservationData) {
|
||||
result = {
|
||||
code: '435',
|
||||
message: 'bad request. reservation data is invalid.',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE RESERVATION-V2 ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// parsing data to json format
|
||||
cancelReservationData = JSON.parse(cancelReservationData);
|
||||
|
||||
if (
|
||||
!cancelReservationData.mid ||
|
||||
!cancelReservationData.tid ||
|
||||
!cancelReservationData.reservation_number ||
|
||||
!cancelReservationData.transaction_date
|
||||
) {
|
||||
result = {
|
||||
code: '436',
|
||||
message: 'bad request. reservation data is empty.',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE RESERVATION-V2 ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
// proses pengecekkan data partner berdasarkan mid dan tid yang di request, apakah terdaftar di sistem CMS atau tidak
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING CANCEL-RESERVATION ]: checking partner...`
|
||||
);
|
||||
|
||||
// get partner, merchant, terminal from tid
|
||||
let getPartner = await model.getPartner(
|
||||
cancelReservationData.mid,
|
||||
cancelReservationData.tid
|
||||
);
|
||||
if (!getPartner) {
|
||||
result = {
|
||||
code: '412',
|
||||
message: 'terminal id is not valid',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
// proses pengecekkan status reservation number yang di request
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING CANCEL-RESERVATION ]: getting reservation by reservation number...`
|
||||
);
|
||||
|
||||
// get reservation pending & in progress status
|
||||
let getReservationCanBeCanceled = await model.getReservationCanBeCanceled(
|
||||
cancelReservationData.reservation_number
|
||||
);
|
||||
if (getReservationCanBeCanceled) {
|
||||
if (
|
||||
getReservationCanBeCanceled.c_status == 'I' ||
|
||||
getReservationCanBeCanceled.c_status == 'A'
|
||||
) {
|
||||
result = {
|
||||
code: '429',
|
||||
message: 'can not be cancelled. The transaction has been loaded.',
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
} else if (getReservationCanBeCanceled.c_status == 'X') {
|
||||
let cancelDate = getReservationCanBeCanceled.d_cancel
|
||||
? moment(getReservationCanBeCanceled.d_cancel).format(
|
||||
'DD-MM-YYYY HH:mm:ss'
|
||||
)
|
||||
: '';
|
||||
result = {
|
||||
code: '430',
|
||||
message: `can not be cancelled. The transaction has been canceled at ${cancelDate}.`,
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
} else if (getReservationCanBeCanceled.c_payment_recon_no) {
|
||||
result = {
|
||||
code: '430',
|
||||
message: `can not be cancelled. The transaction has been recon.`,
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
} else {
|
||||
result = {
|
||||
code: '414',
|
||||
message: "Reservation doesn't exist.",
|
||||
data: {},
|
||||
};
|
||||
|
||||
// log warn
|
||||
winston.logger.warn(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION ]: ${JSON.stringify(
|
||||
result
|
||||
)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
// log debug
|
||||
// proses pencarian saldo terakhir dari nomor kartu yang di request berdasarkan data log hitory
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING CANCEL-RESERVATION ]: getting last balance on the card by card history...`
|
||||
);
|
||||
|
||||
// get last balance on the card
|
||||
let balance = 0;
|
||||
let getLastBalanceFromCardHistory =
|
||||
await model.getLastBalanceFromCardHistory(
|
||||
getReservationCanBeCanceled.c_card_number
|
||||
);
|
||||
if (getLastBalanceFromCardHistory) {
|
||||
balance = getLastBalanceFromCardHistory.m_balance_after;
|
||||
}
|
||||
|
||||
// time
|
||||
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||
|
||||
// binding data
|
||||
let data = {
|
||||
c_status: 'X',
|
||||
c_status_name: 'CANCELED',
|
||||
d_cancel: now,
|
||||
};
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING CANCEL-RESERVATION ]: updating reservation to status cancel...`
|
||||
);
|
||||
|
||||
// cancel transaction
|
||||
await model.cancelReservation(
|
||||
data,
|
||||
cancelReservationData.reservation_number
|
||||
);
|
||||
|
||||
// log debug
|
||||
winston.logger.debug(
|
||||
`${uniqueCode} [ PROCESSING CANCEL-RESERVATION ]: inserting log for card history...`
|
||||
);
|
||||
|
||||
// log card history
|
||||
await model.createReserveBalanceLog({
|
||||
i_log_name: 110,
|
||||
d_log: now,
|
||||
c_card_number: getReservationCanBeCanceled.c_card_number,
|
||||
c_source: 'CMS',
|
||||
c_location: getPartner ? getPartner.partner_name : null,
|
||||
m_balance_before: balance > 0 ? balance : 0,
|
||||
m_amount: 0,
|
||||
m_balance_after: balance > 0 ? balance : 0,
|
||||
j_new_data: data,
|
||||
j_old_data: getReservationCanBeCanceled,
|
||||
c_note: `CANCEL RESERVE BALANCE ${
|
||||
getReservationCanBeCanceled.i_reservation_amount
|
||||
} FROM ${getPartner ? getPartner.partner_name : null}`,
|
||||
c_status: 'S',
|
||||
d_created: now,
|
||||
i_create: null,
|
||||
c_create_username: 'HSM',
|
||||
c_create_fullname: 'HARDWARE SECURE MODULE',
|
||||
c_category: 'T',
|
||||
});
|
||||
|
||||
result = {
|
||||
code: '00',
|
||||
message: 'reservation successfully canceled.',
|
||||
data: {
|
||||
reservation_number: getReservationCanBeCanceled.c_reservation_no,
|
||||
reservation_amount: getReservationCanBeCanceled.i_reservation_amount,
|
||||
},
|
||||
};
|
||||
|
||||
// log info
|
||||
winston.logger.info(
|
||||
`${uniqueCode} [ RESPONSE CANCEL-RESERVATION ]: ${JSON.stringify(result)}`
|
||||
);
|
||||
|
||||
return res.status(200).json(result);
|
||||
} catch (error) {
|
||||
// create log
|
||||
winston.logger.error(
|
||||
`[ RESPONSE CANCEL-RESERVATION ]: 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,
|
||||
checkReservation,
|
||||
@@ -3673,6 +3030,4 @@ module.exports = {
|
||||
inquiryReservation,
|
||||
inquiryReservationByReservation,
|
||||
inquiryListReservationByReservation,
|
||||
cancelReservationValidateV2,
|
||||
cancelReservationV2,
|
||||
};
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
const knex = require('../../../infrastructure/database/knex');
|
||||
const knex = require("../../../infrastructure/database/knex");
|
||||
|
||||
// CHECK CARD NUMBER
|
||||
const checkCardNumber = (cardNumber) => {
|
||||
let result = knex('t_m_card_product')
|
||||
.where('c_card_number', cardNumber)
|
||||
.where('c_status', '!=', 'X')
|
||||
let result = knex("t_m_card_product")
|
||||
.where("c_card_number", cardNumber)
|
||||
.where("c_status", "!=", "X")
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET RESERVATION
|
||||
const getReservationNumberSequence = (data, date) => {
|
||||
let result = knex('trx.t_d_reservation_balance')
|
||||
.select('i_reservation_no_seq')
|
||||
.orderBy('i_reservation_no_seq', 'desc')
|
||||
.whereNotNull('i_reservation_no_seq')
|
||||
.where('i_partner', data.i_partner)
|
||||
.where('i_merchant', data.i_merchant)
|
||||
.whereRaw('??::date = ?', ['d_reservation', date])
|
||||
console.log('AKU DIPANGGIL');
|
||||
let result = knex("trx.t_d_reservation_balance")
|
||||
.select("i_reservation_no_seq")
|
||||
.orderBy("i_reservation_no_seq", "desc")
|
||||
.whereNotNull("i_reservation_no_seq")
|
||||
.where("i_partner", data.i_partner)
|
||||
.where("i_merchant", data.i_merchant)
|
||||
.whereRaw("??::date = ?", ["d_reservation", date])
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
@@ -26,202 +27,202 @@ const getReservationNumberSequence = (data, date) => {
|
||||
const getPartner = (mid, tid) => {
|
||||
let result = knex
|
||||
.select(
|
||||
't_m_partner.i_partner',
|
||||
't_m_partner.c_code as partner_code',
|
||||
't_m_partner.c_name as partner_name',
|
||||
't_m_merchant.i_merchant',
|
||||
't_m_merchant.c_code as merchant_code',
|
||||
't_m_merchant.c_name as merchant_name',
|
||||
't_m_merchant.e_mid as mid',
|
||||
't_m_terminal.i_terminal',
|
||||
't_m_terminal.c_code as terminal_code',
|
||||
't_m_terminal.c_name as terminal_name',
|
||||
't_m_terminal.e_tid as tid'
|
||||
"t_m_partner.i_partner",
|
||||
"t_m_partner.c_code as partner_code",
|
||||
"t_m_partner.c_name as partner_name",
|
||||
"t_m_merchant.i_merchant",
|
||||
"t_m_merchant.c_code as merchant_code",
|
||||
"t_m_merchant.c_name as merchant_name",
|
||||
"t_m_merchant.e_mid as mid",
|
||||
"t_m_terminal.i_terminal",
|
||||
"t_m_terminal.c_code as terminal_code",
|
||||
"t_m_terminal.c_name as terminal_name",
|
||||
"t_m_terminal.e_tid as tid"
|
||||
)
|
||||
.from('t_m_terminal')
|
||||
.from("t_m_terminal")
|
||||
.leftJoin(
|
||||
't_m_merchant',
|
||||
't_m_terminal.i_merchant',
|
||||
't_m_merchant.i_merchant'
|
||||
"t_m_merchant",
|
||||
"t_m_terminal.i_merchant",
|
||||
"t_m_merchant.i_merchant"
|
||||
)
|
||||
.leftJoin('t_m_partner', 't_m_merchant.i_partner', 't_m_partner.i_partner')
|
||||
.where('t_m_merchant.e_mid', mid)
|
||||
.where('t_m_terminal.e_tid', tid)
|
||||
.where('t_m_terminal.c_status', 'A')
|
||||
.where('t_m_merchant.c_status', 'A')
|
||||
.where('t_m_partner.c_status', 'A')
|
||||
.leftJoin("t_m_partner", "t_m_merchant.i_partner", "t_m_partner.i_partner")
|
||||
.where("t_m_merchant.e_mid", mid)
|
||||
.where("t_m_terminal.e_tid", tid)
|
||||
.where("t_m_terminal.c_status", "A")
|
||||
.where("t_m_merchant.c_status", "A")
|
||||
.where("t_m_partner.c_status", "A")
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET ISSUER FEE
|
||||
const getIssuer = (id, time) => {
|
||||
let result = knex('t_c_partner_fee')
|
||||
.select('i_issuer_fee_perc', 'i_channel_fee_perc', 'i_amount')
|
||||
.where('i_partner', id)
|
||||
.where('c_status', 'A')
|
||||
.where('d_valid', '<=', time)
|
||||
.orderBy('d_valid', 'desc')
|
||||
let result = knex("t_c_partner_fee")
|
||||
.select("i_issuer_fee_perc", "i_channel_fee_perc", "i_amount")
|
||||
.where("i_partner", id)
|
||||
.where("c_status", "A")
|
||||
.where("d_valid", "<=", time)
|
||||
.orderBy("d_valid", "desc")
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET RESERVATION EXPIRATION DATE FROM GLOBAL PARAMETER
|
||||
const getReservationExpirationDateValue = () => {
|
||||
let result = knex('t_m_global_parameter')
|
||||
.select('c_value')
|
||||
.where('c_code', 'HSM_EXP_RSV_VAL')
|
||||
.where('c_status', 'A')
|
||||
let result = knex("t_m_global_parameter")
|
||||
.select("c_value")
|
||||
.where("c_code", "HSM_EXP_RSV_VAL")
|
||||
.where("c_status", "A")
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET RESERVATION EXPIRATION DATE MEASURE FROM GLOBAL PARAMETER
|
||||
const getReservationExpirationDateMeasure = () => {
|
||||
let result = knex('t_m_global_parameter')
|
||||
.select('c_value')
|
||||
.where('c_code', 'HSM_EXP_RSV_MEA')
|
||||
.where('c_status', 'A')
|
||||
let result = knex("t_m_global_parameter")
|
||||
.select("c_value")
|
||||
.where("c_code", "HSM_EXP_RSV_MEA")
|
||||
.where("c_status", "A")
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET CHECKING CARD PRODUCT FROM GLOBAL PARAMETER
|
||||
const getCheckByCardProductStatusValue = () => {
|
||||
let result = knex('t_m_global_parameter')
|
||||
.select('c_value')
|
||||
.where('c_code', 'HSM_CHECK_BY_CARD_PRODUCT_STAT')
|
||||
.where('c_status', 'A')
|
||||
let result = knex("t_m_global_parameter")
|
||||
.select("c_value")
|
||||
.where("c_code", "HSM_CHECK_BY_CARD_PRODUCT_STAT")
|
||||
.where("c_status", "A")
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET BI REGULATION STATUS FROM GLOBAL PARAMETER
|
||||
const getBIRegulationStatus = () => {
|
||||
let result = knex('t_m_global_parameter')
|
||||
.select('c_value')
|
||||
.where('c_code', 'HSM_BI_REGULATION_STAT')
|
||||
.where('c_status', 'A')
|
||||
let result = knex("t_m_global_parameter")
|
||||
.select("c_value")
|
||||
.where("c_code", "HSM_BI_REGULATION_STAT")
|
||||
.where("c_status", "A")
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET MAX AMOUNT ON THE CARD FROM GLOBAL PARAMETER
|
||||
const getMaxAmountOnTheCard = () => {
|
||||
let result = knex('t_m_global_parameter')
|
||||
.select('c_value')
|
||||
.where('c_code', 'HSM_BI_MAX_AMOUNT_ON_THE_CARD')
|
||||
.where('c_status', 'A')
|
||||
let result = knex("t_m_global_parameter")
|
||||
.select("c_value")
|
||||
.where("c_code", "HSM_BI_MAX_AMOUNT_ON_THE_CARD")
|
||||
.where("c_status", "A")
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET MAX TOPUP PER MONTH FROM GLOBAL PARAMETER
|
||||
const getMaxTopupPerMonth = () => {
|
||||
let result = knex('t_m_global_parameter')
|
||||
.select('c_value')
|
||||
.where('c_code', 'HSM_BI_MAX_TOPUP_PER_MONTH')
|
||||
.where('c_status', 'A')
|
||||
let result = knex("t_m_global_parameter")
|
||||
.select("c_value")
|
||||
.where("c_code", "HSM_BI_MAX_TOPUP_PER_MONTH")
|
||||
.where("c_status", "A")
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET MAX RESERVATION FROM GLOBAL PARAMETER
|
||||
const getMaxReservation = () => {
|
||||
let result = knex('t_m_global_parameter')
|
||||
.select('c_value')
|
||||
.where('c_code', 'HSM_MAX_RSV_PEN')
|
||||
.where('c_status', 'A')
|
||||
let result = knex("t_m_global_parameter")
|
||||
.select("c_value")
|
||||
.where("c_code", "HSM_MAX_RSV_PEN")
|
||||
.where("c_status", "A")
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// INQUIRY BY RESERVATION NUMBER
|
||||
let inquiryByReservationNumber = (reservationNumber) => {
|
||||
let result = knex('trx.t_d_reservation_balance')
|
||||
let result = knex("trx.t_d_reservation_balance")
|
||||
.select(
|
||||
'c_reservation_no as reservation_number',
|
||||
'd_reservation as reservation_date',
|
||||
'c_ref_no as ref_no',
|
||||
'c_partner_name as partner_name',
|
||||
'c_merchant_name as merchant_name',
|
||||
'c_terminal_name as terminal_name',
|
||||
'c_card_number as card_number',
|
||||
'i_reservation_amount as reservation_amount',
|
||||
'i_issuer_fee as issuer_fee',
|
||||
'i_channel_fee as channel_fee',
|
||||
'c_payment_recon_no as payment_recon_no',
|
||||
'd_payment_recon as recon_date',
|
||||
'c_status as status_code',
|
||||
'c_status_name as description'
|
||||
"c_reservation_no as reservation_number",
|
||||
"d_reservation as reservation_date",
|
||||
"c_ref_no as ref_no",
|
||||
"c_partner_name as partner_name",
|
||||
"c_merchant_name as merchant_name",
|
||||
"c_terminal_name as terminal_name",
|
||||
"c_card_number as card_number",
|
||||
"i_reservation_amount as reservation_amount",
|
||||
"i_issuer_fee as issuer_fee",
|
||||
"i_channel_fee as channel_fee",
|
||||
"c_payment_recon_no as payment_recon_no",
|
||||
"d_payment_recon as recon_date",
|
||||
"c_status as status_code",
|
||||
"c_status_name as description"
|
||||
)
|
||||
.where('c_reservation_no', reservationNumber)
|
||||
.where("c_reservation_no", reservationNumber)
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// INQUIRY LIST RESERVATION
|
||||
let inquiryListReservation = (partnerID, startDate, endDate) => {
|
||||
let result = knex('trx.t_d_reservation_balance')
|
||||
let result = knex("trx.t_d_reservation_balance")
|
||||
.select(
|
||||
'c_reservation_no as reservation_number',
|
||||
'd_reservation as reservation_date',
|
||||
'c_ref_no as ref_no',
|
||||
'c_partner_name as partner_name',
|
||||
'c_merchant_name as merchant_name',
|
||||
'c_terminal_name as terminal_name',
|
||||
'c_card_number as card_number',
|
||||
'i_reservation_amount as reservation_amount',
|
||||
'i_issuer_fee as issuer_fee',
|
||||
'i_channel_fee as channel_fee',
|
||||
'c_payment_recon_no as payment_recon_no',
|
||||
'd_payment_recon as recon_date',
|
||||
'c_status as status_code',
|
||||
'c_status_name as description'
|
||||
"c_reservation_no as reservation_number",
|
||||
"d_reservation as reservation_date",
|
||||
"c_ref_no as ref_no",
|
||||
"c_partner_name as partner_name",
|
||||
"c_merchant_name as merchant_name",
|
||||
"c_terminal_name as terminal_name",
|
||||
"c_card_number as card_number",
|
||||
"i_reservation_amount as reservation_amount",
|
||||
"i_issuer_fee as issuer_fee",
|
||||
"i_channel_fee as channel_fee",
|
||||
"c_payment_recon_no as payment_recon_no",
|
||||
"d_payment_recon as recon_date",
|
||||
"c_status as status_code",
|
||||
"c_status_name as description"
|
||||
)
|
||||
.where('i_partner', partnerID);
|
||||
|
||||
if (startDate && endDate) {
|
||||
result.whereRaw('??::date >= ?', ['d_reservation', startDate]);
|
||||
result.whereRaw('??::date <= ?', ['d_reservation', endDate]);
|
||||
}
|
||||
.where("i_partner", partnerID);
|
||||
|
||||
if (startDate && endDate) {
|
||||
result.whereRaw("??::date >= ?", ["d_reservation", startDate]);
|
||||
result.whereRaw("??::date <= ?", ["d_reservation", endDate]);
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
// INQUIRY BY CARD NUMBER
|
||||
let inquiryByCardNumber = (cardNumber, startDate, endDate) => {
|
||||
let result = knex('trx.t_d_reservation_balance')
|
||||
let result = knex("trx.t_d_reservation_balance")
|
||||
.select(
|
||||
'c_reservation_no as reservation_number',
|
||||
'd_reservation as reservation_date',
|
||||
'c_ref_no as ref_no',
|
||||
'c_partner_name as partner_name',
|
||||
'c_merchant_name as merchant_name',
|
||||
'c_terminal_name as terminal_name',
|
||||
'c_card_number as card_number',
|
||||
'i_reservation_amount as reservation_amount',
|
||||
'i_issuer_fee as issuer_fee',
|
||||
'i_channel_fee as channel_fee',
|
||||
'c_status as status_code',
|
||||
'c_status_name as description'
|
||||
"c_reservation_no as reservation_number",
|
||||
"d_reservation as reservation_date",
|
||||
"c_ref_no as ref_no",
|
||||
"c_partner_name as partner_name",
|
||||
"c_merchant_name as merchant_name",
|
||||
"c_terminal_name as terminal_name",
|
||||
"c_card_number as card_number",
|
||||
"i_reservation_amount as reservation_amount",
|
||||
"i_issuer_fee as issuer_fee",
|
||||
"i_channel_fee as channel_fee",
|
||||
"c_status as status_code",
|
||||
"c_status_name as description"
|
||||
)
|
||||
.where('c_card_number', cardNumber);
|
||||
.where("c_card_number", cardNumber);
|
||||
|
||||
if (startDate && endDate) {
|
||||
result.whereRaw('??::date >= ?', ['d_reservation', startDate]);
|
||||
result.whereRaw('??::date <= ?', ['d_reservation', endDate]);
|
||||
result.whereRaw("??::date >= ?", ["d_reservation", startDate]);
|
||||
result.whereRaw("??::date <= ?", ["d_reservation", endDate]);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET RESERVATION PENDING
|
||||
const getReservationPending = (cardNumber, time) => {
|
||||
let result = knex('trx.t_d_reservation_balance')
|
||||
.count('* as total_reservation')
|
||||
.sum('i_reservation_amount as total_nominal_reservation')
|
||||
.where('c_card_number', cardNumber)
|
||||
.where('c_status', 'P')
|
||||
let result = knex("trx.t_d_reservation_balance")
|
||||
.count("* as total_reservation")
|
||||
.sum("i_reservation_amount as total_nominal_reservation")
|
||||
.where("c_card_number", cardNumber)
|
||||
.where("c_status", "P")
|
||||
// .where("d_expired", ">=", time)
|
||||
.first();
|
||||
return result;
|
||||
@@ -229,33 +230,33 @@ const getReservationPending = (cardNumber, time) => {
|
||||
|
||||
// GET RESERVATION WITH FLAG
|
||||
const getReservationWithFlag = (cardNumber, time) => {
|
||||
let result = knex('trx.t_d_reservation_balance')
|
||||
.count('* as total_reservation')
|
||||
.where('c_card_number', cardNumber)
|
||||
.whereIn('c_status', ['P', 'I'])
|
||||
let result = knex("trx.t_d_reservation_balance")
|
||||
.count("* as total_reservation")
|
||||
.where("c_card_number", cardNumber)
|
||||
.whereIn("c_status", ["P", "I"])
|
||||
// .where("d_expired", ">=", time)
|
||||
.whereNotNull('c_flag')
|
||||
.whereNotNull("c_flag")
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// INSERT RESERVATION
|
||||
const insertReservation = (data) => {
|
||||
let result = knex('trx.t_d_reservation_balance')
|
||||
let result = knex("trx.t_d_reservation_balance")
|
||||
.insert(data)
|
||||
.onConflict('c_ref_no')
|
||||
.onConflict("c_ref_no")
|
||||
.ignore();
|
||||
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')
|
||||
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;
|
||||
@@ -267,140 +268,66 @@ const getAccumulationBalanceInThisMonthFromCardHistory = (
|
||||
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')
|
||||
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;
|
||||
};
|
||||
|
||||
// CREATE LOG FOR CARD HISTORY
|
||||
const createReserveBalanceLog = (data) => {
|
||||
let result = knex('log.t_log_card').insert(data);
|
||||
let result = knex("log.t_log_card").insert(data);
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET RESERVATION PENDING AND IN PROGRESS
|
||||
const getReservationWithPendingAndInProgressStatus = (cardNumber) => {
|
||||
let result = knex('trx.t_d_reservation_balance')
|
||||
.count('* as total_reservation_pending')
|
||||
.where('c_card_number', cardNumber)
|
||||
.whereIn('c_status', ['P', 'I'])
|
||||
let result = knex("trx.t_d_reservation_balance")
|
||||
.count("* as total_reservation_pending")
|
||||
.where("c_card_number", cardNumber)
|
||||
.whereIn("c_status", ["P", "I"])
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET RESERVATION PENDING AND NOT YET PAYMENT RECON
|
||||
const getReservationCanBeCanceled = (reservation_number) => {
|
||||
let result = knex('trx.t_d_reservation_balance')
|
||||
.where('c_reservation_no', reservation_number)
|
||||
let result = knex("trx.t_d_reservation_balance")
|
||||
.where("c_reservation_no", reservation_number)
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
const insertReservationNumber = (reservationNumber) => {
|
||||
let result = knex('trx.t_d_reservation_no_validate')
|
||||
let result = knex("trx.t_d_reservation_no_validate")
|
||||
.insert({
|
||||
c_reservation_no: reservationNumber,
|
||||
})
|
||||
.onConflict('c_reservation_no')
|
||||
.onConflict("c_reservation_no")
|
||||
.ignore();
|
||||
return result;
|
||||
};
|
||||
|
||||
const cancelReservation = (data, reservationNumber) => {
|
||||
let result = knex('trx.t_d_reservation_balance')
|
||||
let result = knex("trx.t_d_reservation_balance")
|
||||
.update(data)
|
||||
.where('c_reservation_no', reservationNumber);
|
||||
.where("c_reservation_no", reservationNumber);
|
||||
return result;
|
||||
};
|
||||
const deleteReservationNumberValidate = (reservationNumber) => {
|
||||
let result = knex('trx.t_d_reservation_no_validate')
|
||||
.where('c_reservation_no', reservationNumber)
|
||||
let result = knex("trx.t_d_reservation_no_validate")
|
||||
.where("c_reservation_no", reservationNumber)
|
||||
.del();
|
||||
return result;
|
||||
};
|
||||
|
||||
// INQUIRY BY REF NUMBER
|
||||
let inquiryListByRefNumber = (refNumber) => {
|
||||
let result = knex('trx.t_d_reservation_balance')
|
||||
.select(
|
||||
'c_reservation_no as reservation_number',
|
||||
'd_reservation as reservation_date',
|
||||
'c_ref_no as ref_no',
|
||||
'c_partner_name as partner_name',
|
||||
'c_merchant_name as merchant_name',
|
||||
'c_terminal_name as terminal_name',
|
||||
'c_card_number as card_number',
|
||||
'i_reservation_amount as reservation_amount',
|
||||
'i_issuer_fee as issuer_fee',
|
||||
'i_channel_fee as channel_fee',
|
||||
'c_status as status_code',
|
||||
'c_status_name as description'
|
||||
)
|
||||
.where('c_ref_no', refNumber);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
// ================================================================= INQUIRY LOAD BALANCE =================================================================
|
||||
// *Created By: Teddy Setiawan*
|
||||
// *Description:*
|
||||
//
|
||||
|
||||
// INQUIRY BY LOAD BALANCE NUMBER
|
||||
const inquiryListByLoadNumber = (load_balance_number) => {
|
||||
let result = knex('trx.t_d_reservation_balance')
|
||||
.select(
|
||||
'trx.t_d_reservation_balance.c_reservation_no as reservation_number',
|
||||
'trx.t_d_reservation_balance.d_reservation as reservation_date',
|
||||
'trx.t_d_reservation_balance.c_ref_no as ref_no',
|
||||
'trx.t_d_reservation_balance.c_partner_name as partner_name_reservation',
|
||||
'trx.t_d_reservation_balance.c_merchant_name as merchant_name_reservation',
|
||||
'trx.t_d_reservation_balance.c_terminal_name as terminal_name_reservation',
|
||||
'trx.t_d_load_balance.d_load_balance as load_date',
|
||||
'trx.t_d_load_balance.c_partner_name as partner_name_load',
|
||||
'trx.t_d_load_balance.c_merchant_name as merchant_name_load',
|
||||
'trx.t_d_load_balance.c_terminal_name as terminal_name_load',
|
||||
'trx.t_d_reservation_balance.c_card_number as card_number',
|
||||
'trx.t_d_reservation_balance.i_reservation_amount as reservation_amount',
|
||||
'trx.t_d_reservation_balance.i_issuer_fee as issuer_fee',
|
||||
'trx.t_d_reservation_balance.i_channel_fee as channel_fee',
|
||||
'trx.t_d_reservation_balance.c_payment_recon_no as payment_recon_no',
|
||||
'trx.t_d_reservation_balance.d_payment_recon as recon_date',
|
||||
'trx.t_d_reservation_balance.c_status as status_code',
|
||||
'trx.t_d_reservation_balance.c_status_name as description'
|
||||
)
|
||||
.leftJoin('trx.t_d_load_balance', function () {
|
||||
this.on(
|
||||
'trx.t_d_reservation_balance.c_load_balance_no',
|
||||
'=',
|
||||
'trx.t_d_load_balance.c_load_balance_no'
|
||||
);
|
||||
})
|
||||
.where(
|
||||
'trx.t_d_reservation_balance.c_load_balance_no',
|
||||
load_balance_number
|
||||
);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
const getGlobalParameter = () => {
|
||||
let result = knex('t_m_global_parameter')
|
||||
.select('c_value')
|
||||
.where('c_code', '=', 'HSM_CANCEL_RESERVATION_LEVEL')
|
||||
.first();
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
checkCardNumber,
|
||||
getReservationNumberSequence,
|
||||
@@ -427,7 +354,4 @@ module.exports = {
|
||||
insertReservationNumber,
|
||||
cancelReservation,
|
||||
deleteReservationNumberValidate,
|
||||
inquiryListByRefNumber,
|
||||
getGlobalParameter,
|
||||
inquiryListByLoadNumber,
|
||||
};
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
const express = require('express');
|
||||
const express = require("express");
|
||||
const router = express.Router();
|
||||
const auth = require('../middlewares/jwt.middleware');
|
||||
const controller = require('../modules/loadbalance/loadbalance.controller');
|
||||
const auth = require("../middlewares/jwt.middleware");
|
||||
const controller = require("../modules/loadbalance/loadbalance.controller");
|
||||
|
||||
router.post(
|
||||
'/loadbalance/request',
|
||||
"/loadbalance/request",
|
||||
auth.authenticateToken,
|
||||
controller.validate('loadingBalanceRequest'),
|
||||
controller.validate("loadingBalanceRequest"),
|
||||
controller.loadingBalanceRequest
|
||||
);
|
||||
|
||||
router.post(
|
||||
'/loadbalance',
|
||||
"/loadbalance",
|
||||
auth.authenticateToken,
|
||||
controller.validate('loadingBalance'),
|
||||
controller.validate("loadingBalance"),
|
||||
controller.loadingBalance
|
||||
);
|
||||
|
||||
router.post(
|
||||
'/loadbalance/inquiry',
|
||||
"/loadbalance/inquiry",
|
||||
auth.authenticateToken,
|
||||
controller.inquiryLoadingBalance
|
||||
);
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const auth = require('../middlewares/jwt.middleware');
|
||||
const lokiMiddleware = require('../middlewares/loki.middleware');
|
||||
const {
|
||||
prometheusMiddleware,
|
||||
} = require('../middlewares/prometheus.middleware');
|
||||
const {
|
||||
getReservationNumberSequence,
|
||||
} = require('../middlewares/redis.middleware');
|
||||
const controller = require('../modules/reservebalance/reservebalance.controller');
|
||||
|
||||
// ================================================================= ROUTE V1 =================================================================
|
||||
@@ -28,9 +21,6 @@ router.post(
|
||||
router.post(
|
||||
'/reservation',
|
||||
auth.authenticateToken,
|
||||
prometheusMiddleware,
|
||||
lokiMiddleware,
|
||||
getReservationNumberSequence,
|
||||
controller.validate('reservation'),
|
||||
controller.reservation
|
||||
);
|
||||
@@ -78,25 +68,8 @@ router.post(
|
||||
router.post(
|
||||
'/reservation/v2',
|
||||
auth.authenticateToken,
|
||||
prometheusMiddleware,
|
||||
lokiMiddleware,
|
||||
getReservationNumberSequence,
|
||||
controller.validate('reservationV2'),
|
||||
controller.reservationV2
|
||||
);
|
||||
|
||||
router.post(
|
||||
'/reservation/cancel/validate/v2',
|
||||
auth.authenticateToken,
|
||||
controller.validate('cancelReservation'),
|
||||
controller.cancelReservationValidateV2
|
||||
);
|
||||
|
||||
router.post(
|
||||
'/reservation/cancel/v2',
|
||||
auth.authenticateToken,
|
||||
controller.validate('cancelReservationV2'),
|
||||
controller.cancelReservationV2
|
||||
);
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -1,106 +1,57 @@
|
||||
# ================================= ENVIRONMENT =================================
|
||||
# environment
|
||||
#NODE_ENV=production
|
||||
NODE_ENV=development
|
||||
#NODE_ENV=testing
|
||||
PORT=3000
|
||||
|
||||
# =========================== KONFIGURASI UNTUK SERVER ===========================
|
||||
# SERVER_FOR=development
|
||||
#SERVER_FOR=production
|
||||
SERVER_FOR=local
|
||||
# database
|
||||
DB_URL=postgresql://postgres:postgres@localhost:5432/CMS_DEV
|
||||
|
||||
# =============================== DATABASE LOCAL =================================
|
||||
# DB_URL=postgresql://postgres:postgres@localhost:5432/CMS_DEV
|
||||
DB_HOST_LOCAL=localhost
|
||||
DB_NAME_LOCAL=CMS_DEV
|
||||
DB_PORT_LOCAL=5432
|
||||
DB_USER_LOCAL=postgres
|
||||
DB_PASSWORD_LOCAL=postgres
|
||||
# crypto
|
||||
SECRET_KEY=U2FsdGVkX19keaNhiBfdNSWnKA2a8Z5deBu/KkU6BNg=
|
||||
|
||||
# ==================================== REDIS =====================================
|
||||
REDIS_URL=redis://localhost:6379
|
||||
REDIS_PASSWORD=
|
||||
|
||||
# ================================== SECRET KEY ==================================
|
||||
# FOR PRODUCTION
|
||||
#SECRET_KEY=U2FsdGVkX19keaNhiBfdNSWnKA2a8Z5deBu/KkU6BNg=
|
||||
# FOR DEVELOPMENT
|
||||
SECRET_KEY=U2FsdGVkX18tPlf9nVJEx7KwTdFsGPO/RK6A0HRYDeg=
|
||||
|
||||
# ===================================== JWT =======================================
|
||||
# jwt
|
||||
JWT_EXPIRATION=30d
|
||||
JWT_REFRESH_EXPIRATION=40d
|
||||
# FOR PRODUCTION
|
||||
#TOKEN_SECRET=101001D00C2001D0483001D0
|
||||
#REFRESH_TOKEN_SECRET=101001D00C2001D0483001D0800082008300800081008200
|
||||
# FOR DEVELOPMENT
|
||||
TOKEN_SECRET=101001A00C2001A0483001A0883001A0
|
||||
REFRESH_TOKEN_SECRET=101001A00C2001A0483001A0883001A0800082008300800081008200
|
||||
TOKEN_SECRET=U2FsdGVkX1/hnA2S3l0Evi+whG73WiOrplJA5fcfe2o=
|
||||
REFRESH_TOKEN_SECRET=U2FsdGVkX18LvuBcY6prEGXDZhDoBa7O0GAUSzTWzdk=
|
||||
|
||||
|
||||
# ===================== CHANGE TO DRC SERVER (YES or NO) ===========================
|
||||
# CHANGE TO DRC SERVER (YES or NO)
|
||||
CHANGE_TO_DRC=YES
|
||||
|
||||
# HIGH AVABILITY (1 = SERVER_HSM_1 ONLY RUNNING, 2 = SERVER_HSM_2 ONLY RUNNING, 12 = SERVER_HSM_1 && SERVER_HSM_2 RUNNING)
|
||||
NUMBER_SERVER_ACTIVE=1
|
||||
NUMBER_SERVER_ACTIVE=12
|
||||
|
||||
# ================================ KONFIGURASI HSM =================================
|
||||
# =================================== KCI =================================
|
||||
|
||||
# system code kci profile
|
||||
# FOR PRODUCTION & DEVELOPMENT
|
||||
SYSTEM_CODE=90B7
|
||||
|
||||
#SERVICE BLOCK
|
||||
# FOR PRODUCTION
|
||||
# SERVICEBLOCK_SERVICE_MUTUAL="101001D00C2001D0483001D0"
|
||||
# FOR DEVELOPMENT
|
||||
SERVICEBLOCK_SERVICE_MUTUAL="101001A00C2001A0483001A0883001A0"
|
||||
|
||||
SERVICEBLOCK_BLOCK_READ="800082008300"
|
||||
SERVICEBLOCK_SERVICE_MUTUAL="101001A00C2001A0483001A0"
|
||||
SERVICEBLOCK_BLOCK_READ="80008200"
|
||||
SERVICEBLOCK_BLOCK_WRITE="800081008200"
|
||||
|
||||
# HSM DC (DATA CENTER)
|
||||
# HSM SERVER
|
||||
# URL_HSM_SERVER_1="ws://182.253.34.129/feliqserver/v1/wsapi"
|
||||
# APIKEY_HSM_SERVER_1="bc391562-f880-3b57-9868-36dfa5cbf954-0TC"
|
||||
# SECRETKEY_HSM_SERVER_1="xWW2o+lpAqDLIN85uHZdfuDQhhd7jCXp4w1rXhCkYEk="
|
||||
# URL_HSM_SERVER_2="ws://182.253.34.129:88/feliqserver/v1/wsapi"
|
||||
# APIKEY_HSM_SERVER_2="bc391562-f880-3b57-9868-36dfa5cbf954-0TC"
|
||||
# SECRETKEY_HSM_SERVER_2="xWW2o+lpAqDLIN85uHZdfuDQhhd7jCXp4w1rXhCkYEk="
|
||||
|
||||
# # HSM DRC (DISASTER RECOVERY CENTER)
|
||||
# # HSM SERVER
|
||||
# URL_HSM_SERVER_BACKUP_1="ws://182.253.34.129/feliqserver/v1/wsapi"
|
||||
# APIKEY_HSM_SERVER_BACKUP_1="bc391562-f880-3b57-9868-36dfa5cbf954-0TC"
|
||||
# SECRETKEY_HSM_SERVER_BACKUP_1="xWW2o+lpAqDLIN85uHZdfuDQhhd7jCXp4w1rXhCkYEk="
|
||||
# URL_HSM_SERVER_BACKUP_2="ws://182.253.34.129:88/feliqserver/v1/wsapi"
|
||||
# APIKEY_HSM_SERVER_BACKUP_2="bc391562-f880-3b57-9868-36dfa5cbf954-0TC"
|
||||
# SECRETKEY_HSM_SERVER_BACKUP_2="xWW2o+lpAqDLIN85uHZdfuDQhhd7jCXp4w1rXhCkYEk="
|
||||
|
||||
# HSM DC (DATA CENTER)
|
||||
# HSM SERVER
|
||||
IP_HSM_SERVER_1="10.1.201.222"
|
||||
URL_HSM_SERVER_1="ws://10.1.201.222/feliqserver/v1/wsapi"
|
||||
# KCI PCI
|
||||
URL_HSM_SERVER_1="ws://10.1.201.215/feliqserver/v1/wsapi"
|
||||
APIKEY_HSM_SERVER_1="bc391562-f880-3b57-9868-36dfa5cbf954-0TC"
|
||||
SECRETKEY_HSM_SERVER_1="xWW2o+lpAqDLIN85uHZdfuDQhhd7jCXp4w1rXhCkYEk="
|
||||
IP_HSM_SERVER_2="10.1.201.215"
|
||||
URL_HSM_SERVER_2="ws://10.1.201.215:88/feliqserver/v1/wsapi"
|
||||
APIKEY_HSM_SERVER_2="bc391562-f880-3b57-9868-36dfa5cbf954-0TC"
|
||||
SECRETKEY_HSM_SERVER_2="xWW2o+lpAqDLIN85uHZdfuDQhhd7jCXp4w1rXhCkYEk="
|
||||
|
||||
# HSM DRC (DISASTER RECOVERY CENTER)
|
||||
# HSM SERVER
|
||||
IP_HSM_SERVER_BACKUP_1="10.1.201.222"
|
||||
# KCI PCI
|
||||
URL_HSM_SERVER_BACKUP_1="ws://10.1.201.215/feliqserver/v1/wsapi"
|
||||
APIKEY_HSM_SERVER_BACKUP_1="bc391562-f880-3b57-9868-36dfa5cbf954-0TC"
|
||||
SECRETKEY_HSM_SERVER_BACKUP_1="xWW2o+lpAqDLIN85uHZdfuDQhhd7jCXp4w1rXhCkYEk="
|
||||
IP_HSM_SERVER_BACKUP_2="10.1.201.215"
|
||||
URL_HSM_SERVER_BACKUP_2="ws://10.1.201.215:88/feliqserver/v1/wsapi"
|
||||
APIKEY_HSM_SERVER_BACKUP_2="bc391562-f880-3b57-9868-36dfa5cbf954-0TC"
|
||||
SECRETKEY_HSM_SERVER_BACKUP_2="xWW2o+lpAqDLIN85uHZdfuDQhhd7jCXp4w1rXhCkYEk="
|
||||
|
||||
|
||||
# ============================= KONFIGURASI HSM NUTECH =============================
|
||||
# =================================== NUTECH =================================
|
||||
|
||||
# SYSTEM CODE IN HEXA STRING
|
||||
# system code nutech profile
|
||||
@@ -112,20 +63,17 @@ SECRETKEY_HSM_SERVER_BACKUP_2="xWW2o+lpAqDLIN85uHZdfuDQhhd7jCXp4w1rXhCkYEk="
|
||||
# SERVICEBLOCK_BLOCK_WRITE="800081008200"
|
||||
|
||||
# HSM DC (DATA CENTER)
|
||||
# HSM SERVER
|
||||
# KCI PCI
|
||||
# URL_HSM_SERVER_1="ws://10.1.201.215/feliqserver/v1/wsapi"
|
||||
# APIKEY_HSM_SERVER_1="d54ff5c4-9709-3bac-9a6e-04b2f4deebae-0TC"
|
||||
# SECRETKEY_HSM_SERVER_1="W8ZiN1o2tNkb1svNlj5Kl8PNohhujaTxeNaGEq2rOWY="
|
||||
# JEPANG
|
||||
# URL_HSM_SERVER_1="wss://gateway04.cyberware.co.jp/feliqserver/v1/wsapi"
|
||||
# APIKEY_HSM_SERVER_1="4c6dd075-dbcb-375f-81f7-62990a5d7000-0TC"
|
||||
# SECRETKEY_HSM_SERVER_1="U5xs7nVonhtbQ+XiYATRSg8Nk5sPu1IpVx7X40KyWiw="
|
||||
# URL_HSM_SERVER_2="wss://gateway04.cyberware.co.jp/feliqserver/v1/wsapi"
|
||||
# APIKEY_HSM_SERVER_2="4c6dd075-dbcb-375f-81f7-62990a5d7000-0TC"
|
||||
# SECRETKEY_HSM_SERVER_2="U5xs7nVonhtbQ+XiYATRSg8Nk5sPu1IpVx7X40KyWiw="
|
||||
|
||||
# HSM DRC (DISASTER RECOVERY CENTER)
|
||||
# HSM SERVER
|
||||
# KCI PCI
|
||||
# URL_HSM_SERVER_BACKUP_1="ws://10.1.201.215/feliqserver/v1/wsapi"
|
||||
# APIKEY_HSM_SERVER_BACKUP_1="d54ff5c4-9709-3bac-9a6e-04b2f4deebae-0TC"
|
||||
# SECRETKEY_HSM_SERVER_BACKUP_1="W8ZiN1o2tNkb1svNlj5Kl8PNohhujaTxeNaGEq2rOWY="
|
||||
@@ -134,5 +82,3 @@ SECRETKEY_HSM_SERVER_BACKUP_2="xWW2o+lpAqDLIN85uHZdfuDQhhd7jCXp4w1rXhCkYEk="
|
||||
# APIKEY_HSM_SERVER_BACKUP_2="4c6dd075-dbcb-375f-81f7-62990a5d7000-0TC"
|
||||
# SECRETKEY_HSM_SERVER_BACKUP_2="U5xs7nVonhtbQ+XiYATRSg8Nk5sPu1IpVx7X40KyWiw="
|
||||
|
||||
|
||||
|
||||
|
||||
+11
-11
@@ -16,22 +16,23 @@ const cron = require('node-cron');
|
||||
const moment = require('moment');
|
||||
require('dotenv').config();
|
||||
moment.locale('id');
|
||||
const responseTime = require('response-time');
|
||||
const { logger } = require('../application/helpers/getbodyrequest');
|
||||
const client = require('prom-client');
|
||||
const responseTime = require("response-time");
|
||||
const { logger } = require("../application/helpers/getbodyrequest")
|
||||
const client = require("prom-client");
|
||||
const register = new client.Registry();
|
||||
const {
|
||||
topuponline_metrics,
|
||||
} = require('../application/helpers/prometheusmetrics');
|
||||
const {topuponline_metrics} = require("../application/helpers/prometheusmetrics");
|
||||
const {prometheusMiddleware} = require("../application/middlewares/prometheus.middleware")
|
||||
const lokiMiddleware = require("../application/middlewares/loki.middleware")
|
||||
const redisMiddleware = require("../application/middlewares/redis.middleware")
|
||||
|
||||
const app = express();
|
||||
|
||||
register.setDefaultLabels({ app: 'topuponline' });
|
||||
register.setDefaultLabels({ app: "topuponline" });
|
||||
client.collectDefaultMetrics({ register });
|
||||
register.registerMetric(topuponline_metrics);
|
||||
|
||||
app.get('/metrics', (req, res) => {
|
||||
res.setHeader('Content-Type', register.contentType);
|
||||
app.get("/metrics", (req, res) => {
|
||||
res.setHeader("Content-Type", register.contentType);
|
||||
register.metrics().then((data) => res.send(data));
|
||||
});
|
||||
|
||||
@@ -70,7 +71,6 @@ app.get('/', async (req, res) => {
|
||||
chipper_data: chipperData,
|
||||
decrypt_data: decrypData,
|
||||
date: moment().format('YYYYMMDDHHmm'),
|
||||
secret_key: helper.encryptText('0nlinetopupDev'),
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -84,7 +84,7 @@ app.use('/api/', historyRoute);
|
||||
app.use('/api/', hsmRoute);
|
||||
app.use('/api/', loadBalanceRoute);
|
||||
app.use('/api/', paymentReconRoute);
|
||||
app.use('/api/', reservationRoute);
|
||||
app.use('/api/', prometheusMiddleware, lokiMiddleware, redisMiddleware, reservationRoute);
|
||||
app.use('/api/', invoiceRoute);
|
||||
app.use('/api/', cashinRoute);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user