Compare commits

...

23 Commits

Author SHA1 Message Date
ihsan 083e0af4a0 disabled cluster 2023-10-04 17:36:49 +07:00
ihsan b87e6cc450 update 2023-10-04 16:46:55 +07:00
ihsan afc72b73ec update 2023-10-04 16:09:50 +07:00
ihsan a2079a7263 update log 2023-10-02 13:36:24 +07:00
ihsan 19de123628 update bugs redis set sequence 2023-10-02 10:44:19 +07:00
ihsan 69ab898bf3 update bugs 2023-09-28 13:08:51 +07:00
Mohamad Lutfi d5df8d4f32 update generate cash-in 2023-09-25 11:49:22 +07:00
ihsan ae74b4c1bd update comment log debug 2023-09-25 11:30:59 +07:00
ihsan dab14b66c4 update fraud bugs 2023-09-21 18:34:05 +07:00
ihsan 481858117d update 2023-09-17 14:55:55 +07:00
ihsan 1fd9940706 update bugs load balance 2023-09-04 09:23:18 +07:00
ihsan 5d8f4d086e update set redis reserve balance 2023-09-01 14:36:35 +07:00
ihsan 409fe6f0ce update 2023-09-01 14:28:53 +07:00
ihsan d0e3fb289e update bugs 2023-08-31 23:50:00 +07:00
ihsan fc28f4e767 update bugs 2023-08-31 23:40:39 +07:00
ihsan 4f69c84b5f update 2023-08-31 23:34:02 +07:00
ihsan 44f81586e3 add redis lodbalance sequence 2023-08-31 23:25:49 +07:00
ihsan e51a7bc98c update bug reservation sequence 2023-08-31 22:42:31 +07:00
ihsan af52b6916b update 2023-08-31 22:36:36 +07:00
ihsan ad0942a93d update 2023-08-31 22:22:23 +07:00
ihsan 4828a230fb debug 2023-08-31 22:18:58 +07:00
ihsan 933e83cd1a update 2023-08-31 22:12:41 +07:00
ihsan 97860df622 update bugs 2023-08-31 21:44:22 +07:00
15 changed files with 861 additions and 663 deletions
@@ -121,8 +121,71 @@ const setReservationNumberSequence = async (partner_id, sequence) => {
} }
}; };
const getLoadBalanceNumberSequence = async (req, res, next) => {
// set default load_balance_number_sequence dari partner apapun is null
req.load_balance_number_sequence = null;
// cek jika redis is connect
let isRedisReady = await redisClient.isReady;
// jika tidak connect
if (isRedisReady) {
// jika connect maka cari sequence dari reservation number sesuai partner yg merequest
// format value nya harusnya seperti ini = { date: '2023-01-01', sequence: 1 }
// data req.partner_id_token di dapat dari authenticateToken di jwt middleware
let getValue = await redisClient.GET(
'load_balance_number_sequence_' + req.partner_id_token
);
if (getValue) {
// parsing data menjadi json format
let parsedValue = JSON.parse(getValue);
// cek apakah tanggal sequence yang di redis sama dengan hari ini atau bukan
if (parsedValue.date == moment().format('YYYY-MM-DD')) {
// jika tanggal nya sama dengan hari ini maka ambil sequence untuk reservation number yang di generate dari redis
req.load_balance_number_sequence = parseInt(parsedValue.sequence);
// langsung update sequence walaupun transaksi insert nya belum selesai
// impact menggunakan redis, untuk nomor sequence bisa saja ada yg loncat karena bisa saja ada transaksi insert reservation yang gagal
let setValue = {
date: moment().format('YYYY-MM-DD'),
sequence: parseInt(parsedValue.sequence) + 1,
};
await redisClient.SET(
`load_balance_number_sequence_${req.partner_id_token}`,
JSON.stringify(setValue)
);
}
}
}
next();
};
const setLoadBalanceNumberSequence = async (partner_id, sequence) => {
// cek jika redis is connect
let isRedisReady = await redisClient.isReady;
// jika tidak connect
if (isRedisReady) {
// jika connect maka cari sequence dari reservation number sesuai partner yg merequest
// format value nya harusnya seperti ini = { date: '2023-01-01', sequence: 1 }
let setValue = {
date: moment().format('YYYY-MM-DD'),
sequence: parseInt(sequence),
};
await redisClient.SET(
`load_balance_number_sequence_${partner_id}`,
JSON.stringify(setValue)
);
}
};
module.exports = { module.exports = {
redisMiddleware, redisMiddleware,
getReservationNumberSequence, getReservationNumberSequence,
setReservationNumberSequence, setReservationNumberSequence,
getLoadBalanceNumberSequence,
setLoadBalanceNumberSequence,
}; };
+75 -75
View File
@@ -101,9 +101,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 +129,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 +158,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 +171,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 +184,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);
@@ -263,9 +263,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 +285,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 +309,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 +336,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 +347,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 +358,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 +437,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 +459,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 +483,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 +507,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);
@@ -585,17 +585,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 +623,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 +637,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 +648,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);
@@ -731,17 +731,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 +768,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 +807,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 +820,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);
+5 -2
View File
@@ -225,6 +225,7 @@ const getReserve = async(trx, code, date, invoice) => {
}) })
.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', '=', 'tdrb.c_invoice_no')
}) })
.leftJoin('payment.t_d_payment_recon as tdpr', function () { .leftJoin('payment.t_d_payment_recon as tdpr', function () {
this.on('tdpr.c_reservation_no', '=', 'tdrb.c_reservation_no') this.on('tdpr.c_reservation_no', '=', 'tdrb.c_reservation_no')
@@ -266,13 +267,15 @@ const getPartnerRecon = async(trx) => {
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', '=', 'tdrb.c_invoice_no')
}) })
.leftJoin('payment.t_d_payment_recon as tdpr', function () { .leftJoin('payment.t_d_payment_recon as tdpr', function () {
this.on('tdpr.c_reservation_no', '=', 'tdrb.c_reservation_no') this.on('tdpr.c_reservation_no', '=', 'tdrb.c_reservation_no')
}) })
.leftJoin('public.t_m_partner as tmp', function () { .leftJoin('public.t_m_partner as tmp', function () {
this.on('tmp.c_code', '=', 'tdrb.c_partner_code') this.on('tmp.i_partner', '=', 'tdrb.i_partner')
}) })
.where("tdrb.c_status", "=", "A") .where("tdrb.c_status", "=", "A")
@@ -228,9 +228,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 +251,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 +275,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(
+14 -14
View File
@@ -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`);
+14 -14
View File
@@ -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`);
+1 -1
View File
@@ -205,7 +205,7 @@ const controller = async (req, res) => {
}; };
// insert data load balance // insert data load balance
let insert = await loadBalance.loadingBalanceInsert(data); let insert = await loadBalance.loadingBalanceInsert(req, data);
if (insert) { if (insert) {
if (insert.code == '00') { if (insert.code == '00') {
result = { result = {
+17 -2
View File
@@ -206,8 +206,9 @@ const controller = async (req, res) => {
); );
// update data load balance // update data load balance
await loadBalance.loadingBalanceUpdate(data); let update = await loadBalance.loadingBalanceUpdate(data);
if (update) {
if (update.code == '00') {
result = { result = {
code: '5002', code: '5002',
message: 'failed from HSM', message: 'failed from HSM',
@@ -218,6 +219,20 @@ const controller = async (req, res) => {
load_balance_number: update.data.load_balance_number, load_balance_number: update.data.load_balance_number,
}, },
}; };
} else {
result = {
code: update.code,
message: update.message,
data: {},
};
}
} else {
result = {
code: '423',
message: 'update/insert failed',
data: {},
};
}
} else { } else {
// jika sudah mencapai maksimum counting flag, maka reset flag ke awal // jika sudah mencapai maksimum counting flag, maka reset flag ke awal
if (flag >= 255) { if (flag >= 255) {
@@ -2,9 +2,16 @@ const { param, body, validationResult } = require('express-validator');
const helper = require('../../helpers/helper'); const helper = require('../../helpers/helper');
const winston = require('../../helpers/winston.logger'); const winston = require('../../helpers/winston.logger');
const model = require('./loadbalance.model'); const model = require('./loadbalance.model');
const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const moment = require('moment'); const moment = require('moment');
const {
setLoadBalanceNumberSequence,
} = require('../../middlewares/redis.middleware');
moment.locale('id'); moment.locale('id');
// variable yang digunakan untuk melakukan perulangan proses generate reservation number jika reservation number yang di generate sudah digunakan orang lain
var maxLoopParameter = 1000;
// VALIDATION // VALIDATION
const validate = (method) => { const validate = (method) => {
switch (method) { switch (method) {
@@ -61,7 +68,7 @@ const generateLoadBalanceNumber = async (data, date, counter) => {
// insert to temp load balance number // insert to temp load balance number
let insert = await model.insertLoadBalanceNumber(loadBalanceNumber); let insert = await model.insertLoadBalanceNumber(loadBalanceNumber);
if (!insert) { if (insert.rowCount < 1) {
loadBalanceNumber = 'XX'; loadBalanceNumber = 'XX';
} }
return loadBalanceNumber; return loadBalanceNumber;
@@ -218,14 +225,12 @@ const updateAllTransaction = async (
// generate load balance number // generate load balance number
let newLoadBalanceNumber; let newLoadBalanceNumber;
let getLoadBalanceSequence; let getLoadBalanceSequence;
let loadBalanceNoSequence; let loadBalanceNoSequence = req.load_balance_number_sequence;
let maxLoop = 0;
do {
// log debug
winston.logger.debug(
`${uniqueCode} getting loading balance sequence...`
);
// log debug
winston.logger.debug(`${uniqueCode} getting loading balance sequence...`);
if (!loadBalanceNoSequence) {
// get loading balance // get loading balance
getLoadBalanceSequence = await model.getLoadBalanceSequence( getLoadBalanceSequence = await model.getLoadBalanceSequence(
getPartner, getPartner,
@@ -234,6 +239,21 @@ const updateAllTransaction = async (
loadBalanceNoSequence = getLoadBalanceSequence loadBalanceNoSequence = getLoadBalanceSequence
? parseInt(getLoadBalanceSequence.i_load_balance_no_seq) + 1 ? parseInt(getLoadBalanceSequence.i_load_balance_no_seq) + 1
: 1; : 1;
}
let maxLoop = 0;
do {
// await _sleep(helper.randomNumberInt());
if (maxLoop > 0) {
loadBalanceNoSequence++;
}
// set sequence to redis
await setLoadBalanceNumberSequence(
req.partner_id_token,
loadBalanceNoSequence
);
// log warn // log warn
winston.logger.warn(`${uniqueCode} generating load balance number...`); winston.logger.warn(`${uniqueCode} generating load balance number...`);
@@ -244,15 +264,23 @@ const updateAllTransaction = async (
loadBalanceNoSequence loadBalanceNoSequence
); );
if (newLoadBalanceNumber != 'XX') {
// set sequence to redis
// await setLoadBalanceNumberSequence(
// req.partner_id_token,
// loadBalanceNoSequence
// );
}
// log warn // log warn
winston.logger.warn( winston.logger.warn(
`${uniqueCode} load balance number is ${newLoadBalanceNumber}.` `${uniqueCode} load balance number is ${newLoadBalanceNumber}.`
); );
if (maxLoop > 20) { if (maxLoop > maxLoopParameter) {
// create log // create log
winston.logger.error( winston.logger.error(
`500 internal server error (max loop) - backend server | ${error.message}` `${uniqueCode} 500 internal server error. Server is busy. please try again`
); );
return false; return false;
@@ -303,26 +331,26 @@ const updateAllTransaction = async (
await model.createDetailLoadBalanceFromReservation(reservationNumber); await model.createDetailLoadBalanceFromReservation(reservationNumber);
// log debug // log debug
winston.logger.debug( // winston.logger.debug(
`${uniqueCode} detail load balance with reservation no : ${JSON.stringify( // `${uniqueCode} detail load balance with reservation no : ${JSON.stringify(
reservationNumber // reservationNumber
)}` // )}`
); // );
if (detailLoadBalance.length > 0) { if (detailLoadBalance.length > 0) {
// log warn // log warn
winston.logger.warn( // winston.logger.warn(
`${uniqueCode} AAAAAAAAAAAAAAAAAA1111 [DATA] : ${JSON.stringify( // `${uniqueCode} AAAAAAAAAAAAAAAAAA1111 [DATA] : ${JSON.stringify(
reservationNumber // reservationNumber
)} [LB] : ${JSON.stringify(dataLoadBalance)} [LBD] : ${JSON.stringify( // )} [LB] : ${JSON.stringify(dataLoadBalance)} [LBD] : ${JSON.stringify(
detailLoadBalance // detailLoadBalance
)} [NOW] : ${JSON.stringify(now)} [FLAG] : ${JSON.stringify(flag)}` // )} [NOW] : ${JSON.stringify(now)} [FLAG] : ${JSON.stringify(flag)}`
); // );
// log debug // log debug
winston.logger.debug( // winston.logger.debug(
`${uniqueCode} updating reservation and insert new load balance transaction...` // `${uniqueCode} updating reservation and insert new load balance transaction...`
); // );
// update reservation and load balance transaction // update reservation and load balance transaction
let updateReservationAndInsertLoadingBalance = let updateReservationAndInsertLoadingBalance =
@@ -335,11 +363,11 @@ const updateAllTransaction = async (
); );
// log debug // log debug
winston.logger.debug( // winston.logger.debug(
`${uniqueCode} status insert new load balance and update reservation : ${JSON.stringify( // `${uniqueCode} status insert new load balance and update reservation : ${JSON.stringify(
updateReservationAndInsertLoadingBalance // updateReservationAndInsertLoadingBalance
)}` // )}`
); // );
// if (updateReservationAndInsertLoadingBalance > 0) { // if (updateReservationAndInsertLoadingBalance > 0) {
// // log debug // // log debug
@@ -429,9 +457,9 @@ const loadingBalanceRequest = async (req, res) => {
} }
// log debug // log debug
winston.logger.debug( // winston.logger.debug(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking production card number or not...` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking production card number or not...`
); // );
// jika settingan untuk server adalah production // jika settingan untuk server adalah production
if (process.env.SERVER_FOR == 'production') { if (process.env.SERVER_FOR == 'production') {
@@ -479,9 +507,9 @@ const loadingBalanceRequest = async (req, res) => {
let month = moment().format('M'); let month = moment().format('M');
// log debug // log debug
winston.logger.debug( // winston.logger.debug(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking partner...` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking partner...`
); // );
// get partner, merchant, terminal from tid // get partner, merchant, terminal from tid
let getPartner = await model.getPartner(mid, tid); let getPartner = await model.getPartner(mid, tid);
@@ -529,9 +557,9 @@ const loadingBalanceRequest = async (req, res) => {
// jika settingan pengecekkan nomor kartu dengan card product CMS aktif // jika settingan pengecekkan nomor kartu dengan card product CMS aktif
if (checkByCardProductStatusValue == 'A') { if (checkByCardProductStatusValue == 'A') {
// log debug // log debug
winston.logger.debug( // winston.logger.debug(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking card number...` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking card number...`
); // );
// check card number request dengan list card number yang terdaftar di CMS // check card number request dengan list card number yang terdaftar di CMS
let checkCardNumber = await model.checkCardNumber(card_number); let checkCardNumber = await model.checkCardNumber(card_number);
@@ -556,9 +584,9 @@ const loadingBalanceRequest = async (req, res) => {
} }
// log debug // log debug
winston.logger.debug( // winston.logger.debug(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking flag on the card and the server...` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking flag on the card and the server...`
); // );
// check last flag untuk nomor kartu dan uid yang di request di sistem CMS // check last flag untuk nomor kartu dan uid yang di request di sistem CMS
let checkFlag = await model.checkFlag(card_number, uid.toUpperCase()); let checkFlag = await model.checkFlag(card_number, uid.toUpperCase());
@@ -570,9 +598,9 @@ const loadingBalanceRequest = async (req, res) => {
} }
// log debug // log debug
winston.logger.debug( // winston.logger.debug(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking reservation pending...` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking reservation pending...`
); // );
// get total reservation pending // get total reservation pending
let getReservationPending = await model.getReservationPendingV2( let getReservationPending = await model.getReservationPendingV2(
@@ -582,9 +610,9 @@ const loadingBalanceRequest = async (req, res) => {
); );
// log debug // log debug
winston.logger.debug( // winston.logger.debug(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking fraud transaction...` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking fraud transaction...`
); // );
// cek disini apakah sebelumnya topup // cek disini apakah sebelumnya topup
let cardHistory = await model.checkCardHistory(card_number); let cardHistory = await model.checkCardHistory(card_number);
@@ -647,9 +675,9 @@ const loadingBalanceRequest = async (req, res) => {
await model.getReservationPendingWithFlagCounter(card_number, now, flag); await model.getReservationPendingWithFlagCounter(card_number, now, flag);
// log debug // log debug
winston.logger.debug( // winston.logger.debug(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking reservation pending with flag...` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking reservation pending with flag...`
); // );
// get total reservation pending // get total reservation pending
// let getReservationPendingWithFlag = // let getReservationPendingWithFlag =
// await model.getReservationPendingWithFlag(card_number, now); // await model.getReservationPendingWithFlag(card_number, now);
@@ -674,9 +702,9 @@ const loadingBalanceRequest = async (req, res) => {
}); });
// log debug // log debug
winston.logger.debug( // winston.logger.debug(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: updating reservation and load balance transaction...` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: updating reservation and load balance transaction...`
); // );
// update // update
let insertUpdate = await updateAllTransaction( let insertUpdate = await updateAllTransaction(
@@ -694,9 +722,9 @@ const loadingBalanceRequest = async (req, res) => {
if (insertUpdate) { if (insertUpdate) {
// log debug // log debug
winston.logger.debug( // winston.logger.debug(
`${uniqueCode} [ PROCESSINGE LOADING-BALANCE-REQUEST ]: updating flag to server...` // `${uniqueCode} [ PROCESSINGE LOADING-BALANCE-REQUEST ]: updating flag to server...`
); // );
// update flag from Server // update flag from Server
await model.updateFlag( await model.updateFlag(
@@ -747,9 +775,9 @@ const loadingBalanceRequest = async (req, res) => {
// await model.updateFlag(now, card_number, uid.toUpperCase(), balance, flag); // await model.updateFlag(now, card_number, uid.toUpperCase(), balance, flag);
// log debug // log debug
winston.logger.debug( // winston.logger.debug(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking reservation pending...` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking reservation pending...`
); // );
// reget total reservation pending // reget total reservation pending
getReservationPending = await model.getReservationPendingV2( getReservationPending = await model.getReservationPendingV2(
@@ -807,14 +835,14 @@ const loadingBalanceRequest = async (req, res) => {
} }
// log debug // log debug
winston.logger.debug( // winston.logger.debug(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking the card number in list fraud transaction or not...XXXXXXXXXXXXXXXXXXXX` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking the card number in list fraud transaction or not...XXXXXXXXXXXXXXXXXXXX`
); // );
// log debug // log debug
winston.logger.debug( // winston.logger.debug(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking total topup amount...` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking total topup amount...`
); // );
// check total amount topup // check total amount topup
if (parseInt(amountTopup) <= 0) { if (parseInt(amountTopup) <= 0) {
@@ -835,9 +863,9 @@ const loadingBalanceRequest = async (req, res) => {
} }
// log debug // log debug
winston.logger.debug( // winston.logger.debug(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking BI regulation status...` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking BI regulation status...`
); // );
// get BI regulation status // get BI regulation status
let getBIRegulationStatus = await model.getBIRegulationStatus(); let getBIRegulationStatus = await model.getBIRegulationStatus();
@@ -861,7 +889,7 @@ const loadingBalanceRequest = async (req, res) => {
if (getBIRegulationStatus.c_value == 'A') { if (getBIRegulationStatus.c_value == 'A') {
// log debug // log debug
winston.logger.debug(`${uniqueCode} checking topup partial status...`); // winston.logger.debug(`${uniqueCode} checking topup partial status...`);
// check topup partial status // check topup partial status
let getTopupPartialStatus = await model.getTopupPartialStatus(); let getTopupPartialStatus = await model.getTopupPartialStatus();
@@ -884,9 +912,9 @@ const loadingBalanceRequest = async (req, res) => {
} }
// log debug // log debug
winston.logger.debug( // winston.logger.debug(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking max balance on the card...` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking max balance on the card...`
); // );
// get max saldo on the card // get max saldo on the card
let getMaxAmountOnTheCard = await model.getMaxAmountOnTheCard(); let getMaxAmountOnTheCard = await model.getMaxAmountOnTheCard();
@@ -985,9 +1013,9 @@ const loadingBalanceRequest = async (req, res) => {
} }
// log debug // log debug
winston.logger.debug( // winston.logger.debug(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking max topup per month...` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: checking max topup per month...`
); // );
// get accumulated balance in this month // get accumulated balance in this month
let accumulatedBalance = 0; let accumulatedBalance = 0;
@@ -1099,9 +1127,9 @@ const loadingBalanceRequest = async (req, res) => {
} }
// log debug // log debug
winston.logger.debug( // winston.logger.debug(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: updating status reservation to in progress...${reservationNumberTemp}, ${now}, ${flag}` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-REQUEST ]: updating status reservation to in progress...${reservationNumberTemp}, ${now}, ${flag}`
); // );
// update status to in progress // update status to in progress
let updateStatusReservation = await model.updateStatusReservation( let updateStatusReservation = await model.updateStatusReservation(
@@ -1171,7 +1199,7 @@ const loadingBalanceRequest = async (req, res) => {
// *Description:* // *Description:*
// proses insert data topup atau load balance ke sistem CMS // proses insert data topup atau load balance ke sistem CMS
const loadingBalanceInsert = async (param) => { const loadingBalanceInsert = async (req, param) => {
try { try {
// param // param
let mid = param.mid; let mid = param.mid;
@@ -1224,9 +1252,9 @@ const loadingBalanceInsert = async (param) => {
} }
// log warn // log warn
winston.logger.warn( // winston.logger.warn(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: checking reservation status...` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: checking reservation status...`
); // );
// check reservation status // check reservation status
for (let index = 0; index < reservation_number.length; index++) { for (let index = 0; index < reservation_number.length; index++) {
@@ -1285,9 +1313,9 @@ const loadingBalanceInsert = async (param) => {
} }
// log warn // log warn
winston.logger.warn( // winston.logger.warn(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: checking last log history...` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: checking last log history...`
); // );
// get last history by card number // get last history by card number
let lastHistory = await model.getLastHistory(card_number); let lastHistory = await model.getLastHistory(card_number);
@@ -1296,17 +1324,17 @@ const loadingBalanceInsert = async (param) => {
// if last history card is topup (21 = log name id for topup) // if last history card is topup (21 = log name id for topup)
if (lastHistory.i_log_name == 21 && lastHistory.c_source == 'CMS') { if (lastHistory.i_log_name == 21 && lastHistory.c_source == 'CMS') {
// log warn // log warn
winston.logger.warn( // winston.logger.warn(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: inserting fraud transaction...` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: inserting fraud transaction...`
); // );
// insert reservation transaction to fraud table // insert reservation transaction to fraud table
await model.insertFraudTransaction(reservation_number); await model.insertFraudTransaction(reservation_number);
// log warn // log warn
winston.logger.warn( // winston.logger.warn(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: suspending reservation...` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: suspending reservation...`
); // );
// update reservation with suspend status // update reservation with suspend status
await model.suspendReservation(reservation_number, now); await model.suspendReservation(reservation_number, now);
@@ -1329,9 +1357,9 @@ const loadingBalanceInsert = async (param) => {
} }
// log warn // log warn
winston.logger.warn( // winston.logger.warn(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: checking fraud transaction...` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: checking fraud transaction...`
); // );
// get data fraud by card number and status fraud is not closed // get data fraud by card number and status fraud is not closed
let fraudTransaction = await model.getFraudTransaction(card_number); let fraudTransaction = await model.getFraudTransaction(card_number);
@@ -1344,9 +1372,9 @@ const loadingBalanceInsert = async (param) => {
} }
// log warn // log warn
winston.logger.warn( // winston.logger.warn(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: checking reservation pending...` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: checking reservation pending...`
); // );
// get total reservation pending without fraud // get total reservation pending without fraud
let getReservationPending = await model.getReservationPendingWithoutFraud( let getReservationPending = await model.getReservationPendingWithoutFraud(
@@ -1373,9 +1401,9 @@ const loadingBalanceInsert = async (param) => {
} }
// log warn // log warn
winston.logger.warn( // winston.logger.warn(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: checking total topup amount...` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: checking total topup amount...`
); // );
// check total topup and request topup // check total topup and request topup
let amountTopup = 0; let amountTopup = 0;
@@ -1403,14 +1431,14 @@ const loadingBalanceInsert = async (param) => {
// generate load balance number // generate load balance number
let loadBalanceNumber; let loadBalanceNumber;
let getLoadBalanceSequence; let getLoadBalanceSequence;
let loadBalanceNoSequence; let loadBalanceNoSequence = req.load_balance_number_sequence;
let maxLoop = 0;
do {
// log debug
winston.logger.debug(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: getting loading balance sequence...`
);
// log debug
// winston.logger.debug(
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: getting loading balance sequence...`
// );
if (!loadBalanceNoSequence) {
// get loading balance // get loading balance
getLoadBalanceSequence = await model.getLoadBalanceSequence( getLoadBalanceSequence = await model.getLoadBalanceSequence(
getPartner, getPartner,
@@ -1419,11 +1447,26 @@ const loadingBalanceInsert = async (param) => {
loadBalanceNoSequence = getLoadBalanceSequence loadBalanceNoSequence = getLoadBalanceSequence
? parseInt(getLoadBalanceSequence.i_load_balance_no_seq) + 1 ? parseInt(getLoadBalanceSequence.i_load_balance_no_seq) + 1
: 1; : 1;
}
let maxLoop = 0;
do {
// await _sleep(helper.randomNumberInt());
if (maxLoop > 0) {
loadBalanceNoSequence++;
}
// set sequence to redis
await setLoadBalanceNumberSequence(
req.partner_id_token,
loadBalanceNoSequence
);
// log warn // log warn
winston.logger.warn( // winston.logger.warn(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: generating load balance number...` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: generating load balance number...`
); // );
loadBalanceNumber = await generateLoadBalanceNumber( loadBalanceNumber = await generateLoadBalanceNumber(
getPartner, getPartner,
@@ -1431,22 +1474,30 @@ const loadingBalanceInsert = async (param) => {
loadBalanceNoSequence loadBalanceNoSequence
); );
// log warn if (loadBalanceNumber != 'XX') {
winston.logger.warn( // set sequence to redis
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: load balance number is ${loadBalanceNumber}.` // await setLoadBalanceNumberSequence(
); // req.partner_id_token,
// loadBalanceNoSequence
// );
}
if (maxLoop > 20) { // log warn
// winston.logger.warn(
// `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: load balance number is ${loadBalanceNumber}.`
// );
if (maxLoop > maxLoopParameter) {
// create log // create log
winston.logger.error( winston.logger.error(
`[ RESPONSE LOADING-BALANCE-INSERT ]: 500 internal server error (max loop) - backend server | ${error.message}` `${uniqueCode} [ RESPONSE LOADING-BALANCE-INSERT ]: 500 internal server error. Server is busy. please try again`
); );
return { return {
code: '500', code: '500',
message: message:
process.env.NODE_ENV != 'production' process.env.NODE_ENV != 'production'
? error.message ? '500 internal server error (max loop) - backend server.'
: '500 internal server error (max loop) - backend server.', : '500 internal server error (max loop) - backend server.',
data: {}, data: {},
}; };
@@ -1494,9 +1545,9 @@ const loadingBalanceInsert = async (param) => {
}; };
// log debug // log debug
winston.logger.debug( // winston.logger.debug(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: getting reservation detail...` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: getting reservation detail...`
); // );
let detail = []; let detail = [];
reservation_number = []; reservation_number = [];
@@ -1562,14 +1613,14 @@ const loadingBalanceInsert = async (param) => {
// check data load balance by reservation_number exist or not // check data load balance by reservation_number exist or not
// log debug // log debug
winston.logger.debug( // winston.logger.debug(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: checking load balance transaction has been exists or not...` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: checking load balance transaction has been exists or not...`
); // );
// log warn // log warn
winston.logger.warn( // winston.logger.warn(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: inserting load balance transaction...` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-INSERT ]: inserting load balance transaction...`
); // );
// insert transaction // insert transaction
let insertLoadingBalance = await model.insertLoadingBalance( let insertLoadingBalance = await model.insertLoadingBalance(
@@ -1585,19 +1636,19 @@ const loadingBalanceInsert = async (param) => {
); );
// log warn // log warn
winston.logger.warn( // winston.logger.warn(
`${uniqueCode} [DATA] : ${JSON.stringify( // `${uniqueCode} [DATA] : ${JSON.stringify(
data // data
)} [DETAIL] : ${JSON.stringify(detail)} [RSV] : ${JSON.stringify( // )} [DETAIL] : ${JSON.stringify(detail)} [RSV] : ${JSON.stringify(
reservation_number // reservation_number
)} [NOW] : ${JSON.stringify(now)} [WRITE STATUS] : ${JSON.stringify( // )} [NOW] : ${JSON.stringify(now)} [WRITE STATUS] : ${JSON.stringify(
write_status // write_status
)} [CARD NUMBER] : ${JSON.stringify( // )} [CARD NUMBER] : ${JSON.stringify(
card_number // card_number
)} [UID] : ${JSON.stringify(uid)} [BALANCE] : ${JSON.stringify( // )} [UID] : ${JSON.stringify(uid)} [BALANCE] : ${JSON.stringify(
balance // balance
)} [FLAG] : ${JSON.stringify(flag)}` // )} [FLAG] : ${JSON.stringify(flag)}`
); // );
if (insertLoadingBalance > 0) { if (insertLoadingBalance > 0) {
result = { result = {
@@ -1687,9 +1738,9 @@ const loadingBalanceUpdate = async (param) => {
let today = moment().format('YYYY-MM-DD'); let today = moment().format('YYYY-MM-DD');
// log debug // log debug
winston.logger.debug( // winston.logger.debug(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-UPDATE ]: checking partner...` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-UPDATE ]: checking partner...`
); // );
// get partner, merchant, terminal from tid // get partner, merchant, terminal from tid
let getPartner = await model.getPartner(mid, tid); let getPartner = await model.getPartner(mid, tid);
@@ -1724,9 +1775,9 @@ const loadingBalanceUpdate = async (param) => {
}; };
// log debug // log debug
winston.logger.debug( // winston.logger.debug(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-UPDATE ]: updating load balance transaction...` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-UPDATE ]: updating load balance transaction...`
); // );
// update transaction // update transaction
await model.updateLoadingBalance( await model.updateLoadingBalance(
@@ -1741,9 +1792,9 @@ const loadingBalanceUpdate = async (param) => {
); );
// log debug // log debug
winston.logger.debug( // winston.logger.debug(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-UPDATE ]: inserting load balance transaction history ${loadBalanceNumber}...` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-UPDATE ]: inserting load balance transaction history ${loadBalanceNumber}...`
); // );
let findDataLoadBalance = await model.findLoadBalance(loadBalanceNumber); let findDataLoadBalance = await model.findLoadBalance(loadBalanceNumber);
let dataLoadBalance = {}; let dataLoadBalance = {};
@@ -1827,9 +1878,9 @@ const loadingBalanceUpdate = async (param) => {
if (!write_status) { if (!write_status) {
// log debug // log debug
winston.logger.debug( // winston.logger.debug(
`${uniqueCode} [ PROCESSING LOADING-BALANCE-UPDATE ]: inserting log for card history...` // `${uniqueCode} [ PROCESSING LOADING-BALANCE-UPDATE ]: inserting log for card history...`
); // );
// log card history // log card history
await model.createLoadBalanceLog({ await model.createLoadBalanceLog({
@@ -861,6 +861,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,7 +881,9 @@ const insertFraudTransaction = (reservationNumber) => {
let result = knex let result = knex
.into( .into(
knex.raw('?? (??, ??, ??, ??, ??, ??)', [ knex.raw(
'?? (??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??)',
[
'trx.t_d_fraud', 'trx.t_d_fraud',
'c_card_number', 'c_card_number',
'c_reservation_no', 'c_reservation_no',
@@ -888,7 +891,21 @@ const insertFraudTransaction = (reservationNumber) => {
'c_reservation_status', 'c_reservation_status',
'c_reservation_flag', 'c_reservation_flag',
'c_reservation_ref_no', '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 +914,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(
@@ -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);
@@ -167,9 +167,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 +221,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 +241,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 +270,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 +289,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 +331,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 +373,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 +409,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 +434,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',
File diff suppressed because it is too large Load Diff
+4
View File
@@ -2,10 +2,14 @@ const express = require('express');
const router = express.Router(); const router = express.Router();
const auth = require('../middlewares/jwt.middleware'); const auth = require('../middlewares/jwt.middleware');
const controller = require('../modules/loadbalance/loadbalance.controller'); const controller = require('../modules/loadbalance/loadbalance.controller');
const {
getLoadBalanceNumberSequence,
} = require('../middlewares/redis.middleware');
router.post( router.post(
'/loadbalance/request', '/loadbalance/request',
auth.authenticateToken, auth.authenticateToken,
getLoadBalanceNumberSequence,
controller.validate('loadingBalanceRequest'), controller.validate('loadingBalanceRequest'),
controller.loadingBalanceRequest controller.loadingBalanceRequest
); );
+15 -15
View File
@@ -29,25 +29,25 @@ if (process.env.CHANGE_TO_DRC == 'YES' || process.env.CHANGE_TO_DRC == 'yes') {
} }
} }
if (cluster.isMaster) { // if (cluster.isMaster) {
console.log(`Number of CPUs is ${totalCPUs}`); // console.log(`Number of CPUs is ${totalCPUs}`);
console.log(`Master ${process.pid} is running`); // 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) => { // cluster.on('exit', (worker, code, signal) => {
console.log(`worker ${worker.process.pid} died`); // console.log(`worker ${worker.process.pid} died`);
console.log("Let's fork another worker!"); // console.log("Let's fork another worker!");
cluster.fork(); // cluster.fork();
}); // });
} else { // } else {
startExpress(); startExpress();
} // }
console.log(`worker pid=${process.pid}`); // console.log(`worker pid=${process.pid}`);
function startExpress() { function startExpress() {
server.listen(PORT, () => { server.listen(PORT, () => {
+24
View File
@@ -6,6 +6,29 @@ let port;
let user; let user;
let password; let password;
if (process.env.CUSTOM_MODE_NODE_ENV == 'devprod') {
// blok ini hanya digunakan untuk kebutuhan testing
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.20.14.14';
database = 'postgres';
port = 5432;
user = 'postgres';
password = 'inhc0mmute_cms';
}
} else {
// setting an normal harusnya masuk blok ini
if (process.env.SERVER_FOR == 'local') { if (process.env.SERVER_FOR == 'local') {
host = process.env.DB_HOST_LOCAL; host = process.env.DB_HOST_LOCAL;
database = process.env.DB_NAME_LOCAL; database = process.env.DB_NAME_LOCAL;
@@ -25,6 +48,7 @@ if (process.env.SERVER_FOR == 'local') {
user = 'postgres'; user = 'postgres';
password = 'inhc0mmute_cms'; password = 'inhc0mmute_cms';
} }
}
module.exports = { module.exports = {
// development: { // development: {