Compare commits

..

10 Commits

Author SHA1 Message Date
ihsan c8f01db5e9 update 2023-03-03 17:33:01 +07:00
ihsan 1be5cc8d0c update 2023-03-03 17:31:43 +07:00
ihsan 352ec2822f update 2023-03-03 17:31:02 +07:00
ihsan 9910d4d834 update 2023-03-03 17:28:29 +07:00
ihsan a2eb984658 update 2023-03-03 17:25:24 +07:00
ihsan eac57a3821 update 2023-03-03 17:21:07 +07:00
ihsan f4451aaea2 update 2023-03-03 17:11:50 +07:00
ihsan 837d1c5d77 update 2023-03-03 16:33:20 +07:00
ihsan 74825d277b update 2023-03-03 16:26:01 +07:00
ihsan 8c231e9901 update 2023-03-03 16:16:14 +07:00
2 changed files with 473 additions and 513 deletions
@@ -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');
@@ -412,194 +412,150 @@ const loadingBalanceRequest = async (req, res) => {
`${uniqueCode} checking the card number in list fraud transaction or not...` `${uniqueCode} checking the card number in list fraud transaction or not...`
); );
// check fraud transaction by card number and how much fraud amount // log debug
let fraudTransaction = await model.getFraudTopupAndDeductTransaction( winston.logger.debug(`${uniqueCode} checking total topup amount...`);
card_number
);
let fraudReservationNumber = []; // check total amount topup
let amountFraudTopup = 0; if (parseInt(amountTopup) <= 0) {
let amountFraudDeduct = 0; result = {
let restAmountFraud = 0; code: '415',
let totalFraudReservation = 0; message: 'amount must be greater than 0',
data: {},
};
// if card number has fraud transaction // log warn
if (fraudTransaction.length > 0) { winston.logger.warn(
let i = 0; `${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
result
)}`
);
if (fraudTransaction.length > 0) { return res.status(200).json(result);
fraudTransaction.forEach((rsv) => {
fraudReservationNumber.push(rsv.c_reservation_no);
amountFraudTopup += parseInt(rsv.i_reservation_amount);
i++;
});
}
totalFraudReservation = i;
} }
// calculate rest amount fraud // log debug
restAmountFraud = parseInt(amountFraudTopup) - parseInt(amountFraudDeduct); winston.logger.debug(`${uniqueCode} checking BI regulation status...`);
// if card number has fraud transaction and amount greater than 0 // get BI regulation status
if (parseInt(restAmountFraud) > 0) { const getBIRegulationStatus = await model.getBIRegulationStatus();
// fraud reservation found, and tell the lib to deduct transaction if (getBIRegulationStatus.c_value == 'A') {
// log debug
winston.logger.debug(`${uniqueCode} checking max balance on the card...`);
// get max saldo on the card
const getMaxAmountOnTheCard = await model.getMaxAmountOnTheCard();
if (getMaxAmountOnTheCard.c_value) {
if (
parseInt(balance) + parseInt(amountTopup) >
parseInt(getMaxAmountOnTheCard.c_value)
) {
result = {
code: '416',
message: 'your card number has reached the maximum balance',
data: {},
};
// log warn
winston.logger.warn(
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
result
)}`
);
return res.status(200).json(result);
}
}
// log debug
winston.logger.debug(`${uniqueCode} checking max topup per month...`);
// get accumulated balance in this month
let accumulatedBalance = 0;
let getAccumulationBalanceInThisMonthFromCardHistory =
await model.getAccumulationBalanceInThisMonthFromCardHistory(
card_number,
year,
month
);
if (getAccumulationBalanceInThisMonthFromCardHistory) {
accumulatedBalance =
getAccumulationBalanceInThisMonthFromCardHistory.accumulation_balance;
}
// validate max topup per month
const getMaxTopupPerMonth = await model.getMaxTopupPerMonth();
if (getMaxTopupPerMonth.c_value) {
if (
parseInt(accumulatedBalance) + parseInt(amountTopup) >
parseInt(getMaxTopupPerMonth.c_value)
) {
result = {
code: '417',
message: 'your card number has been 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);
}
}
}
// 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 = { result = {
code: '00', code: '00',
message: 'reservation exists', message: 'reservation exists',
data: { data: {
amount: parseInt(amountFraudTopup) * -1, amount: amountTopup,
total_reservation: totalFraudReservation, total_reservation: totalReservation,
reservation_number: fraudReservationNumber, reservation_number: reservationNumber,
}, },
}; };
// log info
winston.logger.info(
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
result
)}`
);
} else { } else {
// card number does't have fraud transaction result = {
code: '434',
message: '[434] Failed, please try again later',
data: {
amount: amountTopup,
total_reservation: totalReservation,
reservation_number: reservationNumber,
},
};
// log debug // log info
winston.logger.debug(`${uniqueCode} checking total topup amount...`); winston.logger.info(
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
// check total amount topup result
if (parseInt(amountTopup) <= 0) { )}`
result = {
code: '415',
message: 'amount must be greater than 0',
data: {},
};
// log warn
winston.logger.warn(
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
result
)}`
);
return res.status(200).json(result);
}
// log debug
winston.logger.debug(`${uniqueCode} checking BI regulation status...`);
// get BI regulation status
const getBIRegulationStatus = await model.getBIRegulationStatus();
if (getBIRegulationStatus.c_value == 'A') {
// log debug
winston.logger.debug(
`${uniqueCode} checking max balance on the card...`
);
// get max saldo on the card
const getMaxAmountOnTheCard = await model.getMaxAmountOnTheCard();
if (getMaxAmountOnTheCard.c_value) {
if (
parseInt(balance) + parseInt(amountTopup) >
parseInt(getMaxAmountOnTheCard.c_value)
) {
result = {
code: '416',
message: 'your card number has reached the maximum balance',
data: {},
};
// log warn
winston.logger.warn(
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
result
)}`
);
return res.status(200).json(result);
}
}
// log debug
winston.logger.debug(`${uniqueCode} checking max topup per month...`);
// get accumulated balance in this month
let accumulatedBalance = 0;
let getAccumulationBalanceInThisMonthFromCardHistory =
await model.getAccumulationBalanceInThisMonthFromCardHistory(
card_number,
year,
month
);
if (getAccumulationBalanceInThisMonthFromCardHistory) {
accumulatedBalance =
getAccumulationBalanceInThisMonthFromCardHistory.accumulation_balance;
}
// validate max topup per month
const getMaxTopupPerMonth = await model.getMaxTopupPerMonth();
if (getMaxTopupPerMonth.c_value) {
if (
parseInt(accumulatedBalance) + parseInt(amountTopup) >
parseInt(getMaxTopupPerMonth.c_value)
) {
result = {
code: '417',
message: 'your card number has been 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);
}
}
}
// log debug
winston.logger.debug(
`${uniqueCode} updating status reservation to in progress...`
); );
// update status to in progress
let updateStatusReservation = await model.updateStatusReservation(
reservationNumberTemp,
now,
flag
);
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); return res.json(result);
@@ -668,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');
File diff suppressed because it is too large Load Diff