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...`
);
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');
@@ -412,194 +412,150 @@ const loadingBalanceRequest = async (req, res) => {
`${uniqueCode} checking the card number in list fraud transaction or not...`
);
// check fraud transaction by card number and how much fraud amount
let fraudTransaction = await model.getFraudTopupAndDeductTransaction(
card_number
);
// log debug
winston.logger.debug(`${uniqueCode} checking total topup amount...`);
let fraudReservationNumber = [];
let amountFraudTopup = 0;
let amountFraudDeduct = 0;
let restAmountFraud = 0;
let totalFraudReservation = 0;
// check total amount topup
if (parseInt(amountTopup) <= 0) {
result = {
code: '415',
message: 'amount must be greater than 0',
data: {},
};
// if card number has fraud transaction
if (fraudTransaction.length > 0) {
let i = 0;
// log warn
winston.logger.warn(
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
result
)}`
);
if (fraudTransaction.length > 0) {
fraudTransaction.forEach((rsv) => {
fraudReservationNumber.push(rsv.c_reservation_no);
amountFraudTopup += parseInt(rsv.i_reservation_amount);
i++;
});
}
totalFraudReservation = i;
return res.status(200).json(result);
}
// calculate rest amount fraud
restAmountFraud = parseInt(amountFraudTopup) - parseInt(amountFraudDeduct);
// log debug
winston.logger.debug(`${uniqueCode} checking BI regulation status...`);
// if card number has fraud transaction and amount greater than 0
if (parseInt(restAmountFraud) > 0) {
// fraud reservation found, and tell the lib to deduct transaction
// 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...${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: parseInt(amountFraudTopup) * -1,
total_reservation: totalFraudReservation,
reservation_number: fraudReservationNumber,
amount: amountTopup,
total_reservation: totalReservation,
reservation_number: reservationNumber,
},
};
// log info
winston.logger.info(
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
result
)}`
);
} 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
winston.logger.debug(`${uniqueCode} checking total topup amount...`);
// check total amount topup
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...`
// log info
winston.logger.info(
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
result
)}`
);
// 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);
@@ -668,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');
File diff suppressed because it is too large Load Diff