topup sebagian

This commit is contained in:
2023-02-13 19:14:17 +07:00
parent 162c742e76
commit db57e1682a
3 changed files with 416 additions and 290 deletions
@@ -309,6 +309,7 @@ const loadingBalanceRequest = async (req, res) => {
return res.status(200).json(result);
}
let partialTopup = false;
let totalReservation = 0;
let amountTopup = 0;
let reservationNumber = [];
@@ -321,14 +322,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 = {
@@ -374,6 +367,12 @@ const loadingBalanceRequest = async (req, res) => {
// get BI regulation status
const getBIRegulationStatus = await model.getBIRegulationStatus();
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
winston.logger.debug(`${uniqueCode} checking max balance on the card...`);
@@ -384,20 +383,73 @@ const loadingBalanceRequest = async (req, res) => {
parseInt(balance) + parseInt(amountTopup) >
parseInt(getMaxAmountOnTheCard.c_value)
) {
result = {
code: '416',
message: 'your card number has reached the maximum balance',
data: {},
};
// if topup partial is active
if (getTopupPartialStatus.c_value == 'A') {
// reset reservation data
partialTopup = true;
totalReservation = 0;
amountTopup = 0;
reservationNumber = [];
reservationNumberTemp = [];
i = 0;
// log warn
winston.logger.warn(
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
result
)}`
);
// 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++;
});
return res.status(200).json(result);
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 = {
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);
}
}
}
@@ -424,24 +476,85 @@ const loadingBalanceRequest = async (req, res) => {
parseInt(accumulatedBalance) + parseInt(amountTopup) >
parseInt(getMaxTopupPerMonth.c_value)
) {
result = {
code: '417',
message: 'your card number has been limit top up for this month',
data: {},
};
// if topup partial is active
if (getTopupPartialStatus.c_value == 'A') {
// reset reservation data
partialTopup = true;
totalReservation = 0;
amountTopup = 0;
reservationNumber = [];
reservationNumberTemp = [];
i = 0;
// log warn
winston.logger.warn(
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
result
)}`
);
// 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++;
});
return res.status(200).json(result);
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 = {
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
await model.updateStatusReservation(reservationNumberTemp, now);
result = {
code: '00',
message: 'reservation exists',
@@ -449,6 +562,7 @@ const loadingBalanceRequest = async (req, res) => {
amount: amountTopup,
total_reservation: totalReservation,
reservation_number: reservationNumber,
partial_topup: partialTopup,
},
};