Compare commits

...

88 Commits

Author SHA1 Message Date
ihsan c8f01db5e9 update 2023-03-03 17:33:01 +07:00
ihsan 1be5cc8d0c update 2023-03-03 17:31:43 +07:00
ihsan 352ec2822f update 2023-03-03 17:31:02 +07:00
ihsan 9910d4d834 update 2023-03-03 17:28:29 +07:00
ihsan a2eb984658 update 2023-03-03 17:25:24 +07:00
ihsan eac57a3821 update 2023-03-03 17:21:07 +07:00
ihsan f4451aaea2 update 2023-03-03 17:11:50 +07:00
ihsan 837d1c5d77 update 2023-03-03 16:33:20 +07:00
ihsan 74825d277b update 2023-03-03 16:26:01 +07:00
ihsan 8c231e9901 update 2023-03-03 16:16:14 +07:00
ihsan f7c5cf33f6 update 2023-03-03 16:03:34 +07:00
ihsan 870d8aea46 skip check amount topup 2023-02-27 12:40:48 +07:00
ihsan b46d3a5b25 update 2023-02-24 16:53:38 +07:00
ihsan 5408639d80 update reservation amount total 2023-02-24 15:56:52 +07:00
ihsan 9b2ab48e99 update 2023-02-22 10:24:24 +07:00
ihsan a35492c124 update 2023-02-22 08:20:55 +07:00
ihsan e1f0c60b37 update 2023-02-22 01:24:46 +07:00
ihsan 16afd42876 update 2023-02-22 00:59:36 +07:00
ihsan 3722be6eeb update 2023-02-22 00:44:59 +07:00
ihsan 493f131779 update 2023-02-22 00:36:24 +07:00
ihsan f10ff80284 update 2023-02-22 00:32:01 +07:00
ihsan f30ee86552 update 2023-02-22 00:26:49 +07:00
ihsan e8de33b663 update 2023-02-22 00:13:41 +07:00
ihsan 68ebfb0ac2 update 2023-02-21 20:02:33 +07:00
ihsan 96c46ad49c update 2023-02-21 19:56:53 +07:00
ihsan 10e38babcd update 2023-02-21 19:54:06 +07:00
ihsan 8bc68493cf update 2023-02-21 19:49:42 +07:00
ihsan 2b1b14548a update 2023-02-21 19:46:28 +07:00
ihsan 240bb5fa17 update 2023-02-21 19:44:37 +07:00
ihsan 7676ec54ef update 2023-02-21 19:42:22 +07:00
ihsan de0a8847b5 update 2023-02-21 19:39:57 +07:00
ihsan 4df41a426c update 2023-02-21 19:36:51 +07:00
ihsan 3401e425b4 updaye 2023-02-21 19:33:43 +07:00
ihsan 0d29175942 update 2023-02-21 19:19:07 +07:00
ihsan 4f03433bb2 update 2023-02-21 19:17:07 +07:00
ihsan 1df5f97543 update 2023-02-21 19:08:11 +07:00
ihsan a222714bcb update 2023-02-21 19:07:02 +07:00
ihsan 2249bbbbaf update 2023-02-21 19:01:02 +07:00
ihsan 16fbfdcae1 update 2023-02-21 18:02:58 +07:00
ihsan 6b5f92e597 update 2023-02-21 14:52:28 +07:00
ihsan baf99a975d update bugs 2023-02-21 14:40:05 +07:00
ihsan 70b9ef78cb update 2023-02-20 23:54:54 +07:00
ihsan 4169b40e97 update 2023-02-20 23:52:36 +07:00
ihsan 3566f63bea update 2023-02-20 23:50:21 +07:00
ihsan 066fd49173 update 2023-02-20 23:49:00 +07:00
ihsan 2c0ffbd9d6 update 2023-02-20 23:47:30 +07:00
ihsan ee46232c7a update 2023-02-20 23:46:38 +07:00
ihsan 15131cebb1 update 2023-02-20 23:31:42 +07:00
ihsan 6ff785de5a Merge branch 'nuranggi' into feature_fraud 2023-02-20 23:26:52 +07:00
Nuranggi Hermawan 8e997346d2 UPdate 2023-02-20 23:25:33 +07:00
Nuranggi Hermawan 80dda817fb Update 2023-02-20 23:24:55 +07:00
Nuranggi Hermawan 410ef5ac53 Update 2023-02-20 23:24:07 +07:00
ihsan d9d5be8921 update 2023-02-20 23:24:01 +07:00
ihsan 574092e015 update 2023-02-20 23:18:09 +07:00
ihsan 5ece7912f4 update 2023-02-20 23:15:38 +07:00
ihsan 2540b1c6c0 update 2023-02-20 23:12:29 +07:00
ihsan 4feb7a7724 update 2023-02-20 23:10:14 +07:00
ihsan 4994278078 UPDATE 2023-02-20 23:09:31 +07:00
ihsan c6488f7f69 update 2023-02-20 23:06:20 +07:00
ihsan f0bbf54afc update 2023-02-20 22:53:16 +07:00
ihsan 7c6ab450be update 2023-02-20 22:51:09 +07:00
ihsan 1524d643c6 update 2023-02-20 22:49:18 +07:00
ihsan 36b61697dd update 2023-02-20 22:46:25 +07:00
ihsan 8366d9b38b update 2023-02-20 22:42:35 +07:00
ihsan ed7e0ce127 update 2023-02-20 22:39:46 +07:00
ihsan 8d1e2075c3 update 2023-02-20 22:38:24 +07:00
ihsan 5df52be111 update 2023-02-20 22:37:15 +07:00
ihsan 6e0627fb86 update 2023-02-20 22:34:40 +07:00
ihsan 0235cdb7c0 update 2023-02-20 22:31:14 +07:00
ihsan a64c38b928 update 2023-02-20 22:27:40 +07:00
ihsan 99f004adf2 update 2023-02-20 22:22:55 +07:00
Nuranggi Hermawan 3e5d73dd56 Merge branch 'feature_fraud' of https://github.com/mohamadihsan/topuponline into nuranggi 2023-02-20 22:18:19 +07:00
Nuranggi Hermawan 4481079289 Update 2023-02-20 22:18:02 +07:00
ihsan 9bc1260bc0 update 2023-02-20 22:13:50 +07:00
ihsan df8ad92eba update 2023-02-20 22:10:55 +07:00
ihsan 3b8d9d20ff update merge 2023-02-20 22:08:03 +07:00
Nuranggi Hermawan 5197966807 Udpate 2023-02-20 22:06:22 +07:00
ihsan 966c7b1f60 update 2023-02-20 21:49:33 +07:00
ihsan 002f1375e4 merge 2023-02-20 21:39:20 +07:00
ihsan ada8358c07 merge 2023-02-20 21:37:17 +07:00
Nuranggi Hermawan b587640684 Update 2023-02-20 21:35:43 +07:00
Nuranggi Hermawan 7d56ebbe77 Update 2023-02-20 21:32:12 +07:00
Nuranggi Hermawan 015832c683 Update 2023-02-20 21:23:47 +07:00
Nuranggi Hermawan 79a5c5951b Update 2023-02-20 21:19:59 +07:00
ihsan c54a030519 update fraud 2023-02-20 21:16:12 +07:00
Nuranggi Hermawan 775b36cfd2 Update 2023-02-20 21:03:02 +07:00
ihsan b796bfdd5c update 2023-02-20 17:15:09 +07:00
ihsan 25f66afa7b change update status to in progress to last statement 2023-02-14 06:26:04 +07:00
4 changed files with 1433 additions and 741 deletions
@@ -86,38 +86,38 @@ const loadingBalanceRequest = async (req, res) => {
`${uniqueCode} checking production card number or not...`
);
if (process.env.SERVER_FOR == 'production') {
if (card_number.substring(0, 1) != '1') {
result = {
code: '400',
message: "It's not production card number.",
data: {},
};
// if (process.env.SERVER_FOR == 'production') {
// if (card_number.substring(0, 1) != '1') {
// result = {
// code: '400',
// message: "It's not production card number.",
// data: {},
// };
// log warn
winston.logger.warn(
`${uniqueCode} RESPONSE check reservation: ${JSON.stringify(result)}`
);
// // log warn
// winston.logger.warn(
// `${uniqueCode} RESPONSE check reservation: ${JSON.stringify(result)}`
// );
return res.status(200).json(result);
}
} else {
if (card_number.substring(0, 1) == '1') {
result = {
code: '400',
message:
"It's production card number. Please use the development card number.",
data: {},
};
// return res.status(200).json(result);
// }
// } else {
// 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 check reservation: ${JSON.stringify(result)}`
);
// // log warn
// winston.logger.warn(
// `${uniqueCode} RESPONSE check reservation: ${JSON.stringify(result)}`
// );
return res.status(200).json(result);
}
}
// return res.status(200).json(result);
// }
// }
// time
let now = moment().format('YYYY-MM-DD HH:mm:ss');
@@ -192,13 +192,69 @@ const loadingBalanceRequest = async (req, res) => {
winston.logger.debug(`${uniqueCode} checking reservation pending...`);
// get total reservation pending
let getReservationPending = await model.getReservationPending(
let getReservationPending = await model.getReservationPendingV2(
card_number,
now,
flag
);
// cek disini apakah sebelumnya topup
const cardHistory = await model.checkCardHistory(card_number);
if (cardHistory.length > 0) {
if (cardHistory.i_log_name == 21 && cardHistory.c_source == 'CMS') {
if (getReservationPending.length > 0) {
// insert semua reserve balance ke fraud
const dataFraud = [];
const rsv = [];
for (const item of getReservationPending) {
rsv.push(item.c_reservation_no);
dataFraud.push({
c_card_number: item.c_card_number,
c_reservation_no: item.c_reservation_no,
i_reservation_amount: item.i_reservation_amount,
c_reservation_status: item.c_status,
c_reservation_flag: item.c_flag,
c_reservation_ref_no: item.c_ref_no,
});
}
winston.logger.debug(
`${uniqueCode} INSERT TO trx.t_d_froud ${JSON.stringify(dataFraud)}`
);
const fraud = await model.insertFraud(dataFraud);
// log debug
winston.logger.debug(
`${uniqueCode} RESERVE NUMBER FROM trx.t_d_froud ${JSON.stringify(
fraud
)}`
);
winston.logger.debug(
`${uniqueCode} reserve number ${JSON.stringify(rsv)}`
);
// update reserve balance
await model.updateFraudToReserve(rsv);
} else {
result = {
code: '414',
message: "reservation doesn't exist",
data: {},
};
// log warn
winston.logger.warn(
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
result
)}`
);
return res.status(200).json(result);
}
}
}
// get total reservation pending with compare flag counter on card and the reservation transaction
// where status != -1
let getReservationPendingWithFlagCounter =
await model.getReservationPendingWithFlagCounter(card_number, now, flag);
@@ -211,67 +267,79 @@ const loadingBalanceRequest = async (req, res) => {
// await model.getReservationPendingWithFlag(card_number, now);
if (getReservationPendingWithFlagCounter.length > 0) {
if (lastFlag && parseInt(lastFlag) <= parseInt(flag)) {
let reservationNumberPendingSuccessLoaded = [];
let loadBalanceNumberPendingSuccessLoaded = [];
if (lastFlag) {
if (parseInt(lastFlag) <= parseInt(flag)) {
let reservationNumberPendingSuccessLoaded = [];
let loadBalanceNumberPendingSuccessLoaded = [];
let totalReservationAmount = 0;
getReservationPendingWithFlagCounter.forEach((element) => {
reservationNumberPendingSuccessLoaded.push(element.c_reservation_no);
loadBalanceNumberPendingSuccessLoaded.push(element.c_load_balance_no);
});
getReservationPendingWithFlagCounter.forEach((element) => {
reservationNumberPendingSuccessLoaded.push(
element.c_reservation_no
);
if (element.c_load_balance_no) {
loadBalanceNumberPendingSuccessLoaded.push(
element.c_load_balance_no
);
}
totalReservationAmount += parseInt(element.i_reservation_amount);
});
// log debug
winston.logger.debug(
`${uniqueCode} updating reservation and load balance transaction...`
);
// update
let insertUpdate = await updateReservationAndLoadingBalance(
reservationNumberPendingSuccessLoaded,
loadBalanceNumberPendingSuccessLoaded,
mid,
tid,
card_number,
balance,
flag,
uniqueCode
);
if (insertUpdate) {
// log debug
winston.logger.debug(`${uniqueCode} updating flag to server...`);
// update flag from Server
await model.updateFlag(
now,
card_number,
uid.toUpperCase(),
balance,
flag
winston.logger.debug(
`${uniqueCode} updating reservation and load balance transaction...`
);
result = {
code: '01',
message: 'your card number has been cleared successfully',
data: {},
};
} else {
result = {
code: '423',
message: 'updated failed',
data: {},
};
}
// update
let insertUpdate = await updateReservationAndLoadingBalance(
reservationNumberPendingSuccessLoaded,
loadBalanceNumberPendingSuccessLoaded,
mid,
tid,
card_number,
balance,
flag,
uniqueCode,
totalReservationAmount,
uid
);
// log warn
winston.logger.warn(
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
result
)}`
);
if (insertUpdate) {
// log debug
winston.logger.debug(`${uniqueCode} updating flag to server...`);
if (getReservationPending.length < 1) {
return res.status(200).json(result);
// update flag from Server
await model.updateFlag(
now,
card_number,
uid.toUpperCase(),
balance,
flag
);
result = {
code: '01',
message: 'your card number has been cleared successfully',
data: {},
};
} else {
result = {
code: '423',
message: 'updated failed',
data: {},
};
}
// log warn
winston.logger.warn(
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
result
)}`
);
if (getReservationPending.length < 1) {
return res.status(200).json(result);
}
}
}
}
@@ -286,7 +354,7 @@ const loadingBalanceRequest = async (req, res) => {
winston.logger.debug(`${uniqueCode} checking reservation pending...`);
// reget total reservation pending
getReservationPending = await model.getReservationPending(
getReservationPending = await model.getReservationPendingV2(
card_number,
now,
flag
@@ -321,14 +389,6 @@ const loadingBalanceRequest = async (req, res) => {
i++;
});
// log debug
winston.logger.debug(
`${uniqueCode} updating status reservation to in progress...`
);
// update status to in progress
await model.updateStatusReservation(reservationNumberTemp, now);
totalReservation = i;
if (totalReservation == 0) {
result = {
@@ -347,6 +407,11 @@ const loadingBalanceRequest = async (req, res) => {
return res.status(200).json(result);
}
// log debug
winston.logger.debug(
`${uniqueCode} checking the card number in list fraud transaction or not...`
);
// log debug
winston.logger.debug(`${uniqueCode} checking total topup amount...`);
@@ -442,21 +507,57 @@ const loadingBalanceRequest = async (req, res) => {
}
}
result = {
code: '00',
message: 'reservation exists',
data: {
amount: amountTopup,
total_reservation: totalReservation,
reservation_number: reservationNumber,
},
};
// log info
winston.logger.info(
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(result)}`
// log debug
winston.logger.debug(
`${uniqueCode} updating status reservation to in progress...${reservationNumberTemp}, ${now}, ${flag}`
);
// update status to in progress
let updateStatusReservation = await model.updateStatusReservation(
reservationNumberTemp,
now,
flag
);
// log debug
winston.logger.debug(`${uniqueCode} XXXXX ${updateStatusReservation}`);
if (updateStatusReservation) {
result = {
code: '00',
message: 'reservation exists',
data: {
amount: amountTopup,
total_reservation: totalReservation,
reservation_number: reservationNumber,
},
};
// log info
winston.logger.info(
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
result
)}`
);
} else {
result = {
code: '434',
message: '[434] Failed, please try again later',
data: {
amount: amountTopup,
total_reservation: totalReservation,
reservation_number: reservationNumber,
},
};
// log info
winston.logger.info(
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
result
)}`
);
}
return res.json(result);
} catch (error) {
// create log
@@ -523,38 +624,38 @@ const loadingBalance = async (req, res) => {
`${uniqueCode} checking production card number or not...`
);
if (process.env.SERVER_FOR == 'production') {
if (card_number.substring(0, 1) != '1') {
result = {
code: '400',
message: "It's not production card number.",
data: {},
};
// if (process.env.SERVER_FOR == 'production') {
// if (card_number.substring(0, 1) != '1') {
// result = {
// code: '400',
// message: "It's not production card number.",
// data: {},
// };
// log warn
winston.logger.warn(
`${uniqueCode} RESPONSE check reservation: ${JSON.stringify(result)}`
);
// // log warn
// winston.logger.warn(
// `${uniqueCode} RESPONSE check reservation: ${JSON.stringify(result)}`
// );
return res.status(200).json(result);
}
} else {
if (card_number.substring(0, 1) == '1') {
result = {
code: '400',
message:
"It's production card number. Please use the development card number.",
data: {},
};
// return res.status(200).json(result);
// }
// } else {
// 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 check reservation: ${JSON.stringify(result)}`
);
// // log warn
// winston.logger.warn(
// `${uniqueCode} RESPONSE check reservation: ${JSON.stringify(result)}`
// );
return res.status(200).json(result);
}
}
// return res.status(200).json(result);
// }
// }
// time
let now = moment().format('YYYY-MM-DD HH:mm:ss');
@@ -667,7 +768,7 @@ const loadingBalance = async (req, res) => {
amountTopup += parseInt(rsv.i_reservation_amount);
});
if (amount != amountTopup) {
if (parseInt(amount) != parseInt(amountTopup)) {
result = {
code: '418',
message: 'topup amount is different',
@@ -951,8 +1052,8 @@ const loadingBalanceInsert = async (param) => {
let now = moment().format('YYYY-MM-DD HH:mm:ss');
let today = moment().format('YYYY-MM-DD');
// log debug
winston.logger.debug(`${uniqueCode} checking partner...`);
// log warn
winston.logger.warn(`${uniqueCode} checking partner...`);
// get partner, merchant, terminal from tid
let getPartner = await model.getPartner(mid, tid);
@@ -971,8 +1072,8 @@ const loadingBalanceInsert = async (param) => {
return result;
}
// log debug
winston.logger.debug(`${uniqueCode} checking reservation status...`);
// log warn
winston.logger.warn(`${uniqueCode} checking reservation status...`);
// check reservation status
for (let index = 0; index < reservation_number.length; index++) {
@@ -980,6 +1081,7 @@ const loadingBalanceInsert = async (param) => {
reservation_number[index]
);
// if reservation doesn't exist or has been canceled
if (!reservationStatus) {
result = {
code: '414',
@@ -997,24 +1099,67 @@ const loadingBalanceInsert = async (param) => {
return result;
}
// if there are reservation with status active
if (reservationStatus.c_status == 'A') {
var reservationLoaded = await model.findReservationLoaded(
// if there are reservation on load balance table transaction but before process on reservation failed update to LOADED
let reservationLoaded = await model.findReservationLoaded(
reservationStatus.i_reservation_balance
);
let loadBalanceNumberExisting = reservationLoaded.c_load_balance_no;
let loadDate = reservationLoaded.d_load_balance;
if (reservationLoaded) {
let loadBalanceNumberExisting = reservationLoaded.c_load_balance_no;
let loadDate = reservationLoaded.d_load_balance;
result = {
code: '00',
message:
'reservation has been successfully loaded on ' +
moment(loadDate).format('DD MMM YYYY HH:mm:ss'),
data: {
load_balance_number: loadBalanceNumberExisting,
},
};
// log info
winston.logger.info(
`${uniqueCode} RESPONSE load balance insert: ${JSON.stringify(
result
)}`
);
return result;
}
}
}
// log warn
winston.logger.warn(`${uniqueCode} checking last log history...`);
// get last history by card number
let lastHistory = await model.getLastHistory(card_number);
if (lastHistory) {
// if last history card is topup 21 = log name id for topup and source is CMS, that mean topup with online source)
if (lastHistory.i_log_name == 21 && lastHistory.c_source == 'CMS') {
// log warn
winston.logger.warn(`${uniqueCode} inserting fraud transaction...`);
// insert reservation transaction to fraud table
await model.insertFraudTransaction(reservation_number);
// log warn
winston.logger.warn(`${uniqueCode} suspending reservation...`);
// update reservation with suspend status
await model.suspendReservation(reservation_number, now);
result = {
code: '00',
message:
'reservation has been successfully loaded on ' +
moment(loadDate).format('DD MMM YYYY HH:mm:ss'),
data: {
load_balance_number: loadBalanceNumberExisting,
},
code: '432',
message: 'your card number has fraud transaction',
data: {},
};
// log info
winston.logger.info(
// log warn
winston.logger.warn(
`${uniqueCode} RESPONSE load balance insert: ${JSON.stringify(
result
)}`
@@ -1024,14 +1169,27 @@ const loadingBalanceInsert = async (param) => {
}
}
// log debug
winston.logger.debug(`${uniqueCode} checking reservation pending...`);
// log warn
winston.logger.warn(`${uniqueCode} checking fraud transaction...`);
// get total reservation pending
let getReservationPending = await model.getReservationPending(
// get data fraud by card number and status fraud is not closed
let fraudTransaction = await model.getFraudTransaction(card_number);
let fraudReservationNumber = [];
if (fraudTransaction.length > 0) {
fraudTransaction.forEach((rsv) => {
fraudReservationNumber.push(rsv.c_reservation_no);
});
}
// log warn
winston.logger.warn(`${uniqueCode} checking reservation pending...`);
// get total reservation pending without fraud
let getReservationPending = await model.getReservationPendingWithoutFraud(
card_number,
now,
flag
flag,
fraudReservationNumber
);
if (getReservationPending.length < 1) {
@@ -1049,8 +1207,8 @@ const loadingBalanceInsert = async (param) => {
return result;
}
// log debug
winston.logger.debug(`${uniqueCode} checking total topup amount...`);
// log warn
winston.logger.warn(`${uniqueCode} checking total topup amount...`);
// check total topup and request topup
let amountTopup = 0;
@@ -1058,7 +1216,7 @@ const loadingBalanceInsert = async (param) => {
amountTopup += parseInt(rsv.i_reservation_amount);
});
if (amount != amountTopup) {
if (parseInt(amount) != parseInt(amountTopup)) {
result = {
code: '418',
message: 'topup amount is different',
@@ -1091,8 +1249,8 @@ const loadingBalanceInsert = async (param) => {
? parseInt(getLoadBalanceSequence.i_load_balance_no_seq) + 1
: 1;
// log debug
winston.logger.debug(`${uniqueCode} generating load balance number...`);
// log warn
winston.logger.warn(`${uniqueCode} generating load balance number...`);
loadBalanceNumber = await generateLoadBalanceNumber(
getPartner,
@@ -1100,6 +1258,11 @@ const loadingBalanceInsert = async (param) => {
loadBalanceNoSequence
);
// log warn
winston.logger.warn(
`${uniqueCode} load balance number is ${loadBalanceNumber}.`
);
if (maxLoop > 20) {
// create log
winston.logger.error(
@@ -1161,8 +1324,13 @@ const loadingBalanceInsert = async (param) => {
winston.logger.debug(`${uniqueCode} getting reservation detail...`);
let detail = [];
for (let index = 0; index < reservation_number.length; index++) {
let reservation = await model.findReservation(reservation_number[index]);
reservation_number = [];
for (let index = 0; index < getReservationPending.length; index++) {
reservation_number.push(getReservationPending[index].c_reservation_no);
let reservation = await model.findReservation(
getReservationPending[index].c_reservation_no
);
if (!reservation) {
result = {
@@ -1223,11 +1391,11 @@ const loadingBalanceInsert = async (param) => {
`${uniqueCode} checking load balance transaction has been exists or not...`
);
// log debug
winston.logger.debug(`${uniqueCode} inserting load balance transaction...`);
// log warn
winston.logger.warn(`${uniqueCode} inserting load balance transaction...`);
// insert transaction
await model.insertLoadingBalance(
let insertLoadingBalance = await model.insertLoadingBalance(
data,
detail,
reservation_number,
@@ -1239,21 +1407,51 @@ const loadingBalanceInsert = async (param) => {
flag
);
result = {
code: '00',
message: write_status
? 'transaction saved successfully. Err: failed write to the card'
: 'balance loaded successfully',
data: {
load_balance_number: loadBalanceNumber,
},
};
// log info
winston.logger.info(
`${uniqueCode} RESPONSE load balance insert: ${JSON.stringify(result)}`
// log warn
winston.logger.warn(
`${uniqueCode} AAAAAAAAAAAAAAAAAA [DATA] : ${JSON.stringify(
data
)} [DETAIL] : ${JSON.stringify(detail)} [RSV] : ${JSON.stringify(
reservation_number
)} [NOW] : ${JSON.stringify(now)} [WRITE STATUS] : ${JSON.stringify(
write_status
)} [CARD NUMBER] : ${JSON.stringify(
card_number
)} [UID] : ${JSON.stringify(uid)} [BALANCE] : ${JSON.stringify(
balance
)} [FLAG] : ${JSON.stringify(flag)}`
);
if (insertLoadingBalance > 0) {
result = {
code: '00',
message: write_status
? 'transaction saved successfully. Err: failed write to the card'
: 'balance loaded successfully',
data: {
load_balance_number: loadBalanceNumber,
},
};
// log info
winston.logger.info(
`${uniqueCode} RESPONSE load balance insert: ${JSON.stringify(result)}`
);
} else {
result = {
code: '433',
message: '[433] Failed, please try again later',
data: {
load_balance_number: loadBalanceNumber,
},
};
// log warn
winston.logger.warn(
`${uniqueCode} RESPONSE load balance insert: ${JSON.stringify(result)}`
);
}
return result;
} catch (error) {
// create log
@@ -1782,7 +1980,9 @@ const updateReservationAndLoadingBalance = async (
cardNumber,
balance,
flag,
uniqueCode
uniqueCode,
totalReservationAmount,
uid
) => {
try {
// log debug
@@ -1795,17 +1995,18 @@ const updateReservationAndLoadingBalance = async (
// get load balance
let dataLoadingBalance = null;
let getLastLoadingBalanceFlag = await model.getLastLoadingBalanceFlag(
loadBalanceNumber
);
if (getLastLoadingBalanceFlag) {
dataLoadingBalance = getLastLoadingBalanceFlag;
} else {
// insert new load balance transaction by data on card and update data reservation
let dataLoadingBalanceDetail = [];
if (loadBalanceNumber.length > 0) {
let getLastLoadingBalanceFlag = await model.getLastLoadingBalanceFlag(
loadBalanceNumber
);
if (getLastLoadingBalanceFlag) {
dataLoadingBalance = getLastLoadingBalanceFlag;
}
}
// get detail load balance
let dataLoadingBalanceDetail = [];
if (dataLoadingBalance) {
// log debug
winston.logger.debug(
@@ -1821,12 +2022,12 @@ const updateReservationAndLoadingBalance = async (
}
}
if (dataLoadingBalance && dataLoadingBalanceDetail.length > 0) {
// time
let now = moment().format('YYYY-MM-DD HH:mm:ss');
let today = moment().format('YYYY-MM-DD');
let getPartner = await model.getPartner(mid, tid);
// time
let now = moment().format('YYYY-MM-DD HH:mm:ss');
let today = moment().format('YYYY-MM-DD');
let getPartner = await model.getPartner(mid, tid);
if (dataLoadingBalance && dataLoadingBalanceDetail.length > 0) {
let data = {
c_load_balance_no: dataLoadingBalance.c_load_balance_no,
d_load_balance: dataLoadingBalance.d_load_balance,
@@ -1906,7 +2107,175 @@ const updateReservationAndLoadingBalance = async (
return true;
} else {
return false;
// insert new load balance transaction by data on card and update data reservation
// log debug
winston.logger.debug(
`${uniqueCode} generating and insert new data load balance...`
);
// generate load balance number
let newLoadBalanceNumber;
let getLoadBalanceSequence;
let loadBalanceNoSequence;
let maxLoop = 0;
do {
// log debug
winston.logger.debug(
`${uniqueCode} getting loading balance sequence...`
);
// get loading balance
getLoadBalanceSequence = await model.getLoadBalanceSequence(
getPartner,
today
);
loadBalanceNoSequence = getLoadBalanceSequence
? parseInt(getLoadBalanceSequence.i_load_balance_no_seq) + 1
: 1;
// log warn
winston.logger.warn(`${uniqueCode} generating load balance number...`);
newLoadBalanceNumber = await generateLoadBalanceNumber(
getPartner,
moment(today).format('YYMMDD'),
loadBalanceNoSequence
);
// log warn
winston.logger.warn(
`${uniqueCode} load balance number is ${newLoadBalanceNumber}.`
);
if (maxLoop > 20) {
// create log
winston.logger.error(
`500 internal server error (max loop) - backend server | ${error.message}`
);
return false;
}
maxLoop++;
} while (newLoadBalanceNumber == 'XX');
let dataLoadBalance = {
c_load_balance_no: newLoadBalanceNumber,
d_load_balance: now,
c_ref_no: null,
i_partner: getPartner.i_partner,
c_partner_code: getPartner.partner_code,
c_partner_name: getPartner.partner_name,
i_merchant: getPartner.i_merchant,
c_merchant_code: getPartner.merchant_code,
c_merchant_name: getPartner.merchant_name,
c_mid: getPartner.mid,
i_terminal: getPartner.i_terminal,
c_terminal_code: getPartner.terminal_code,
c_terminal_name: getPartner.terminal_name,
c_tid: getPartner.tid,
c_card_number: cardNumber,
i_topup_amount: totalReservationAmount,
m_balance: balance,
c_return_sap: null,
i_load_balance_no_seq: loadBalanceNoSequence,
c_idm: uid,
c_status: 'A',
c_status_name: 'SUCCESS',
d_create: now,
i_create: null,
c_create_username: null,
c_create_fullname: null,
d_modify: null,
i_modify: null,
c_modify_username: null,
c_modify_fullname: null,
d_delete: null,
i_delete: null,
c_delete_username: null,
c_delete_fullname: null,
};
// create detaial load balance
let detailLoadBalance =
await model.createDetailLoadBalanceFromReservation(reservationNumber);
// log debug
winston.logger.debug(
`${uniqueCode} detail load balance with reservation no : ${JSON.stringify(
reservationNumber
)}`
);
if (detailLoadBalance.length > 0) {
// log warn
winston.logger.warn(
`${uniqueCode} AAAAAAAAAAAAAAAAAA1111 [DATA] : ${JSON.stringify(
reservationNumber
)} [LB] : ${JSON.stringify(dataLoadBalance)} [LBD] : ${JSON.stringify(
detailLoadBalance
)} [NOW] : ${JSON.stringify(now)} [FLAG] : ${JSON.stringify(flag)}`
);
// log debug
winston.logger.debug(
`${uniqueCode} updating reservation and insert new load balance transaction...`
);
// update reservation and load balance transaction
let updateReservationAndInsertLoadingBalance =
await model.updateReservationAndInsertLoadingBalance(
reservationNumber,
dataLoadBalance,
detailLoadBalance,
now,
flag
);
// log debug
winston.logger.debug(
`${uniqueCode} status insert new load balance and update reservation : ${JSON.stringify(
updateReservationAndInsertLoadingBalance
)}`
);
// if (updateReservationAndInsertLoadingBalance > 0) {
// // log debug
// winston.logger.debug(
// `${uniqueCode} inserting log for card history...`
// );
// // log card history
// await model.createLoadBalanceLog({
// i_log_name:21,
// d_log: dataLoadingBalance.d_load_balance,
// c_card_number: cardNumber,
// c_source: 'CMS',
// c_location: getPartner ? getPartner.partner_name : null,
// m_balance_before: parseInt(dataLoadingBalance.m_balance),
// m_amount: parseInt(dataLoadingBalance.i_topup_amount),
// m_balance_after: parseInt(balance),
// j_new_data: { data: data, detail: dataLoadingBalanceDetail },
// j_old_data: null,
// c_note: `LOAD BALANCE ${dataLoadingBalance.i_topup_amount} FROM ${
// getPartner ? getPartner.partner_name : null
// } SUCCESSFULLY`,
// c_status: 'S',
// d_created: now,
// i_create: null,
// c_create_username: 'HSM',
// c_create_fullname: 'HARDWARE SECURE MODULE',
// c_category: 'T',
// });
// } else {
// return false;
// }
} else {
return false;
}
return true;
}
} catch (error) {
// create log
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+65 -65
View File
@@ -1,4 +1,4 @@
require("dotenv").config();
require('dotenv').config();
let host;
let database;
@@ -6,77 +6,77 @@ let port;
let user;
let password;
if (process.env.SERVER_FOR == "local") {
host = "localhost";
database = "postgres";
if (process.env.SERVER_FOR == 'local') {
host = 'localhost';
database = 'postgres';
port = 5432;
user = "postgres";
password = "postgres";
} else if (process.env.SERVER_FOR == "development") {
host = "10.20.14.14";
database = "postgres";
user = 'postgres';
password = 'postgres';
} else if (process.env.SERVER_FOR == 'development') {
host = '10.20.14.14';
database = 'postgres';
port = 5432;
user = "cms";
password = "Cm5kc1#2021";
} else if (process.env.SERVER_FOR == "production") {
host = "10.1.201.75";
database = "postgres";
user = 'postgres';
password = 'inhc0mmute_cms';
} else if (process.env.SERVER_FOR == 'production') {
host = '10.1.201.75';
database = 'postgres';
port = 5432;
user = "postgres";
password = "inhc0mmute_cms";
user = 'postgres';
password = 'inhc0mmute_cms';
}
module.exports = {
// development: {
// client: "pg",
// connection: process.env.DB_URL,
// migrations: {
// directory: "./infrastructure/database/migrations",
// },
// seeds: { directory: "./infrastructure/database/seeds" },
// },
development: {
client: "pg",
connection: {
host: host,
database: database,
user: user,
password: password,
},
// connection: process.env.DB_URL,
pool: {
min: 2,
max: 10,
},
migrations: {
directory: "./infrastructure/database/migrations",
},
module.exports = {
// development: {
// client: "pg",
// connection: process.env.DB_URL,
// migrations: {
// directory: "./infrastructure/database/migrations",
// },
// seeds: { directory: "./infrastructure/database/seeds" },
// },
development: {
client: 'pg',
connection: {
host: host,
database: database,
user: user,
password: password,
},
// connection: process.env.DB_URL,
pool: {
min: 2,
max: 10,
},
migrations: {
directory: './infrastructure/database/migrations',
},
},
testing: {
client: "pg",
connection: process.env.DB_URL,
migrations: {
directory: "./infrastructure/database/migrations",
},
seeds: { directory: "./infrastructure/database/seeds" },
testing: {
client: 'pg',
connection: process.env.DB_URL,
migrations: {
directory: './infrastructure/database/migrations',
},
seeds: { directory: './infrastructure/database/seeds' },
},
production: {
client: "pg",
connection: {
host: host,
database: database,
user: user,
password: password,
},
// connection: process.env.DB_URL,
pool: {
min: 2,
max: 10,
},
migrations: {
directory: "./infrastructure/database/migrations",
},
production: {
client: 'pg',
connection: {
host: host,
database: database,
user: user,
password: password,
},
};
// connection: process.env.DB_URL,
pool: {
min: 2,
max: 10,
},
migrations: {
directory: './infrastructure/database/migrations',
},
},
};