mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-05 11:06:28 +00:00
Compare commits
88 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c8f01db5e9 | |||
| 1be5cc8d0c | |||
| 352ec2822f | |||
| 9910d4d834 | |||
| a2eb984658 | |||
| eac57a3821 | |||
| f4451aaea2 | |||
| 837d1c5d77 | |||
| 74825d277b | |||
| 8c231e9901 | |||
| f7c5cf33f6 | |||
| 870d8aea46 | |||
| b46d3a5b25 | |||
| 5408639d80 | |||
| 9b2ab48e99 | |||
| a35492c124 | |||
| e1f0c60b37 | |||
| 16afd42876 | |||
| 3722be6eeb | |||
| 493f131779 | |||
| f10ff80284 | |||
| f30ee86552 | |||
| e8de33b663 | |||
| 68ebfb0ac2 | |||
| 96c46ad49c | |||
| 10e38babcd | |||
| 8bc68493cf | |||
| 2b1b14548a | |||
| 240bb5fa17 | |||
| 7676ec54ef | |||
| de0a8847b5 | |||
| 4df41a426c | |||
| 3401e425b4 | |||
| 0d29175942 | |||
| 4f03433bb2 | |||
| 1df5f97543 | |||
| a222714bcb | |||
| 2249bbbbaf | |||
| 16fbfdcae1 | |||
| 6b5f92e597 | |||
| baf99a975d | |||
| 70b9ef78cb | |||
| 4169b40e97 | |||
| 3566f63bea | |||
| 066fd49173 | |||
| 2c0ffbd9d6 | |||
| ee46232c7a | |||
| 15131cebb1 | |||
| 6ff785de5a | |||
| 8e997346d2 | |||
| 80dda817fb | |||
| 410ef5ac53 | |||
| d9d5be8921 | |||
| 574092e015 | |||
| 5ece7912f4 | |||
| 2540b1c6c0 | |||
| 4feb7a7724 | |||
| 4994278078 | |||
| c6488f7f69 | |||
| f0bbf54afc | |||
| 7c6ab450be | |||
| 1524d643c6 | |||
| 36b61697dd | |||
| 8366d9b38b | |||
| ed7e0ce127 | |||
| 8d1e2075c3 | |||
| 5df52be111 | |||
| 6e0627fb86 | |||
| 0235cdb7c0 | |||
| a64c38b928 | |||
| 99f004adf2 | |||
| 3e5d73dd56 | |||
| 4481079289 | |||
| 9bc1260bc0 | |||
| df8ad92eba | |||
| 3b8d9d20ff | |||
| 5197966807 | |||
| 966c7b1f60 | |||
| 002f1375e4 | |||
| ada8358c07 | |||
| b587640684 | |||
| 7d56ebbe77 | |||
| 015832c683 | |||
| 79a5c5951b | |||
| c54a030519 | |||
| 775b36cfd2 | |||
| b796bfdd5c | |||
| 25f66afa7b |
@@ -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
@@ -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',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user