change logic masximum reservation with pending status

This commit is contained in:
2022-09-12 18:55:11 +07:00
parent 0685387b46
commit 3b77dcbf3c
2 changed files with 11 additions and 8 deletions
@@ -337,7 +337,7 @@ const reservationValidate = async (req, res) => {
let getMaxReservation = await model.getMaxReservation();
let maxReservation = getMaxReservation.c_value
? parseInt(getMaxReservation.c_value)
: 1;
: 0;
// log debug
winston.logger.debug(`${uniqueCode} checking total reservation pending...`);
@@ -348,9 +348,10 @@ const reservationValidate = async (req, res) => {
now
);
let totalReservationPending =
getReservationPending.total_reservation > 0
? getReservationPending.total_reservation
: 0;
getReservationPending.total_nominal_reservation > 0
? parseInt(getReservationPending.total_nominal_reservation) +
parseInt(amount)
: parseInt(amount);
if (totalReservationPending >= maxReservation) {
result = {
@@ -603,7 +604,7 @@ const reservation = async (req, res) => {
let getMaxReservation = await model.getMaxReservation();
let maxReservation = getMaxReservation.c_value
? parseInt(getMaxReservation.c_value)
: 1;
: 0;
// // log debug
// winston.logger.debug(`${uniqueCode} checking reservation with flag...`);
@@ -642,9 +643,10 @@ const reservation = async (req, res) => {
now
);
let totalReservationPending =
getReservationPending.total_reservation > 0
? getReservationPending.total_reservation
: 0;
getReservationPending.total_nominal_reservation > 0
? parseInt(getReservationPending.total_nominal_reservation) +
parseInt(amount)
: parseInt(amount);
if (totalReservationPending >= maxReservation) {
result = {
@@ -180,6 +180,7 @@ let inquiryByCardNumber = (cardNumber, startDate, endDate) => {
const getReservationPending = (cardNumber, time) => {
let result = knex("trx.t_d_reservation_balance")
.count("* as total_reservation")
.sum("* as total_nominal_reservation")
.where("c_card_number", cardNumber)
.where("c_status", "P")
// .where("d_expired", ">=", time)