mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-06 21:56:27 +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...`
|
`${uniqueCode} checking production card number or not...`
|
||||||
);
|
);
|
||||||
|
|
||||||
if (process.env.SERVER_FOR == 'production') {
|
// if (process.env.SERVER_FOR == 'production') {
|
||||||
if (card_number.substring(0, 1) != '1') {
|
// if (card_number.substring(0, 1) != '1') {
|
||||||
result = {
|
// result = {
|
||||||
code: '400',
|
// code: '400',
|
||||||
message: "It's not production card number.",
|
// message: "It's not production card number.",
|
||||||
data: {},
|
// data: {},
|
||||||
};
|
// };
|
||||||
|
|
||||||
// log warn
|
// // log warn
|
||||||
winston.logger.warn(
|
// winston.logger.warn(
|
||||||
`${uniqueCode} RESPONSE check reservation: ${JSON.stringify(result)}`
|
// `${uniqueCode} RESPONSE check reservation: ${JSON.stringify(result)}`
|
||||||
);
|
// );
|
||||||
|
|
||||||
return res.status(200).json(result);
|
// return res.status(200).json(result);
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
if (card_number.substring(0, 1) == '1') {
|
// if (card_number.substring(0, 1) == '1') {
|
||||||
result = {
|
// result = {
|
||||||
code: '400',
|
// code: '400',
|
||||||
message:
|
// message:
|
||||||
"It's production card number. Please use the development card number.",
|
// "It's production card number. Please use the development card number.",
|
||||||
data: {},
|
// data: {},
|
||||||
};
|
// };
|
||||||
|
|
||||||
// log warn
|
// // log warn
|
||||||
winston.logger.warn(
|
// winston.logger.warn(
|
||||||
`${uniqueCode} RESPONSE check reservation: ${JSON.stringify(result)}`
|
// `${uniqueCode} RESPONSE check reservation: ${JSON.stringify(result)}`
|
||||||
);
|
// );
|
||||||
|
|
||||||
return res.status(200).json(result);
|
// return res.status(200).json(result);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// time
|
// time
|
||||||
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
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...`);
|
winston.logger.debug(`${uniqueCode} checking reservation pending...`);
|
||||||
|
|
||||||
// get total reservation pending
|
// get total reservation pending
|
||||||
let getReservationPending = await model.getReservationPending(
|
let getReservationPending = await model.getReservationPendingV2(
|
||||||
card_number,
|
card_number,
|
||||||
now,
|
now,
|
||||||
flag
|
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
|
// get total reservation pending with compare flag counter on card and the reservation transaction
|
||||||
|
// where status != -1
|
||||||
let getReservationPendingWithFlagCounter =
|
let getReservationPendingWithFlagCounter =
|
||||||
await model.getReservationPendingWithFlagCounter(card_number, now, flag);
|
await model.getReservationPendingWithFlagCounter(card_number, now, flag);
|
||||||
|
|
||||||
@@ -211,13 +267,22 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
// await model.getReservationPendingWithFlag(card_number, now);
|
// await model.getReservationPendingWithFlag(card_number, now);
|
||||||
|
|
||||||
if (getReservationPendingWithFlagCounter.length > 0) {
|
if (getReservationPendingWithFlagCounter.length > 0) {
|
||||||
if (lastFlag && parseInt(lastFlag) <= parseInt(flag)) {
|
if (lastFlag) {
|
||||||
|
if (parseInt(lastFlag) <= parseInt(flag)) {
|
||||||
let reservationNumberPendingSuccessLoaded = [];
|
let reservationNumberPendingSuccessLoaded = [];
|
||||||
let loadBalanceNumberPendingSuccessLoaded = [];
|
let loadBalanceNumberPendingSuccessLoaded = [];
|
||||||
|
let totalReservationAmount = 0;
|
||||||
|
|
||||||
getReservationPendingWithFlagCounter.forEach((element) => {
|
getReservationPendingWithFlagCounter.forEach((element) => {
|
||||||
reservationNumberPendingSuccessLoaded.push(element.c_reservation_no);
|
reservationNumberPendingSuccessLoaded.push(
|
||||||
loadBalanceNumberPendingSuccessLoaded.push(element.c_load_balance_no);
|
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
|
// log debug
|
||||||
@@ -234,7 +299,9 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
card_number,
|
card_number,
|
||||||
balance,
|
balance,
|
||||||
flag,
|
flag,
|
||||||
uniqueCode
|
uniqueCode,
|
||||||
|
totalReservationAmount,
|
||||||
|
uid
|
||||||
);
|
);
|
||||||
|
|
||||||
if (insertUpdate) {
|
if (insertUpdate) {
|
||||||
@@ -275,6 +342,7 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
// winston.logger.debug(`${uniqueCode} updating flag to server...`);
|
// winston.logger.debug(`${uniqueCode} updating flag to server...`);
|
||||||
@@ -286,7 +354,7 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
winston.logger.debug(`${uniqueCode} checking reservation pending...`);
|
winston.logger.debug(`${uniqueCode} checking reservation pending...`);
|
||||||
|
|
||||||
// reget total reservation pending
|
// reget total reservation pending
|
||||||
getReservationPending = await model.getReservationPending(
|
getReservationPending = await model.getReservationPendingV2(
|
||||||
card_number,
|
card_number,
|
||||||
now,
|
now,
|
||||||
flag
|
flag
|
||||||
@@ -309,7 +377,6 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
return res.status(200).json(result);
|
return res.status(200).json(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
let partialTopup = false;
|
|
||||||
let totalReservation = 0;
|
let totalReservation = 0;
|
||||||
let amountTopup = 0;
|
let amountTopup = 0;
|
||||||
let reservationNumber = [];
|
let reservationNumber = [];
|
||||||
@@ -340,6 +407,11 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
return res.status(200).json(result);
|
return res.status(200).json(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// log debug
|
||||||
|
winston.logger.debug(
|
||||||
|
`${uniqueCode} checking the card number in list fraud transaction or not...`
|
||||||
|
);
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(`${uniqueCode} checking total topup amount...`);
|
winston.logger.debug(`${uniqueCode} checking total topup amount...`);
|
||||||
|
|
||||||
@@ -367,12 +439,6 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
// get BI regulation status
|
// get BI regulation status
|
||||||
const getBIRegulationStatus = await model.getBIRegulationStatus();
|
const getBIRegulationStatus = await model.getBIRegulationStatus();
|
||||||
if (getBIRegulationStatus.c_value == 'A') {
|
if (getBIRegulationStatus.c_value == 'A') {
|
||||||
// log debug
|
|
||||||
winston.logger.debug(`${uniqueCode} checking topup partial status...`);
|
|
||||||
|
|
||||||
// check topup partial status
|
|
||||||
const getTopupPartialStatus = await model.getTopupPartialStatus();
|
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(`${uniqueCode} checking max balance on the card...`);
|
winston.logger.debug(`${uniqueCode} checking max balance on the card...`);
|
||||||
|
|
||||||
@@ -383,58 +449,6 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
parseInt(balance) + parseInt(amountTopup) >
|
parseInt(balance) + parseInt(amountTopup) >
|
||||||
parseInt(getMaxAmountOnTheCard.c_value)
|
parseInt(getMaxAmountOnTheCard.c_value)
|
||||||
) {
|
) {
|
||||||
// if topup partial is active
|
|
||||||
if (getTopupPartialStatus.c_value == 'A') {
|
|
||||||
// reset reservation data
|
|
||||||
partialTopup = true;
|
|
||||||
totalReservation = 0;
|
|
||||||
amountTopup = 0;
|
|
||||||
reservationNumber = [];
|
|
||||||
reservationNumberTemp = [];
|
|
||||||
i = 0;
|
|
||||||
|
|
||||||
// sum amount can be topup
|
|
||||||
getReservationPending.forEach((rsv) => {
|
|
||||||
if (
|
|
||||||
parseInt(balance) + parseInt(amountTopup) <=
|
|
||||||
parseInt(getMaxAmountOnTheCard.c_value)
|
|
||||||
) {
|
|
||||||
amountTopup += parseInt(rsv.i_reservation_amount);
|
|
||||||
if (
|
|
||||||
amountTopup > parseInt(getMaxAmountOnTheCard.c_value) ||
|
|
||||||
parseInt(balance) + amountTopup >
|
|
||||||
parseInt(getMaxAmountOnTheCard.c_value)
|
|
||||||
) {
|
|
||||||
amountTopup =
|
|
||||||
amountTopup - parseInt(rsv.i_reservation_amount);
|
|
||||||
i--;
|
|
||||||
} else {
|
|
||||||
reservationNumber.push(rsv.c_reservation_no);
|
|
||||||
reservationNumberTemp.push(rsv.c_reservation_no);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
});
|
|
||||||
|
|
||||||
totalReservation = i;
|
|
||||||
if (totalReservation == 0) {
|
|
||||||
result = {
|
|
||||||
code: '414',
|
|
||||||
message:
|
|
||||||
"reservation doesn't exist. Lowest amount exceeds the maximum balance",
|
|
||||||
data: {},
|
|
||||||
};
|
|
||||||
|
|
||||||
// log warn
|
|
||||||
winston.logger.warn(
|
|
||||||
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
|
|
||||||
result
|
|
||||||
)}`
|
|
||||||
);
|
|
||||||
|
|
||||||
return res.status(200).json(result);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
result = {
|
result = {
|
||||||
code: '416',
|
code: '416',
|
||||||
message: 'your card number has reached the maximum balance',
|
message: 'your card number has reached the maximum balance',
|
||||||
@@ -451,7 +465,6 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
return res.status(200).json(result);
|
return res.status(200).json(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(`${uniqueCode} checking max topup per month...`);
|
winston.logger.debug(`${uniqueCode} checking max topup per month...`);
|
||||||
@@ -476,58 +489,6 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
parseInt(accumulatedBalance) + parseInt(amountTopup) >
|
parseInt(accumulatedBalance) + parseInt(amountTopup) >
|
||||||
parseInt(getMaxTopupPerMonth.c_value)
|
parseInt(getMaxTopupPerMonth.c_value)
|
||||||
) {
|
) {
|
||||||
// if topup partial is active
|
|
||||||
if (getTopupPartialStatus.c_value == 'A') {
|
|
||||||
// reset reservation data
|
|
||||||
partialTopup = true;
|
|
||||||
totalReservation = 0;
|
|
||||||
amountTopup = 0;
|
|
||||||
reservationNumber = [];
|
|
||||||
reservationNumberTemp = [];
|
|
||||||
i = 0;
|
|
||||||
|
|
||||||
// sum amount can be topup
|
|
||||||
getReservationPending.forEach((rsv) => {
|
|
||||||
if (
|
|
||||||
parseInt(balance) + parseInt(amountTopup) <=
|
|
||||||
parseInt(getMaxAmountOnTheCard.c_value)
|
|
||||||
) {
|
|
||||||
amountTopup += parseInt(rsv.i_reservation_amount);
|
|
||||||
if (
|
|
||||||
amountTopup > parseInt(getMaxAmountOnTheCard.c_value) ||
|
|
||||||
parseInt(balance) + amountTopup >
|
|
||||||
parseInt(getMaxAmountOnTheCard.c_value)
|
|
||||||
) {
|
|
||||||
amountTopup =
|
|
||||||
amountTopup - parseInt(rsv.i_reservation_amount);
|
|
||||||
i--;
|
|
||||||
} else {
|
|
||||||
reservationNumber.push(rsv.c_reservation_no);
|
|
||||||
reservationNumberTemp.push(rsv.c_reservation_no);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
});
|
|
||||||
|
|
||||||
totalReservation = i;
|
|
||||||
if (totalReservation == 0) {
|
|
||||||
result = {
|
|
||||||
code: '417',
|
|
||||||
message:
|
|
||||||
"reservation doesn't exist. Lowest amount exceeds the limit top up for this month",
|
|
||||||
data: {},
|
|
||||||
};
|
|
||||||
|
|
||||||
// log warn
|
|
||||||
winston.logger.warn(
|
|
||||||
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
|
|
||||||
result
|
|
||||||
)}`
|
|
||||||
);
|
|
||||||
|
|
||||||
return res.status(200).json(result);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
result = {
|
result = {
|
||||||
code: '417',
|
code: '417',
|
||||||
message: 'your card number has been limit top up for this month',
|
message: 'your card number has been limit top up for this month',
|
||||||
@@ -545,16 +506,23 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
winston.logger.debug(
|
||||||
`${uniqueCode} updating status reservation to in progress...`
|
`${uniqueCode} updating status reservation to in progress...${reservationNumberTemp}, ${now}, ${flag}`
|
||||||
);
|
);
|
||||||
|
|
||||||
// update status to in progress
|
// update status to in progress
|
||||||
await model.updateStatusReservation(reservationNumberTemp, now);
|
let updateStatusReservation = await model.updateStatusReservation(
|
||||||
|
reservationNumberTemp,
|
||||||
|
now,
|
||||||
|
flag
|
||||||
|
);
|
||||||
|
|
||||||
|
// log debug
|
||||||
|
winston.logger.debug(`${uniqueCode} XXXXX ${updateStatusReservation}`);
|
||||||
|
|
||||||
|
if (updateStatusReservation) {
|
||||||
result = {
|
result = {
|
||||||
code: '00',
|
code: '00',
|
||||||
message: 'reservation exists',
|
message: 'reservation exists',
|
||||||
@@ -562,14 +530,33 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
amount: amountTopup,
|
amount: amountTopup,
|
||||||
total_reservation: totalReservation,
|
total_reservation: totalReservation,
|
||||||
reservation_number: reservationNumber,
|
reservation_number: reservationNumber,
|
||||||
partial_topup: partialTopup,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// log info
|
// log info
|
||||||
winston.logger.info(
|
winston.logger.info(
|
||||||
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(result)}`
|
`${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);
|
return res.json(result);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -637,38 +624,38 @@ const loadingBalance = async (req, res) => {
|
|||||||
`${uniqueCode} checking production card number or not...`
|
`${uniqueCode} checking production card number or not...`
|
||||||
);
|
);
|
||||||
|
|
||||||
if (process.env.SERVER_FOR == 'production') {
|
// if (process.env.SERVER_FOR == 'production') {
|
||||||
if (card_number.substring(0, 1) != '1') {
|
// if (card_number.substring(0, 1) != '1') {
|
||||||
result = {
|
// result = {
|
||||||
code: '400',
|
// code: '400',
|
||||||
message: "It's not production card number.",
|
// message: "It's not production card number.",
|
||||||
data: {},
|
// data: {},
|
||||||
};
|
// };
|
||||||
|
|
||||||
// log warn
|
// // log warn
|
||||||
winston.logger.warn(
|
// winston.logger.warn(
|
||||||
`${uniqueCode} RESPONSE check reservation: ${JSON.stringify(result)}`
|
// `${uniqueCode} RESPONSE check reservation: ${JSON.stringify(result)}`
|
||||||
);
|
// );
|
||||||
|
|
||||||
return res.status(200).json(result);
|
// return res.status(200).json(result);
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
if (card_number.substring(0, 1) == '1') {
|
// if (card_number.substring(0, 1) == '1') {
|
||||||
result = {
|
// result = {
|
||||||
code: '400',
|
// code: '400',
|
||||||
message:
|
// message:
|
||||||
"It's production card number. Please use the development card number.",
|
// "It's production card number. Please use the development card number.",
|
||||||
data: {},
|
// data: {},
|
||||||
};
|
// };
|
||||||
|
|
||||||
// log warn
|
// // log warn
|
||||||
winston.logger.warn(
|
// winston.logger.warn(
|
||||||
`${uniqueCode} RESPONSE check reservation: ${JSON.stringify(result)}`
|
// `${uniqueCode} RESPONSE check reservation: ${JSON.stringify(result)}`
|
||||||
);
|
// );
|
||||||
|
|
||||||
return res.status(200).json(result);
|
// return res.status(200).json(result);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// time
|
// time
|
||||||
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||||
@@ -781,7 +768,7 @@ const loadingBalance = async (req, res) => {
|
|||||||
amountTopup += parseInt(rsv.i_reservation_amount);
|
amountTopup += parseInt(rsv.i_reservation_amount);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (amount != amountTopup) {
|
if (parseInt(amount) != parseInt(amountTopup)) {
|
||||||
result = {
|
result = {
|
||||||
code: '418',
|
code: '418',
|
||||||
message: 'topup amount is different',
|
message: 'topup amount is different',
|
||||||
@@ -1065,8 +1052,8 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||||
let today = moment().format('YYYY-MM-DD');
|
let today = moment().format('YYYY-MM-DD');
|
||||||
|
|
||||||
// log debug
|
// log warn
|
||||||
winston.logger.debug(`${uniqueCode} checking partner...`);
|
winston.logger.warn(`${uniqueCode} 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);
|
||||||
@@ -1085,8 +1072,8 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
// log warn
|
||||||
winston.logger.debug(`${uniqueCode} checking reservation status...`);
|
winston.logger.warn(`${uniqueCode} 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++) {
|
||||||
@@ -1094,6 +1081,7 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
reservation_number[index]
|
reservation_number[index]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// if reservation doesn't exist or has been canceled
|
||||||
if (!reservationStatus) {
|
if (!reservationStatus) {
|
||||||
result = {
|
result = {
|
||||||
code: '414',
|
code: '414',
|
||||||
@@ -1111,10 +1099,14 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if there are reservation with status active
|
||||||
if (reservationStatus.c_status == 'A') {
|
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
|
reservationStatus.i_reservation_balance
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (reservationLoaded) {
|
||||||
let loadBalanceNumberExisting = reservationLoaded.c_load_balance_no;
|
let loadBalanceNumberExisting = reservationLoaded.c_load_balance_no;
|
||||||
let loadDate = reservationLoaded.d_load_balance;
|
let loadDate = reservationLoaded.d_load_balance;
|
||||||
result = {
|
result = {
|
||||||
@@ -1137,15 +1129,67 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// log debug
|
// log warn
|
||||||
winston.logger.debug(`${uniqueCode} checking reservation pending...`);
|
winston.logger.warn(`${uniqueCode} checking last log history...`);
|
||||||
|
|
||||||
// get total reservation pending
|
// get last history by card number
|
||||||
let getReservationPending = await model.getReservationPending(
|
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: '432',
|
||||||
|
message: 'your card number has fraud transaction',
|
||||||
|
data: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
// log warn
|
||||||
|
winston.logger.warn(
|
||||||
|
`${uniqueCode} RESPONSE load balance insert: ${JSON.stringify(
|
||||||
|
result
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// log warn
|
||||||
|
winston.logger.warn(`${uniqueCode} checking fraud transaction...`);
|
||||||
|
|
||||||
|
// 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,
|
card_number,
|
||||||
now,
|
flag,
|
||||||
flag
|
fraudReservationNumber
|
||||||
);
|
);
|
||||||
|
|
||||||
if (getReservationPending.length < 1) {
|
if (getReservationPending.length < 1) {
|
||||||
@@ -1163,8 +1207,8 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
// log warn
|
||||||
winston.logger.debug(`${uniqueCode} checking total topup amount...`);
|
winston.logger.warn(`${uniqueCode} checking total topup amount...`);
|
||||||
|
|
||||||
// check total topup and request topup
|
// check total topup and request topup
|
||||||
let amountTopup = 0;
|
let amountTopup = 0;
|
||||||
@@ -1172,7 +1216,7 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
amountTopup += parseInt(rsv.i_reservation_amount);
|
amountTopup += parseInt(rsv.i_reservation_amount);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (amount != amountTopup) {
|
if (parseInt(amount) != parseInt(amountTopup)) {
|
||||||
result = {
|
result = {
|
||||||
code: '418',
|
code: '418',
|
||||||
message: 'topup amount is different',
|
message: 'topup amount is different',
|
||||||
@@ -1205,8 +1249,8 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
? parseInt(getLoadBalanceSequence.i_load_balance_no_seq) + 1
|
? parseInt(getLoadBalanceSequence.i_load_balance_no_seq) + 1
|
||||||
: 1;
|
: 1;
|
||||||
|
|
||||||
// log debug
|
// log warn
|
||||||
winston.logger.debug(`${uniqueCode} generating load balance number...`);
|
winston.logger.warn(`${uniqueCode} generating load balance number...`);
|
||||||
|
|
||||||
loadBalanceNumber = await generateLoadBalanceNumber(
|
loadBalanceNumber = await generateLoadBalanceNumber(
|
||||||
getPartner,
|
getPartner,
|
||||||
@@ -1214,6 +1258,11 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
loadBalanceNoSequence
|
loadBalanceNoSequence
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// log warn
|
||||||
|
winston.logger.warn(
|
||||||
|
`${uniqueCode} load balance number is ${loadBalanceNumber}.`
|
||||||
|
);
|
||||||
|
|
||||||
if (maxLoop > 20) {
|
if (maxLoop > 20) {
|
||||||
// create log
|
// create log
|
||||||
winston.logger.error(
|
winston.logger.error(
|
||||||
@@ -1275,8 +1324,13 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
winston.logger.debug(`${uniqueCode} getting reservation detail...`);
|
winston.logger.debug(`${uniqueCode} getting reservation detail...`);
|
||||||
|
|
||||||
let detail = [];
|
let detail = [];
|
||||||
for (let index = 0; index < reservation_number.length; index++) {
|
reservation_number = [];
|
||||||
let reservation = await model.findReservation(reservation_number[index]);
|
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) {
|
if (!reservation) {
|
||||||
result = {
|
result = {
|
||||||
@@ -1337,11 +1391,11 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
`${uniqueCode} checking load balance transaction has been exists or not...`
|
`${uniqueCode} checking load balance transaction has been exists or not...`
|
||||||
);
|
);
|
||||||
|
|
||||||
// log debug
|
// log warn
|
||||||
winston.logger.debug(`${uniqueCode} inserting load balance transaction...`);
|
winston.logger.warn(`${uniqueCode} inserting load balance transaction...`);
|
||||||
|
|
||||||
// insert transaction
|
// insert transaction
|
||||||
await model.insertLoadingBalance(
|
let insertLoadingBalance = await model.insertLoadingBalance(
|
||||||
data,
|
data,
|
||||||
detail,
|
detail,
|
||||||
reservation_number,
|
reservation_number,
|
||||||
@@ -1353,6 +1407,22 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
flag
|
flag
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 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 = {
|
result = {
|
||||||
code: '00',
|
code: '00',
|
||||||
message: write_status
|
message: write_status
|
||||||
@@ -1367,6 +1437,20 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
winston.logger.info(
|
winston.logger.info(
|
||||||
`${uniqueCode} RESPONSE load balance insert: ${JSON.stringify(result)}`
|
`${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;
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -1896,7 +1980,9 @@ const updateReservationAndLoadingBalance = async (
|
|||||||
cardNumber,
|
cardNumber,
|
||||||
balance,
|
balance,
|
||||||
flag,
|
flag,
|
||||||
uniqueCode
|
uniqueCode,
|
||||||
|
totalReservationAmount,
|
||||||
|
uid
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
// log debug
|
// log debug
|
||||||
@@ -1909,17 +1995,18 @@ const updateReservationAndLoadingBalance = async (
|
|||||||
|
|
||||||
// get load balance
|
// get load balance
|
||||||
let dataLoadingBalance = null;
|
let dataLoadingBalance = null;
|
||||||
|
let dataLoadingBalanceDetail = [];
|
||||||
|
|
||||||
|
if (loadBalanceNumber.length > 0) {
|
||||||
let getLastLoadingBalanceFlag = await model.getLastLoadingBalanceFlag(
|
let getLastLoadingBalanceFlag = await model.getLastLoadingBalanceFlag(
|
||||||
loadBalanceNumber
|
loadBalanceNumber
|
||||||
);
|
);
|
||||||
if (getLastLoadingBalanceFlag) {
|
if (getLastLoadingBalanceFlag) {
|
||||||
dataLoadingBalance = getLastLoadingBalanceFlag;
|
dataLoadingBalance = getLastLoadingBalanceFlag;
|
||||||
} else {
|
}
|
||||||
// insert new load balance transaction by data on card and update data reservation
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// get detail load balance
|
// get detail load balance
|
||||||
let dataLoadingBalanceDetail = [];
|
|
||||||
if (dataLoadingBalance) {
|
if (dataLoadingBalance) {
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
winston.logger.debug(
|
||||||
@@ -1935,12 +2022,12 @@ const updateReservationAndLoadingBalance = async (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataLoadingBalance && dataLoadingBalanceDetail.length > 0) {
|
|
||||||
// time
|
// time
|
||||||
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||||
let today = moment().format('YYYY-MM-DD');
|
let today = moment().format('YYYY-MM-DD');
|
||||||
let getPartner = await model.getPartner(mid, tid);
|
let getPartner = await model.getPartner(mid, tid);
|
||||||
|
|
||||||
|
if (dataLoadingBalance && dataLoadingBalanceDetail.length > 0) {
|
||||||
let data = {
|
let data = {
|
||||||
c_load_balance_no: dataLoadingBalance.c_load_balance_no,
|
c_load_balance_no: dataLoadingBalance.c_load_balance_no,
|
||||||
d_load_balance: dataLoadingBalance.d_load_balance,
|
d_load_balance: dataLoadingBalance.d_load_balance,
|
||||||
@@ -2020,8 +2107,176 @@ const updateReservationAndLoadingBalance = async (
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
// 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;
|
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) {
|
} catch (error) {
|
||||||
// create log
|
// create log
|
||||||
winston.logger.error(
|
winston.logger.error(
|
||||||
|
|||||||
@@ -72,8 +72,33 @@ const getReservationPending = (cardNumber, time, flag) => {
|
|||||||
// .where("d_expired", ">=", time)
|
// .where("d_expired", ">=", time)
|
||||||
.where(function () {
|
.where(function () {
|
||||||
this.orWhere('c_flag', flag).orWhere('c_flag', '-1');
|
this.orWhere('c_flag', flag).orWhere('c_flag', '-1');
|
||||||
})
|
});
|
||||||
.orderBy('i_reservation_amount', 'asc');
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
const getReservationPendingV2 = (cardNumber, time, flag) => {
|
||||||
|
let result = knex('trx.t_d_reservation_balance')
|
||||||
|
// .sum("i_reservation_amount as total_reservation_amount")
|
||||||
|
// .count("* as total_reservation")
|
||||||
|
.select(
|
||||||
|
'i_reservation_amount',
|
||||||
|
'c_reservation_no',
|
||||||
|
'c_flag',
|
||||||
|
'd_reservation',
|
||||||
|
'c_ref_no',
|
||||||
|
'c_card_number',
|
||||||
|
'c_status'
|
||||||
|
)
|
||||||
|
.where('c_card_number', cardNumber)
|
||||||
|
.whereIn('c_status', ['P', 'I'])
|
||||||
|
// .where("d_expired", ">=", time)
|
||||||
|
.whereRaw(
|
||||||
|
`c_reservation_no NOT IN (SELECT c_reservation_no FROM trx.t_d_fraud tdf WHERE tdf.c_status = 'A' AND tdf.c_card_number = '${cardNumber}')`
|
||||||
|
)
|
||||||
|
.where(function () {
|
||||||
|
this.orWhere('c_flag', flag).orWhere('c_flag', '-1');
|
||||||
|
});
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -96,6 +121,28 @@ const getReservationPendingWithFlagCounter = (cardNumber, time, flag) => {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// GET RESERVATION PENDING WITH COMPARE FLAG COUNTER
|
||||||
|
const getReservationPendingWithFlagCounterV2 = (cardNumber, time, flag) => {
|
||||||
|
let result = knex('trx.t_d_reservation_balance')
|
||||||
|
// .sum("i_reservation_amount as total_reservation_amount")
|
||||||
|
// .count("* as total_reservation")
|
||||||
|
.select(
|
||||||
|
'i_reservation_amount',
|
||||||
|
'c_reservation_no',
|
||||||
|
'c_flag',
|
||||||
|
'c_load_balance_no'
|
||||||
|
)
|
||||||
|
.where('c_card_number', cardNumber)
|
||||||
|
.whereIn('c_status', ['P', 'I'])
|
||||||
|
.whereRaw('??::INT < ??', ['c_flag', parseInt(flag)])
|
||||||
|
.whereRaw(
|
||||||
|
`c_reservation_no NOT IN (SELECT c_reservation_no FROM trx.t_d_fraud tdf WHERE tdf.c_status = 'A' AND tdf.c_card_number = '${cardNumber}')`
|
||||||
|
)
|
||||||
|
// .where("d_expired", ">=", time)
|
||||||
|
.where('c_flag', '!=', '-1');
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
// GET RESERVATION PENDING WITH FLAG
|
// GET RESERVATION PENDING WITH FLAG
|
||||||
const getReservationPendingWithFlag = (cardNumber, time) => {
|
const getReservationPendingWithFlag = (cardNumber, time) => {
|
||||||
let result = knex('trx.t_d_reservation_balance')
|
let result = knex('trx.t_d_reservation_balance')
|
||||||
@@ -108,6 +155,21 @@ const getReservationPendingWithFlag = (cardNumber, time) => {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// GET RESERVATION PENDING WITH FLAG
|
||||||
|
const getReservationPendingWithFlagV2 = (cardNumber, time) => {
|
||||||
|
let result = knex('trx.t_d_reservation_balance')
|
||||||
|
// .sum("i_reservation_amount as total_reservation_amount")
|
||||||
|
// .count("* as total_reservation")
|
||||||
|
.select('i_reservation_amount', 'c_reservation_no', 'c_flag')
|
||||||
|
.where('c_card_number', cardNumber)
|
||||||
|
.whereIn('c_status', ['P', 'I'])
|
||||||
|
.whereRaw(
|
||||||
|
`c_reservation_no NOT IN (SELECT c_reservation_no FROM trx.t_d_fraud tdf WHERE tdf.c_status = 'A' AND tdf.c_card_number = '${cardNumber}')`
|
||||||
|
)
|
||||||
|
.whereNotNull('c_flag_code');
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
// GET BI REGULATION STATUS FROM GLOBAL PARAMETER
|
// GET BI REGULATION STATUS FROM GLOBAL PARAMETER
|
||||||
const getBIRegulationStatus = () => {
|
const getBIRegulationStatus = () => {
|
||||||
let result = knex('t_m_global_parameter')
|
let result = knex('t_m_global_parameter')
|
||||||
@@ -217,7 +279,7 @@ const insertLoadingBalance = async (
|
|||||||
balance,
|
balance,
|
||||||
flag
|
flag
|
||||||
) => {
|
) => {
|
||||||
await knex
|
return await knex
|
||||||
.transaction((trx) => {
|
.transaction((trx) => {
|
||||||
knex('trx.t_d_load_balance')
|
knex('trx.t_d_load_balance')
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
@@ -321,7 +383,7 @@ const insertLoadingBalance = async (
|
|||||||
})
|
})
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
// console.log(result);
|
// console.log(result);
|
||||||
return result;
|
return result.rowCount;
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log(error.message);
|
console.log(error.message);
|
||||||
@@ -539,7 +601,7 @@ const updateReservationAndLoadingBalance = async (
|
|||||||
now,
|
now,
|
||||||
flag
|
flag
|
||||||
) => {
|
) => {
|
||||||
await knex
|
return await knex
|
||||||
.transaction((trx) => {
|
.transaction((trx) => {
|
||||||
knex('trx.t_d_load_balance')
|
knex('trx.t_d_load_balance')
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
@@ -600,7 +662,7 @@ const updateReservationAndLoadingBalance = async (
|
|||||||
})
|
})
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
// console.log(result);
|
// console.log(result);
|
||||||
return result;
|
return result.rowCount;
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log(error.message);
|
console.log(error.message);
|
||||||
@@ -641,11 +703,12 @@ const getLastLoadingBalanceDetailFlag = (loadBalanceId) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// update
|
// update
|
||||||
const updateStatusReservation = (reservationNumber, now) => {
|
const updateStatusReservation = (reservationNumber, now, flag) => {
|
||||||
let result = knex('trx.t_d_reservation_balance')
|
let result = knex('trx.t_d_reservation_balance')
|
||||||
.update({
|
.update({
|
||||||
c_status: 'I',
|
c_status: 'I',
|
||||||
c_status_name: 'IN PROGRESS',
|
c_status_name: 'IN PROGRESS',
|
||||||
|
c_flag: flag,
|
||||||
d_modify: now,
|
d_modify: now,
|
||||||
i_modify: null,
|
i_modify: null,
|
||||||
c_modify_username: null,
|
c_modify_username: null,
|
||||||
@@ -723,16 +786,248 @@ const insertLoadBalanceNumber = (loadBalanceNumber) => {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// GET TOPUP PARTIAL STATUS FROM GLOBAL PARAMETER
|
// GET RESERVATION PENDING WITHOUT FRAUD
|
||||||
const getTopupPartialStatus = () => {
|
const getReservationPendingWithoutFraud = (
|
||||||
let result = knex('t_m_global_parameter')
|
cardNumber,
|
||||||
.select('c_value')
|
flag,
|
||||||
.where('c_code', 'HSM_TOPUP_PARTIAL_STAT')
|
reservationNumber = []
|
||||||
.where('c_status', 'A')
|
) => {
|
||||||
|
if (reservationNumber.length > 0) {
|
||||||
|
let rsv = ``;
|
||||||
|
if (reservationNumber.length > 0) {
|
||||||
|
for (let index = 0; index < reservationNumber.length; index++) {
|
||||||
|
if (index > 0) {
|
||||||
|
rsv = rsv + `,`;
|
||||||
|
}
|
||||||
|
|
||||||
|
rsv = `'` + rsv + reservationNumber[index] + `'`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let result = knex('trx.t_d_reservation_balance')
|
||||||
|
.select(
|
||||||
|
'trx.t_d_reservation_balance.i_reservation_amount',
|
||||||
|
'trx.t_d_reservation_balance.c_reservation_no',
|
||||||
|
'trx.t_d_reservation_balance.c_flag'
|
||||||
|
)
|
||||||
|
.where('trx.t_d_reservation_balance.c_card_number', cardNumber)
|
||||||
|
.whereIn('trx.t_d_reservation_balance.c_status', ['P', 'I'])
|
||||||
|
.whereRaw(
|
||||||
|
`trx.t_d_reservation_balance.c_reservation_no NOT IN (SELECT c_reservation_no FROM trx.t_d_fraud WHERE trx.t_d_fraud.c_status = 'A' AND trx.t_d_fraud.c_reservation_no IN (${rsv}))`
|
||||||
|
)
|
||||||
|
// .where("d_expired", ">=", time)
|
||||||
|
.where(function () {
|
||||||
|
this.orWhere('trx.t_d_reservation_balance.c_flag', flag).orWhere(
|
||||||
|
'trx.t_d_reservation_balance.c_flag',
|
||||||
|
'-1'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
} else {
|
||||||
|
let result = knex('trx.t_d_reservation_balance')
|
||||||
|
// .sum("i_reservation_amount as total_reservation_amount")
|
||||||
|
// .count("* as total_reservation")
|
||||||
|
.select('i_reservation_amount', 'c_reservation_no', 'c_flag')
|
||||||
|
.where('c_card_number', cardNumber)
|
||||||
|
.whereIn('c_status', ['P', 'I'])
|
||||||
|
// .where("d_expired", ">=", time)
|
||||||
|
.where(function () {
|
||||||
|
this.orWhere('c_flag', flag).orWhere('c_flag', '-1');
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// GET FRAUD TRANSACTION
|
||||||
|
const getFraudTransaction = (cardNumber) => {
|
||||||
|
let result = knex('trx.t_d_fraud')
|
||||||
|
.where('c_card_number', cardNumber)
|
||||||
|
.where('c_status', '!=', 'X');
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
// GET FRAUD TRANSACTION
|
||||||
|
const getLastHistory = (cardNumber) => {
|
||||||
|
let result = knex('log.t_log_card')
|
||||||
|
.where('c_card_number', cardNumber)
|
||||||
|
.whereIn('i_log_name', [21, 90])
|
||||||
|
.where('c_source', 'CMS')
|
||||||
|
.where('c_status', 'S')
|
||||||
|
.orderBy('d_log', 'desc')
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// INSERT FRAUD TRANSACTION
|
||||||
|
const insertFraudTransaction = (reservationNumber) => {
|
||||||
|
let rsv = ``;
|
||||||
|
if (reservationNumber.length > 0) {
|
||||||
|
for (let index = 0; index < reservationNumber.length; index++) {
|
||||||
|
if (index > 0) {
|
||||||
|
rsv = rsv + `,`;
|
||||||
|
}
|
||||||
|
|
||||||
|
rsv = `'` + rsv + reservationNumber[index] + `'`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let result = knex
|
||||||
|
.into(
|
||||||
|
knex.raw('?? (??, ??, ??, ??, ??, ??)', [
|
||||||
|
'trx.t_d_fraud',
|
||||||
|
'c_card_number',
|
||||||
|
'c_reservation_no',
|
||||||
|
'i_reservation_amount',
|
||||||
|
'c_reservation_status',
|
||||||
|
'c_reservation_flag',
|
||||||
|
'c_reservation_ref_no',
|
||||||
|
])
|
||||||
|
)
|
||||||
|
.insert(function () {
|
||||||
|
this.select(
|
||||||
|
'c_card_number',
|
||||||
|
'c_reservation_no',
|
||||||
|
'i_reservation_amount',
|
||||||
|
'c_status',
|
||||||
|
'c_flag',
|
||||||
|
'c_ref_no'
|
||||||
|
)
|
||||||
|
.from('trx.t_d_reservation_balance')
|
||||||
|
.whereIn(
|
||||||
|
'trx.t_d_reservation_balance.c_reservation_no',
|
||||||
|
reservationNumber
|
||||||
|
)
|
||||||
|
.whereRaw(
|
||||||
|
`trx.t_d_reservation_balance.c_reservation_no NOT IN (SELECT c_reservation_no FROM trx.t_d_fraud WHERE trx.t_d_fraud.c_status = 'A' AND trx.t_d_fraud.c_reservation_no IN (${rsv}))`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
// SUSPEND RESERVATION
|
||||||
|
const suspendReservation = (reservationNumber, datetime) => {
|
||||||
|
let result = knex('trx.t_d_reservation_balance')
|
||||||
|
.update({
|
||||||
|
c_status: 'S',
|
||||||
|
c_status_name: 'SUSPEND',
|
||||||
|
d_modify: datetime,
|
||||||
|
})
|
||||||
|
.whereIn('c_reservation_no', reservationNumber);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
// CHECK HISTORY CARD
|
||||||
|
const checkCardHistory = (c_card_number) => {
|
||||||
|
let result = knex('log.t_log_card')
|
||||||
|
// .select(['i_log_name', 'c_source'])
|
||||||
|
.where('c_card_number', c_card_number)
|
||||||
|
.where('c_source', 'CMS')
|
||||||
|
.whereIn('i_log_name', ['21', '90'])
|
||||||
|
.orderBy('d_log', 'DESC')
|
||||||
|
.first();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
// INSERT FRAUD
|
||||||
|
const insertFraud = (data) => {
|
||||||
|
let result = knex('trx.t_d_fraud').insert(data, ['c_reservation_no']);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
// UPDATE RESERVE BALANCE
|
||||||
|
const updateFraudToReserve = (reserve_no) => {
|
||||||
|
let result = knex('trx.t_d_reservation_balance')
|
||||||
|
.update({
|
||||||
|
c_status: 'S',
|
||||||
|
c_status_name: 'SUSPEND',
|
||||||
|
})
|
||||||
|
.whereIn('c_reservation_no', reserve_no);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
// CREATE DETAIL LOAD BALANCE FROM RESERVATION
|
||||||
|
const createDetailLoadBalanceFromReservation = (reservationNumber) => {
|
||||||
|
let result = knex('trx.t_d_reservation_balance')
|
||||||
|
.whereIn('c_reservation_no', reservationNumber)
|
||||||
|
.where('c_status', '!=', 'X');
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
// UPDATE RESERVATION AND LOADING BALANCE CASE FAILED WRITE BEFORE
|
||||||
|
const updateReservationAndInsertLoadingBalance = async (
|
||||||
|
reservationNumber,
|
||||||
|
dataLoadBalance,
|
||||||
|
detailLoadBalance,
|
||||||
|
now,
|
||||||
|
flag
|
||||||
|
) => {
|
||||||
|
return await knex
|
||||||
|
.transaction((trx) => {
|
||||||
|
knex('trx.t_d_load_balance')
|
||||||
|
.transacting(trx)
|
||||||
|
.insert(dataLoadBalance)
|
||||||
|
.returning('i_load_balance')
|
||||||
|
.then((detail) => {
|
||||||
|
let id = detail[0];
|
||||||
|
let loadDetail = [];
|
||||||
|
detailLoadBalance.forEach((element) => {
|
||||||
|
loadDetail.push({
|
||||||
|
i_load_balance: id,
|
||||||
|
i_reservation_balance: element.i_reservation_balance,
|
||||||
|
c_reservation_no: element.c_reservation_no,
|
||||||
|
i_amount: element.i_reservation_amount,
|
||||||
|
i_issuer: element.i_issuer,
|
||||||
|
i_issuer_code: element.i_issuer_code,
|
||||||
|
i_issuer_name: element.i_issuer_name,
|
||||||
|
i_issuer_fee: element.i_issuer_fee,
|
||||||
|
i_channel: element.i_channel,
|
||||||
|
i_channel_code: element.i_channel_code,
|
||||||
|
i_channel_name: element.i_channel_name,
|
||||||
|
i_channel_fee: element.i_channel_fee,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// insert detail load balance
|
||||||
|
return knex('trx.t_d_load_balance_detail')
|
||||||
|
.transacting(trx)
|
||||||
|
.insert(loadDetail);
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
// update reservation
|
||||||
|
return knex('trx.t_d_reservation_balance')
|
||||||
|
.transacting(trx)
|
||||||
|
.update({
|
||||||
|
d_load_balance: dataLoadBalance.d_load_balance,
|
||||||
|
c_load_balance_no: dataLoadBalance.c_load_balance_no,
|
||||||
|
c_flag: flag,
|
||||||
|
c_flag_code: null,
|
||||||
|
c_status: 'A',
|
||||||
|
c_status_name: 'LOADED',
|
||||||
|
d_modify: now,
|
||||||
|
i_modify: null,
|
||||||
|
c_modify_username: null,
|
||||||
|
c_modify_fullname: null,
|
||||||
|
})
|
||||||
|
.whereIn('c_reservation_no', reservationNumber);
|
||||||
|
})
|
||||||
|
.then(trx.commit)
|
||||||
|
.catch(trx.rollback);
|
||||||
|
})
|
||||||
|
.then((result) => {
|
||||||
|
console.log(result);
|
||||||
|
return result.rowCount;
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log(error.message);
|
||||||
|
return error.message;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
checkCardNumber,
|
checkCardNumber,
|
||||||
getPartner,
|
getPartner,
|
||||||
@@ -764,5 +1059,17 @@ module.exports = {
|
|||||||
getAccumulationBalanceInThisMonthFromCardHistory,
|
getAccumulationBalanceInThisMonthFromCardHistory,
|
||||||
createLoadBalanceLog,
|
createLoadBalanceLog,
|
||||||
insertLoadBalanceNumber,
|
insertLoadBalanceNumber,
|
||||||
getTopupPartialStatus,
|
getReservationPendingWithoutFraud,
|
||||||
|
getFraudTransaction,
|
||||||
|
getLastHistory,
|
||||||
|
insertFraudTransaction,
|
||||||
|
suspendReservation,
|
||||||
|
checkCardHistory,
|
||||||
|
insertFraud,
|
||||||
|
updateFraudToReserve,
|
||||||
|
getReservationPendingV2,
|
||||||
|
getReservationPendingWithFlagCounterV2,
|
||||||
|
getReservationPendingWithFlagV2,
|
||||||
|
createDetailLoadBalanceFromReservation,
|
||||||
|
updateReservationAndInsertLoadingBalance,
|
||||||
};
|
};
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
+3
-3
@@ -8,7 +8,7 @@ let password;
|
|||||||
|
|
||||||
if (process.env.SERVER_FOR == 'local') {
|
if (process.env.SERVER_FOR == 'local') {
|
||||||
host = 'localhost';
|
host = 'localhost';
|
||||||
database = 'CMS_DEV';
|
database = 'postgres';
|
||||||
port = 5432;
|
port = 5432;
|
||||||
user = 'postgres';
|
user = 'postgres';
|
||||||
password = 'postgres';
|
password = 'postgres';
|
||||||
@@ -16,8 +16,8 @@ if (process.env.SERVER_FOR == 'local') {
|
|||||||
host = '10.20.14.14';
|
host = '10.20.14.14';
|
||||||
database = 'postgres';
|
database = 'postgres';
|
||||||
port = 5432;
|
port = 5432;
|
||||||
user = 'cms';
|
user = 'postgres';
|
||||||
password = 'Cm5kc1#2021';
|
password = 'inhc0mmute_cms';
|
||||||
} else if (process.env.SERVER_FOR == 'production') {
|
} else if (process.env.SERVER_FOR == 'production') {
|
||||||
host = '10.1.201.75';
|
host = '10.1.201.75';
|
||||||
database = 'postgres';
|
database = 'postgres';
|
||||||
|
|||||||
Reference in New Issue
Block a user