mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-05 10:56:27 +00:00
update
This commit is contained in:
@@ -11,7 +11,7 @@ const authenticateRefreshToken = (req, res, next) => {
|
||||
jwt.verify(req.header("refresh_token"), process.env.REFRESH_TOKEN_SECRET, (err, data) => {
|
||||
if (err) {
|
||||
return res.json({
|
||||
code: "01",
|
||||
code: "400",
|
||||
message: "Refresh Token is invalid. Please login!",
|
||||
data: {},
|
||||
});
|
||||
@@ -49,7 +49,7 @@ const authenticateToken = async (req, res, next) => {
|
||||
|
||||
if (!token) {
|
||||
return res.json({
|
||||
code: "01",
|
||||
code: "401",
|
||||
message: "Token is required",
|
||||
data: {},
|
||||
});
|
||||
@@ -58,7 +58,7 @@ const authenticateToken = async (req, res, next) => {
|
||||
await jwt.verify(token, process.env.TOKEN_SECRET, (err, data) => {
|
||||
if (err) {
|
||||
return res.json({
|
||||
code: "01",
|
||||
code: "402",
|
||||
message: "Invalid Token.",
|
||||
data: {},
|
||||
});
|
||||
@@ -72,7 +72,7 @@ const authenticateToken = async (req, res, next) => {
|
||||
});
|
||||
} else {
|
||||
return res.json({
|
||||
code: "01",
|
||||
code: "400",
|
||||
message: "Header not found",
|
||||
data: {},
|
||||
});
|
||||
|
||||
@@ -47,7 +47,7 @@ const login = async (req, res, next) => {
|
||||
const err = validationResult(req);
|
||||
if (!err.isEmpty()) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "400",
|
||||
message: err.errors[0].msg,
|
||||
data: {},
|
||||
});
|
||||
@@ -57,7 +57,7 @@ const login = async (req, res, next) => {
|
||||
let checkMidTid = await model.checkMidTid(mid, tid);
|
||||
if (!checkMidTid) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "403",
|
||||
message: "MID or TID is not registered.",
|
||||
data: {},
|
||||
});
|
||||
@@ -67,7 +67,7 @@ const login = async (req, res, next) => {
|
||||
let checkDataLogin = await model.checkDataLogin(mid, tid);
|
||||
if (!checkDataLogin) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "403",
|
||||
message: "Terminal Login already exists.",
|
||||
data: {},
|
||||
});
|
||||
@@ -80,7 +80,7 @@ const login = async (req, res, next) => {
|
||||
);
|
||||
if (!checkPassword) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "403",
|
||||
message: "Password is wrong.",
|
||||
data: {},
|
||||
});
|
||||
@@ -110,8 +110,8 @@ const login = async (req, res, next) => {
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
return res.status(500).json({
|
||||
code: "01",
|
||||
return res.status(200).json({
|
||||
code: "404",
|
||||
message: error.message,
|
||||
data: {},
|
||||
});
|
||||
@@ -127,7 +127,7 @@ const register = async (req, res) => {
|
||||
const err = validationResult(req);
|
||||
if (!err.isEmpty()) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "400",
|
||||
message: err.errors[0].msg,
|
||||
data: {},
|
||||
});
|
||||
@@ -137,7 +137,7 @@ const register = async (req, res) => {
|
||||
let checkMidTid = await model.checkMidTid(mid, tid);
|
||||
if (!checkMidTid) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "403",
|
||||
message: "MID or TID is not registered.",
|
||||
data: {},
|
||||
});
|
||||
@@ -147,7 +147,7 @@ const register = async (req, res) => {
|
||||
let checkDataLogin = await model.checkDataLogin(mid, tid);
|
||||
if (checkDataLogin) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "403",
|
||||
message: "Terminal Login already exists.",
|
||||
data: {},
|
||||
});
|
||||
@@ -175,14 +175,14 @@ const register = async (req, res) => {
|
||||
// insert data login
|
||||
let result = await model.insertDataLogin(data);
|
||||
|
||||
return res.status(201).json({
|
||||
return res.status(200).json({
|
||||
code: "00",
|
||||
message: "Data login saved successfully.",
|
||||
data: result.command,
|
||||
});
|
||||
} catch (error) {
|
||||
return res.status(500).json({
|
||||
code: "01",
|
||||
return res.status(200).json({
|
||||
code: "404",
|
||||
message: error.message,
|
||||
data: {},
|
||||
});
|
||||
@@ -199,7 +199,7 @@ const refreshToken = async (req, res) => {
|
||||
const err = validationResult(req);
|
||||
if (!err.isEmpty()) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "400",
|
||||
message: err.errors[0].msg,
|
||||
data: {},
|
||||
});
|
||||
@@ -215,7 +215,7 @@ const refreshToken = async (req, res) => {
|
||||
);
|
||||
if (!checkRefreshToken) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "400",
|
||||
message: "Refresh Token is invalid. Please try login",
|
||||
data: {},
|
||||
});
|
||||
@@ -245,8 +245,8 @@ const refreshToken = async (req, res) => {
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
return res.status(500).json({
|
||||
code: "01",
|
||||
return res.status(200).json({
|
||||
code: "404",
|
||||
message: error.message,
|
||||
data: {},
|
||||
});
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
const { param, body, validationResult } = require("express-validator");
|
||||
const model = require("./history.model");
|
||||
const moment = require("moment");
|
||||
moment.locale("id");
|
||||
|
||||
// VALIDATION
|
||||
const validate = (method) => {
|
||||
switch (method) {
|
||||
case "history":
|
||||
return [
|
||||
body("mid").not().isEmpty().withMessage("MID is required"),
|
||||
body("tid").not().isEmpty().withMessage("TID is required"),
|
||||
body("card_number")
|
||||
.not()
|
||||
.isEmpty()
|
||||
.withMessage("Card Number is required"),
|
||||
];
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
// HISTORY
|
||||
const history = async (req, res) => {
|
||||
try {
|
||||
// check validator
|
||||
const err = validationResult(req, res);
|
||||
if (!err.isEmpty()) {
|
||||
return res.status(200).json({
|
||||
code: "400",
|
||||
message: err.errors[0].msg,
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
// param
|
||||
let { mid, tid, card_number, start_date, end_date } = req.body;
|
||||
|
||||
// time
|
||||
let now = moment().format("YYYY-MM-DD HH:mm:ss");
|
||||
|
||||
// validation inquiry date
|
||||
if ((!start_date && end_date) || (start_date && !end_date)) {
|
||||
return res.status(200).json({
|
||||
code: "400",
|
||||
message: "bad request. please check the date!",
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
// get partner, merchant, terminal from tid
|
||||
let getPartner = await model.getPartner(mid, tid);
|
||||
if (!getPartner) {
|
||||
return res.status(200).json({
|
||||
code: "403",
|
||||
message: "terminal id is not valid",
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
// check reservation and load balance transaction
|
||||
let result = await model.historyByCardNumber(
|
||||
mid,
|
||||
tid,
|
||||
card_number,
|
||||
start_date,
|
||||
end_date
|
||||
);
|
||||
|
||||
if (!result) {
|
||||
return res.status(200).json({
|
||||
code: "403",
|
||||
message: "history doesn't exist",
|
||||
data: [],
|
||||
});
|
||||
}
|
||||
|
||||
return res.json({
|
||||
code: "00",
|
||||
message: "history has been found.",
|
||||
data: result,
|
||||
});
|
||||
} catch (error) {
|
||||
return res.status(200).json({
|
||||
code: "404",
|
||||
message: error.message,
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
validate,
|
||||
history,
|
||||
};
|
||||
@@ -0,0 +1,81 @@
|
||||
const knex = require("../../../infrastructure/database/knex");
|
||||
|
||||
// GET PARTNER, MERCHANT, TERMINAL FROM TID
|
||||
const getPartner = (mid, tid) => {
|
||||
let result = knex
|
||||
.select(
|
||||
"t_m_partner.i_partner",
|
||||
"t_m_partner.c_code as partner_code",
|
||||
"t_m_partner.c_name as partner_name",
|
||||
"t_m_merchant.i_merchant",
|
||||
"t_m_merchant.c_code as merchant_code",
|
||||
"t_m_merchant.c_name as merchant_name",
|
||||
"t_m_merchant.e_mid as mid",
|
||||
"t_m_terminal.i_terminal",
|
||||
"t_m_terminal.c_code as terminal_code",
|
||||
"t_m_terminal.c_name as terminal_name",
|
||||
"t_m_terminal.e_tid as tid"
|
||||
)
|
||||
.from("t_m_terminal")
|
||||
.leftJoin(
|
||||
"t_m_merchant",
|
||||
"t_m_terminal.i_merchant",
|
||||
"t_m_merchant.i_merchant"
|
||||
)
|
||||
.leftJoin("t_m_partner", "t_m_merchant.i_partner", "t_m_partner.i_partner")
|
||||
.where("t_m_merchant.e_mid", mid)
|
||||
.where("t_m_terminal.e_tid", tid)
|
||||
.where("t_m_terminal.c_status", "A")
|
||||
.where("t_m_merchant.c_status", "A")
|
||||
.where("t_m_partner.c_status", "A")
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// HISTORY BY CARD NUMBER
|
||||
let historyByCardNumber = (mid, tid, cardNumber, startDate, endDate) => {
|
||||
// let result = knex("trx.t_d_reservation_balance")
|
||||
// .select(
|
||||
// "'reservation' as transaction_type",
|
||||
// "trx.t_d_reservation_balance.c_reservation_no as unique_number",
|
||||
// "trx.t_d_reservation_balance.d_reservation as date",
|
||||
// "trx.t_d_reservation_balance.c_ref_no as ref_no",
|
||||
// "trx.t_d_reservation_balance.c_partner_name as partner_name",
|
||||
// "trx.t_d_reservation_balance.c_merchant_name as merchant_name",
|
||||
// "trx.t_d_reservation_balance.c_terminal_name as terminal_name",
|
||||
// "trx.t_d_reservation_balance.c_card_number as card_number",
|
||||
// "trx.t_d_reservation_balance.i_reservation_amount as amount",
|
||||
// "trx.t_d_reservation_balance.i_issuer_fee as issuer_fee",
|
||||
// "trx.t_d_reservation_balance.i_channel_fee as channel_fee",
|
||||
// "trx.t_d_reservation_balance.c_status as status_code",
|
||||
// "trx.t_d_reservation_balance.c_status_name as description"
|
||||
// )
|
||||
// .where("trx.t_d_reservation_balance.c_mid", mid)
|
||||
// .where("trx.t_d_reservation_balance.c_tid", tid)
|
||||
// .where("trx.t_d_reservation_balance.c_card_number", cardNumber)
|
||||
// .orderBy("trx.t_d_reservation_balance.d_reservation", "desc");
|
||||
|
||||
// if (startDate && endDate) {
|
||||
// result.whereRaw("??::date >= ?", ["trx.t_d_reservation_balance.d_reservation", startDate]);
|
||||
// result.whereRaw("??::date <= ?", ["trx.t_d_reservation_balance.d_reservation", endDate]);
|
||||
// }
|
||||
|
||||
let result = knex
|
||||
.select("*")
|
||||
.from(
|
||||
"(select trx.t_d_reservation_balance.c_reservation_no as unique_number, trx.t_d_reservation_balance.d_reservation as date, trx.t_d_reservation_balance.c_ref_no as ref_no, trx.t_d_reservation_balance.c_partner_name as partner_name, trx.t_d_reservation_balance.c_merchant_name as merchant_name, trx.t_d_reservation_balance.c_terminal_name as terminal_name, trx.t_d_reservation_balance.c_card_number as card_number, trx.t_d_reservation_balance.i_reservation_amount as amount, trx.t_d_reservation_balance.i_issuer_fee as issuer_fee, trx.t_d_reservation_balance.i_channel_fee as channel_fee, trx.t_d_reservation_balance.c_status as status_code, trx.t_d_reservation_balance.c_status_name as description from trx.t_d_reservation_balance where trx.t_d_reservation_balance.c_mid = '?' and trx.t_d_reservation_balance.c_tid = '?' and trx.t_d_reservation_balance.c_card_number = '?' union all select trx.t_d_load_balance.c_load_balance_no as unique_number, trx.t_d_load_balance.d_load_balance as load_date, trx.t_d_load_balance.c_ref_no as ref_no, trx.t_d_load_balance.c_partner_name as partner_name, trx.t_d_load_balance.c_merchant_name as merchant_name, trx.t_d_load_balance.c_terminal_name as terminal_name, trx.t_d_load_balance.c_card_number as card_number, trx.t_d_load_balance.i_topup_amount as amount, trx.t_d_load_balance_detail.i_issuer_fee as issuer_fee, trx.t_d_load_balance_detail.i_channel_fee as channel_fee, trx.t_d_load_balance.c_status as status_code, trx.t_d_load_balance.c_status_name as description from trx.t_d_load_balance left join trx.t_d_load_balance_detail on trx.t_d_load_balance_detail.i_load_balance = trx.t_d_load_balance.i_load_balance where trx.t_d_load_balance.c_mid = '?' and trx.t_d_load_balance.c_tid = '?' and trx.t_d_load_balance.c_card_number = '?')",
|
||||
mid,
|
||||
tid,
|
||||
cardNumber,
|
||||
mid,
|
||||
tid,
|
||||
cardNumber
|
||||
);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getPartner,
|
||||
historyByCardNumber,
|
||||
};
|
||||
@@ -10,6 +10,8 @@ const validate = (method) => {
|
||||
return [
|
||||
body("mid").not().isEmpty().withMessage("MID is required"),
|
||||
body("tid").not().isEmpty().withMessage("TID is required"),
|
||||
body("uid").not().isEmpty().withMessage("UID is required"),
|
||||
body("flag").not().isEmpty().withMessage("Flag is required"),
|
||||
body("card_number")
|
||||
.not()
|
||||
.isEmpty()
|
||||
@@ -19,6 +21,8 @@ const validate = (method) => {
|
||||
return [
|
||||
body("mid").not().isEmpty().withMessage("MID is required"),
|
||||
body("tid").not().isEmpty().withMessage("TID is required"),
|
||||
body("uid").not().isEmpty().withMessage("UID is required"),
|
||||
body("flag").not().isEmpty().withMessage("Flag is required"),
|
||||
body("card_number")
|
||||
.not()
|
||||
.isEmpty()
|
||||
@@ -48,14 +52,14 @@ const loadingBalanceRequest = async (req, res) => {
|
||||
const err = validationResult(req, res);
|
||||
if (!err.isEmpty()) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "400",
|
||||
message: err.errors[0].msg,
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
// param
|
||||
let { mid, tid, card_number } = req.body;
|
||||
let { mid, tid, card_number, uid, balance, flag } = req.body;
|
||||
|
||||
// time
|
||||
let now = moment().format("YYYY-MM-DD HH:mm:ss");
|
||||
@@ -64,7 +68,7 @@ const loadingBalanceRequest = async (req, res) => {
|
||||
let getPartner = await model.getPartner(mid, tid);
|
||||
if (!getPartner) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "403",
|
||||
message: "terminal id is not valid",
|
||||
data: {},
|
||||
});
|
||||
@@ -74,12 +78,36 @@ const loadingBalanceRequest = async (req, res) => {
|
||||
let checkCardNumber = await model.checkCardNumber(card_number);
|
||||
if (!checkCardNumber) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "403",
|
||||
message: "card number is not registered",
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
// check last flag
|
||||
let checkFlag = await model.checkFlag(card_number, uid);
|
||||
let lastFlag = null;
|
||||
if (checkFlag) {
|
||||
lastFlag = checkFlag.c_flag;
|
||||
}
|
||||
|
||||
// get total reservation pending
|
||||
let getReservationPendingWithFlag = await model.getReservationPendingWithFlag(
|
||||
card_number,
|
||||
now
|
||||
);
|
||||
if (getReservationPendingWithFlag) {
|
||||
if (lastFlag != flag) {
|
||||
// update
|
||||
await updateReservationAndLoadingBalance(getReservationPendingWithFlag.c_reservation_no, mid, tid);
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
message: "your card number has been cleared successfully",
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// get total reservation pending
|
||||
let getReservationPending = await model.getReservationPending(
|
||||
card_number,
|
||||
@@ -88,23 +116,57 @@ const loadingBalanceRequest = async (req, res) => {
|
||||
|
||||
if (getReservationPending.length < 1) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "403",
|
||||
message: "reservation doesn't exist",
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
let totalReservation = getReservationPending.length;
|
||||
let totalReservation = 0;
|
||||
let amountTopup = 0;
|
||||
let reservationNumber = [];
|
||||
let i = 0;
|
||||
getReservationPending.forEach((rsv) => {
|
||||
amountTopup += parseInt(rsv.i_reservation_amount);
|
||||
reservationNumber.push(rsv.c_reservation_no);
|
||||
if (rsv.c_flag) {
|
||||
if (lastFlag == flag) {
|
||||
amountTopup += parseInt(rsv.i_reservation_amount);
|
||||
reservationNumber.push(rsv.c_reservation_no);
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
amountTopup += parseInt(rsv.i_reservation_amount);
|
||||
reservationNumber.push(rsv.c_reservation_no);
|
||||
i++;
|
||||
}
|
||||
});
|
||||
|
||||
totalReservation = i;
|
||||
if (totalReservation == 0) {
|
||||
return res.status(200).json({
|
||||
code: "403",
|
||||
message: "reservation doesn't exist",
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
// get BI regulation status
|
||||
const getBIRegulationStatus = await model.getBIRegulationStatus();
|
||||
if (getBIRegulationStatus.c_value == "A") {
|
||||
// get max saldo on the card
|
||||
const getMaxAmountOnTheCard = await model.getMaxAmountOnTheCard();
|
||||
if (getMaxAmountOnTheCard.c_value) {
|
||||
if (
|
||||
parseInt(balance) + parseInt(amountTopup) >
|
||||
parseInt(getMaxAmountOnTheCard.c_value)
|
||||
) {
|
||||
return res.status(200).json({
|
||||
code: "403",
|
||||
message: "your card number has reached the maximum balance",
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// get accumulated balance in this month
|
||||
let accumulatedBalance = 19900000;
|
||||
|
||||
@@ -116,7 +178,7 @@ const loadingBalanceRequest = async (req, res) => {
|
||||
parseInt(getMaxTopupPerMonth.c_value)
|
||||
) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "403",
|
||||
message: "your card number has been limit top up for this month",
|
||||
data: {},
|
||||
});
|
||||
@@ -136,14 +198,109 @@ const loadingBalanceRequest = async (req, res) => {
|
||||
data: result,
|
||||
});
|
||||
} catch (error) {
|
||||
return res.status(500).json({
|
||||
code: "01",
|
||||
return res.status(200).json({
|
||||
code: "404",
|
||||
message: error.message,
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const updateReservationAndLoadingBalance = async (reservationNumber, mid, tid) => {
|
||||
// get reservation
|
||||
let dataReservation = [];
|
||||
let getLastReservationFlag = await model.getLastReservationFlag(
|
||||
reservationNumber
|
||||
);
|
||||
if (getLastReservationFlag) {
|
||||
dataReservation = getLastReservationFlag;
|
||||
}
|
||||
|
||||
// get load balance
|
||||
let dataLoadingBalance = [];
|
||||
let getLastLoadingBalanceFlag = await model.getLastLoadingBalanceFlag(
|
||||
reservationNumber
|
||||
);
|
||||
if (getLastLoadingBalanceFlag) {
|
||||
dataLoadingBalance = getLastLoadingBalanceFlag;
|
||||
}
|
||||
|
||||
// get detail load balance
|
||||
let dataLoadingBalanceDetail = [];
|
||||
let getLastLoadingBalanceDetailFlag =
|
||||
await model.getLastLoadingBalanceDetailFlag(dataLoadingBalance.i_load_balance);
|
||||
if (getLastLoadingBalanceDetailFlag) {
|
||||
dataLoadingBalanceDetail = getLastLoadingBalanceDetailFlag;
|
||||
}
|
||||
|
||||
if (dataReservation && dataLoadingBalance && dataLoadingBalanceDetail) {
|
||||
|
||||
// time
|
||||
let now = moment().format("YYYY-MM-DD HH:mm:ss");
|
||||
let today = moment().format("YYYY-MM-DD");
|
||||
let getPartner = await model.getPartner(mid, tid);
|
||||
|
||||
// get loading balance
|
||||
const getLoadBalanceSequence = await model.getLoadBalanceSequence(
|
||||
getPartner,
|
||||
today
|
||||
);
|
||||
const loadBalanceNoSequence = getLoadBalanceSequence
|
||||
? parseInt(getLoadBalanceSequence.i_load_balance_no_seq) + 1
|
||||
: 1;
|
||||
|
||||
// generate load balance number
|
||||
let loadBalanceNumber = await model.generateLoadBalanceNumber(
|
||||
getPartner,
|
||||
moment(today).format("YYYYMMDD"),
|
||||
loadBalanceNoSequence
|
||||
);
|
||||
|
||||
let data = {
|
||||
c_load_balance_no: loadBalanceNumber,
|
||||
d_load_balance: now,
|
||||
c_ref_no: dataReservation.c_ref_no,
|
||||
i_partner: getPartner ? getPartner.i_partner : null,
|
||||
c_partner_code: getPartner ? getPartner.partner_code : null,
|
||||
c_partner_name: getPartner ? getPartner.partner_name : null,
|
||||
i_merchant: getPartner ? getPartner.i_merchant : null,
|
||||
c_merchant_code: getPartner ? getPartner.merchant_code : null,
|
||||
c_merchant_name: getPartner ? getPartner.merchant_name : null,
|
||||
c_mid: getPartner ? getPartner.mid : null,
|
||||
i_terminal: getPartner ? getPartner.i_terminal : null,
|
||||
c_terminal_code: getPartner ? getPartner.terminal_code : null,
|
||||
c_terminal_name: getPartner ? getPartner.terminal_name : null,
|
||||
c_tid: getPartner ? getPartner.tid : null,
|
||||
c_card_number: dataReservation.c_card_number,
|
||||
i_topup_amount: dataReservation.i_reservation_amount,
|
||||
c_return_sap: null,
|
||||
i_load_balance_no_seq: loadBalanceNoSequence,
|
||||
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,
|
||||
};
|
||||
|
||||
// insert reservation and load balance transaction
|
||||
await model.insertReservationAndLoadingBalance(
|
||||
reservationNumber,
|
||||
data,
|
||||
dataLoadingBalanceDetail,
|
||||
now
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
// LOAD BALANCE
|
||||
const loadingBalance = async (req, res) => {
|
||||
try {
|
||||
@@ -151,15 +308,25 @@ const loadingBalance = async (req, res) => {
|
||||
const err = validationResult(req, res);
|
||||
if (!err.isEmpty()) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "400",
|
||||
message: err.errors[0].msg,
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
// param
|
||||
let { mid, tid, card_number, amount, reservation_number, ref_no } =
|
||||
req.body;
|
||||
let {
|
||||
mid,
|
||||
tid,
|
||||
card_number,
|
||||
amount,
|
||||
reservation_number,
|
||||
ref_no,
|
||||
write_status,
|
||||
uid,
|
||||
balance,
|
||||
flag,
|
||||
} = req.body;
|
||||
|
||||
// time
|
||||
let now = moment().format("YYYY-MM-DD HH:mm:ss");
|
||||
@@ -169,7 +336,7 @@ const loadingBalance = async (req, res) => {
|
||||
let getPartner = await model.getPartner(mid, tid);
|
||||
if (!getPartner) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "403",
|
||||
message: "terminal id is not valid",
|
||||
data: {},
|
||||
});
|
||||
@@ -183,7 +350,7 @@ const loadingBalance = async (req, res) => {
|
||||
|
||||
if (!reservationStatus) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "403",
|
||||
message: "reservation number doesn't exist",
|
||||
data: {},
|
||||
});
|
||||
@@ -197,7 +364,9 @@ const loadingBalance = async (req, res) => {
|
||||
let loadDate = reservationLoaded.d_load_balance;
|
||||
return res.status(200).json({
|
||||
code: "00",
|
||||
message: "reservation has been successfully loaded on " + moment(loadDate).format("DD MMM YYYY HH:mm:ss"),
|
||||
message:
|
||||
"reservation has been successfully loaded on " +
|
||||
moment(loadDate).format("DD MMM YYYY HH:mm:ss"),
|
||||
data: {
|
||||
load_balance_number: loadBalanceNumberExisting,
|
||||
},
|
||||
@@ -213,7 +382,7 @@ const loadingBalance = async (req, res) => {
|
||||
|
||||
if (getReservationPending.length < 1) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "403",
|
||||
message: "reservation doesn't exist",
|
||||
data: {},
|
||||
});
|
||||
@@ -227,7 +396,7 @@ const loadingBalance = async (req, res) => {
|
||||
|
||||
if (amount != amountTopup) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "403",
|
||||
message: "topup amount is different",
|
||||
data: {},
|
||||
});
|
||||
@@ -268,8 +437,8 @@ const loadingBalance = async (req, res) => {
|
||||
i_topup_amount: amount,
|
||||
c_return_sap: null,
|
||||
i_load_balance_no_seq: loadBalanceNoSequence,
|
||||
c_status: "A",
|
||||
c_status_name: "SUCCESS",
|
||||
c_status: write_status ? "F" : "A",
|
||||
c_status_name: write_status ? "FAILED" : "SUCCESS",
|
||||
d_create: now,
|
||||
i_create: null,
|
||||
c_create_username: null,
|
||||
@@ -286,6 +455,15 @@ const loadingBalance = async (req, res) => {
|
||||
|
||||
let detail = [];
|
||||
for (let index = 0; index < reservation_number.length; index++) {
|
||||
let reservation = await model.findReservation(reservation_number[index]);
|
||||
|
||||
if (!reservation) {
|
||||
return res.status(200).json({
|
||||
code: "403",
|
||||
message: "reservation number doesn't exist",
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
detail.push({
|
||||
i_reservation_balance: reservation.i_reservation_balance
|
||||
? reservation.i_reservation_balance
|
||||
@@ -323,18 +501,30 @@ const loadingBalance = async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
await model.insertLoadingBalance(data, detail, reservation_number, now);
|
||||
await model.insertLoadingBalance(
|
||||
data,
|
||||
detail,
|
||||
reservation_number,
|
||||
now,
|
||||
write_status,
|
||||
card_number,
|
||||
uid,
|
||||
balance,
|
||||
flag
|
||||
);
|
||||
|
||||
return res.status(201).json({
|
||||
return res.status(200).json({
|
||||
code: "00",
|
||||
message: "balance loaded successfully",
|
||||
message: write_status
|
||||
? "transaction saved successfully. Err: failed write to the card"
|
||||
: "balance loaded successfully",
|
||||
data: {
|
||||
load_balance_number: loadBalanceNumber,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
return res.status(500).json({
|
||||
code: "01",
|
||||
return res.status(200).json({
|
||||
code: "404",
|
||||
message: error.message,
|
||||
data: {},
|
||||
});
|
||||
@@ -353,7 +543,7 @@ const inquiryLoadingBalance = async (req, res) => {
|
||||
// validation parameter inquiry
|
||||
if (!load_balance_number && !card_number) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "400",
|
||||
message:
|
||||
"bad request. please add the load balance number or card number!",
|
||||
data: {},
|
||||
@@ -363,7 +553,7 @@ const inquiryLoadingBalance = async (req, res) => {
|
||||
// validation inquiry date
|
||||
if ((!start_date && end_date) || (start_date && !end_date)) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "400",
|
||||
message: "bad request. please check the date!",
|
||||
data: {},
|
||||
});
|
||||
@@ -377,7 +567,7 @@ const inquiryLoadingBalance = async (req, res) => {
|
||||
|
||||
if (!byLoadBalanceNumber) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "403",
|
||||
message: "load balance doesn't exist",
|
||||
data: [],
|
||||
});
|
||||
@@ -397,7 +587,7 @@ const inquiryLoadingBalance = async (req, res) => {
|
||||
|
||||
if (!byCardNumber) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "403",
|
||||
message: "load balance doesn't exist",
|
||||
data: {},
|
||||
});
|
||||
@@ -410,8 +600,8 @@ const inquiryLoadingBalance = async (req, res) => {
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
return res.status(500).json({
|
||||
code: "01",
|
||||
return res.status(200).json({
|
||||
code: "404",
|
||||
message: error.message,
|
||||
data: {},
|
||||
});
|
||||
|
||||
@@ -56,13 +56,26 @@ const getReservationPending = (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")
|
||||
.select("i_reservation_amount", "c_reservation_no", "c_flag")
|
||||
.where("c_card_number", cardNumber)
|
||||
.where("c_status", "P")
|
||||
.where("d_expired", ">=", time);
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET RESERVATION PENDING WITH FLAG
|
||||
const getReservationPendingWithFlag = (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)
|
||||
.where("c_status", "P")
|
||||
.whereNotNull("c_flag")
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET BI REGULATION STATUS FROM GLOBAL PARAMETER
|
||||
const getBIRegulationStatus = () => {
|
||||
let result = knex("t_m_global_parameter")
|
||||
@@ -73,6 +86,16 @@ const getBIRegulationStatus = () => {
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET MAX AMOUNT ON THE CARD FROM GLOBAL PARAMETER
|
||||
const getMaxAmountOnTheCard = () => {
|
||||
let result = knex("t_m_global_parameter")
|
||||
.select("c_value")
|
||||
.where("c_code", "HSM_BI_MAX_AMOUNT_ON_THE_CARD")
|
||||
.where("c_status", "A")
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET MAX TOPUP PER MONTH FROM GLOBAL PARAMETER
|
||||
const getMaxTopupPerMonth = () => {
|
||||
let result = knex("t_m_global_parameter")
|
||||
@@ -151,7 +174,17 @@ const findReservation = (reservationNumber) => {
|
||||
};
|
||||
|
||||
// INSERT LOADING BALANCE
|
||||
const insertLoadingBalance = async (data, detail, reservationNumber, now) => {
|
||||
const insertLoadingBalance = async (
|
||||
data,
|
||||
detail,
|
||||
reservationNumber,
|
||||
now,
|
||||
writeStatus,
|
||||
cardNumber,
|
||||
uid,
|
||||
balance,
|
||||
flag
|
||||
) => {
|
||||
await knex
|
||||
.transaction((trx) => {
|
||||
knex("trx.t_d_load_balance")
|
||||
@@ -167,6 +200,10 @@ const insertLoadingBalance = async (data, detail, reservationNumber, now) => {
|
||||
i_reservation_balance: element.i_reservation_balance,
|
||||
c_reservation_no: element.c_reservation_no,
|
||||
i_amount: element.i_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,
|
||||
@@ -180,13 +217,13 @@ const insertLoadingBalance = async (data, detail, reservationNumber, now) => {
|
||||
.insert(loadDetail);
|
||||
})
|
||||
.then(() => {
|
||||
console.log("UPDATE RESERVATION");
|
||||
// update reservation
|
||||
return knex("trx.t_d_reservation_balance")
|
||||
.transacting(trx)
|
||||
.update({
|
||||
c_status: "A",
|
||||
c_status_name: "LOADED",
|
||||
c_flag: writeStatus ? "FW" : null,
|
||||
c_status: writeStatus ? "P" : "A",
|
||||
c_status_name: writeStatus ? "PENDING" : "LOADED",
|
||||
d_modify: now,
|
||||
i_modify: null,
|
||||
c_modify_username: null,
|
||||
@@ -194,6 +231,24 @@ const insertLoadingBalance = async (data, detail, reservationNumber, now) => {
|
||||
})
|
||||
.whereIn("c_reservation_no", reservationNumber);
|
||||
})
|
||||
.then(() => {
|
||||
// delete flag counting
|
||||
return knex("trx.t_d_flag_counting")
|
||||
.transacting(trx)
|
||||
.where("c_card_number", cardNumber)
|
||||
.where("c_uid", uid)
|
||||
.del();
|
||||
})
|
||||
.then(() => {
|
||||
// insert flag counting
|
||||
return knex("trx.t_d_flag_counting").transacting(trx).insert({
|
||||
d_request: now,
|
||||
c_card_number: cardNumber,
|
||||
c_uid: uid,
|
||||
i_balance: balance,
|
||||
c_flag: flag,
|
||||
});
|
||||
})
|
||||
.then(trx.commit)
|
||||
.catch(trx.rollback);
|
||||
})
|
||||
@@ -231,12 +286,123 @@ const generateLoadBalanceNumber = (data, date, counter) => {
|
||||
return loadBalanceNumber;
|
||||
};
|
||||
|
||||
// CHECK FLAG
|
||||
const checkFlag = (cardNumber, uid) => {
|
||||
let result = knex("trx.t_d_flag_counting")
|
||||
.where("c_card_number", cardNumber)
|
||||
.where("c_uid", uid)
|
||||
.orderBy("d_request", "desc")
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// INSERT RESERVATION AND LOADING BALANCE CASE FAILED WRITE BEFORE
|
||||
const insertReservationAndLoadingBalance = async (
|
||||
reservationNumber,
|
||||
data,
|
||||
detail,
|
||||
now
|
||||
) => {
|
||||
await knex
|
||||
.transaction((trx) => {
|
||||
knex("trx.t_d_load_balance")
|
||||
.transacting(trx)
|
||||
.insert(data)
|
||||
.returning("i_load_balance")
|
||||
.then((resp) => {
|
||||
let id = resp[0];
|
||||
let loadDetail = [];
|
||||
detail.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_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({
|
||||
c_flag: null,
|
||||
c_status: "A",
|
||||
c_status_name: "LOADED",
|
||||
d_modify: now,
|
||||
i_modify: null,
|
||||
c_modify_username: null,
|
||||
c_modify_fullname: null,
|
||||
})
|
||||
.where("c_reservation_no", reservationNumber);
|
||||
})
|
||||
.then(trx.commit)
|
||||
.catch(trx.rollback);
|
||||
})
|
||||
.then((result) => {
|
||||
// console.log(result);
|
||||
return result;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error.message);
|
||||
return error.message;
|
||||
});
|
||||
};
|
||||
|
||||
//
|
||||
const getLastReservationFlag = (reservationNumber) => {
|
||||
let result = knex("trx.t_d_reservation_balance")
|
||||
.where("c_reservation_no", reservationNumber)
|
||||
.whereNotNull("c_flag")
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
//
|
||||
const getLastLoadingBalanceFlag = (reservationNumber) => {
|
||||
let result = knex("trx.t_d_load_balance")
|
||||
.select("trx.t_d_load_balance.*")
|
||||
.leftJoin(
|
||||
"trx.t_d_load_balance_detail",
|
||||
"trx.t_d_load_balance_detail.i_load_balance",
|
||||
"trx.t_d_load_balance.i_load_balance"
|
||||
)
|
||||
.where("trx.t_d_load_balance_detail.c_reservation_no", reservationNumber)
|
||||
.where("trx.t_d_load_balance.c_status", "F")
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
//
|
||||
const getLastLoadingBalanceDetailFlag = (loadBalanceId) => {
|
||||
let result = knex("trx.t_d_load_balance_detail").where(
|
||||
"i_load_balance",
|
||||
loadBalanceId
|
||||
);
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
checkCardNumber,
|
||||
getPartner,
|
||||
getIssuer,
|
||||
getReservationPending,
|
||||
getReservationPendingWithFlag,
|
||||
getBIRegulationStatus,
|
||||
getMaxAmountOnTheCard,
|
||||
getMaxTopupPerMonth,
|
||||
findReservationLoaded,
|
||||
findReservation,
|
||||
@@ -245,4 +411,9 @@ module.exports = {
|
||||
generateLoadBalanceNumber,
|
||||
inquiryByLoadBalanceNumber,
|
||||
inquiryByCardNumber,
|
||||
checkFlag,
|
||||
insertReservationAndLoadingBalance,
|
||||
getLastReservationFlag,
|
||||
getLastLoadingBalanceFlag,
|
||||
getLastLoadingBalanceDetailFlag,
|
||||
};
|
||||
|
||||
@@ -34,7 +34,7 @@ const reservation = async (req, res) => {
|
||||
const err = validationResult(req, res);
|
||||
if (!err.isEmpty()) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "400",
|
||||
message: err.errors[0].msg,
|
||||
data: {},
|
||||
});
|
||||
@@ -51,7 +51,7 @@ const reservation = async (req, res) => {
|
||||
let getPartner = await model.getPartner(mid, tid);
|
||||
if (!getPartner) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "403",
|
||||
message: "terminal id is not valid",
|
||||
data: {},
|
||||
});
|
||||
@@ -61,7 +61,7 @@ const reservation = async (req, res) => {
|
||||
let checkCardNumber = await model.checkCardNumber(card_number);
|
||||
if (!checkCardNumber) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "403",
|
||||
message: "card number is not registered",
|
||||
data: {},
|
||||
});
|
||||
@@ -70,6 +70,24 @@ const reservation = async (req, res) => {
|
||||
// get BI regulation status
|
||||
const getBIRegulationStatus = await model.getBIRegulationStatus();
|
||||
if (getBIRegulationStatus.c_value == "A") {
|
||||
// get last balance on the card
|
||||
let balance = 1950000;
|
||||
|
||||
// get max saldo on the card
|
||||
const getMaxAmountOnTheCard = await model.getMaxAmountOnTheCard();
|
||||
if (getMaxAmountOnTheCard.c_value) {
|
||||
if (
|
||||
parseInt(balance) + parseInt(amount) >
|
||||
parseInt(getMaxAmountOnTheCard.c_value)
|
||||
) {
|
||||
return res.status(200).json({
|
||||
code: "403",
|
||||
message: "your card number has reached the maximum balance",
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// get accumulated balance in this month
|
||||
let accumulatedBalance = 19950000;
|
||||
|
||||
@@ -81,7 +99,7 @@ const reservation = async (req, res) => {
|
||||
parseInt(getMaxTopupPerMonth.c_value)
|
||||
) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "403",
|
||||
message: "your card number has been limit top up for this month",
|
||||
data: {},
|
||||
});
|
||||
@@ -95,6 +113,24 @@ const reservation = async (req, res) => {
|
||||
? getMaxReservation.c_value
|
||||
: 1;
|
||||
|
||||
// get reservation with flag
|
||||
let reservationWithFlag = await model.getReservationWithFlag(
|
||||
card_number,
|
||||
now
|
||||
);
|
||||
let totalReservationWithFlag =
|
||||
reservationWithFlag.total_reservation > 0
|
||||
? reservationWithFlag.total_reservation
|
||||
: 0;
|
||||
if (totalReservationWithFlag > 0) {
|
||||
return res.status(200).json({
|
||||
code: "403",
|
||||
message:
|
||||
"your card number has incomplete transaction. Please unload your balance!",
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
// get total reservation pending
|
||||
let getReservationPending = await model.getReservationPending(
|
||||
card_number,
|
||||
@@ -107,7 +143,7 @@ const reservation = async (req, res) => {
|
||||
|
||||
if (totalReservationPending >= maxReservation) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "403",
|
||||
message:
|
||||
"your card number has some pending transaction. Please finished it!",
|
||||
data: {},
|
||||
@@ -124,7 +160,7 @@ const reservation = async (req, res) => {
|
||||
}
|
||||
// if (!getIssuer) {
|
||||
// return res.status(200).json({
|
||||
// code: "01",
|
||||
// code: "403",
|
||||
// message: "issuer doesn't exist",
|
||||
// data: {},
|
||||
// });
|
||||
@@ -207,7 +243,7 @@ const reservation = async (req, res) => {
|
||||
|
||||
await model.insertReservation(data);
|
||||
|
||||
return res.status(201).json({
|
||||
return res.status(200).json({
|
||||
code: "00",
|
||||
message: "reservation saved successfully.",
|
||||
data: {
|
||||
@@ -215,8 +251,8 @@ const reservation = async (req, res) => {
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
return res.status(500).json({
|
||||
code: "01",
|
||||
return res.status(200).json({
|
||||
code: "404",
|
||||
message: error.message,
|
||||
data: {},
|
||||
});
|
||||
@@ -235,7 +271,7 @@ const inquiryReservation = async (req, res) => {
|
||||
// validation parameter inquiry
|
||||
if (!reservation_number && !card_number) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "403",
|
||||
message:
|
||||
"bad request. please add the reservation number or card number!",
|
||||
data: {},
|
||||
@@ -245,7 +281,7 @@ const inquiryReservation = async (req, res) => {
|
||||
// validation inquiry date
|
||||
if ((!start_date && end_date) || (start_date && !end_date)) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "403",
|
||||
message: "bad request. please check the date!",
|
||||
data: {},
|
||||
});
|
||||
@@ -259,7 +295,7 @@ const inquiryReservation = async (req, res) => {
|
||||
|
||||
if (!byReservationNumber) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "403",
|
||||
message: "reservation doesn't exist",
|
||||
data: {},
|
||||
});
|
||||
@@ -279,7 +315,7 @@ const inquiryReservation = async (req, res) => {
|
||||
|
||||
if (!byCardNumber) {
|
||||
return res.status(200).json({
|
||||
code: "01",
|
||||
code: "403",
|
||||
message: "reservation doesn't exist",
|
||||
data: [],
|
||||
});
|
||||
@@ -292,8 +328,8 @@ const inquiryReservation = async (req, res) => {
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
return res.status(500).json({
|
||||
code: "01",
|
||||
return res.status(200).json({
|
||||
code: "404",
|
||||
message: error.message,
|
||||
data: {},
|
||||
});
|
||||
|
||||
@@ -105,6 +105,16 @@ const getBIRegulationStatus = () => {
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET MAX AMOUNT ON THE CARD FROM GLOBAL PARAMETER
|
||||
const getMaxAmountOnTheCard = () => {
|
||||
let result = knex("t_m_global_parameter")
|
||||
.select("c_value")
|
||||
.where("c_code", "HSM_BI_MAX_AMOUNT_ON_THE_CARD")
|
||||
.where("c_status", "A")
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET MAX TOPUP PER MONTH FROM GLOBAL PARAMETER
|
||||
const getMaxTopupPerMonth = () => {
|
||||
let result = knex("t_m_global_parameter")
|
||||
@@ -184,6 +194,18 @@ const getReservationPending = (cardNumber, time) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET RESERVATION WITH FLAG
|
||||
const getReservationWithFlag = (cardNumber, time) => {
|
||||
let result = knex("trx.t_d_reservation_balance")
|
||||
.count("* as total_reservation")
|
||||
.where("c_card_number", cardNumber)
|
||||
.where("c_status", "P")
|
||||
.where("d_expired", ">=", time)
|
||||
.whereNotNull("c_flag")
|
||||
.first();
|
||||
return result;
|
||||
};
|
||||
|
||||
// INSERT RESERVATION
|
||||
const insertReservation = (data) => {
|
||||
let result = knex("trx.t_d_reservation_balance").insert(data);
|
||||
@@ -199,10 +221,12 @@ module.exports = {
|
||||
getReservationExpirationDateValue,
|
||||
getReservationExpirationDateMeasure,
|
||||
getBIRegulationStatus,
|
||||
getMaxAmountOnTheCard,
|
||||
getMaxTopupPerMonth,
|
||||
getMaxReservation,
|
||||
inquiryByReservationNumber,
|
||||
inquiryByCardNumber,
|
||||
getReservationPending,
|
||||
getReservationWithFlag,
|
||||
insertReservation,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
const express = require("express");
|
||||
const router = express.Router();
|
||||
const auth = require("../middlewares/jwt.middleware");
|
||||
const controller = require("../modules/history/history.controller");
|
||||
|
||||
router.post(
|
||||
"/history",
|
||||
auth.authenticateToken,
|
||||
controller.validate("history"),
|
||||
controller.history
|
||||
);
|
||||
|
||||
module.exports = router;
|
||||
@@ -6,6 +6,7 @@ const reservationRoute = require("./application/routes/reservebalance.routes");
|
||||
const loadBalanceRoute = require("./application/routes/loadbalance.routes");
|
||||
const helper = require("./application/helpers/helper");
|
||||
const hsmRoute = require("./application/routes/hsm")
|
||||
const historyRoute = require("./application/routes/history.routes")
|
||||
|
||||
require("dotenv").config();
|
||||
|
||||
@@ -29,9 +30,10 @@ app.get("/", (req, res) => {
|
||||
});
|
||||
|
||||
app.use("/api/", authRoute);
|
||||
app.use("/api/", reservationRoute);
|
||||
app.use("/api/", loadBalanceRoute);
|
||||
app.use("/api/", historyRoute);
|
||||
app.use("/api/", hsmRoute);
|
||||
app.use("/api/", loadBalanceRoute);
|
||||
app.use("/api/", reservationRoute);
|
||||
|
||||
// set port, listen for requests
|
||||
const PORT = process.env.PORT || 8000;
|
||||
|
||||
Reference in New Issue
Block a user