This commit is contained in:
2022-05-30 17:09:29 +07:00
parent 53d273ef17
commit bdcfbb002a
10 changed files with 120 additions and 118 deletions
+3 -3
View File
@@ -44,7 +44,7 @@ const controller = async (req, res) => {
if (_timeOut) {
return res.status(200).send({
status: "99",
code: "99",
message: "Timeout",
data: {}
})
@@ -58,7 +58,7 @@ const controller = async (req, res) => {
respData1 = generate.getResponseData(respData);
return res.status(200).send({
status: "00",
code: "00",
message: "Request Authenticate 1 Success",
data: {
trxID: generate.buf2hex(transactionId),
@@ -70,7 +70,7 @@ const controller = async (req, res) => {
} catch (error) {
return res.status(200).send({
status: "404",
code: "404",
message: error.message,
data: {}
})
+3 -3
View File
@@ -12,7 +12,7 @@ const controller = async (req, res) => {
if (auth2v2requestData[0] != 0x41) {
return res.status(200).send({
status: "403",
code: "403",
message: "Wrong Respone from Card",
data: {}
})
@@ -46,7 +46,7 @@ const controller = async (req, res) => {
respData1 = generate.getResponseData(respData);
return res.status(200).send({
status: "00",
code: "00",
message: "Request Authenticate 2 Success",
data: {
trxID: generate.buf2hex(transactionId),
@@ -58,7 +58,7 @@ const controller = async (req, res) => {
} catch (error) {
return res.status(200).send({
status: "404",
code: "404",
message: error.message,
data: {}
})
+3 -3
View File
@@ -12,7 +12,7 @@ const controller = async (req, res) => {
if (auth2v2responseSetData[0] != 0x43) {
return res.status(200).send({
status: "403",
code: "403",
message: "Wrong Respone from Card",
data: {}
})
@@ -47,7 +47,7 @@ const controller = async (req, res) => {
respData1 = generate.getResponseData(respData);
return res.status(200).send({
status: "00",
code: "00",
message: "Request Authenticate Resp Success",
data: {
trxID: generate.buf2hex(transactionId),
@@ -59,7 +59,7 @@ const controller = async (req, res) => {
} catch (error) {
return res.status(200).send({
status: "404",
code: "404",
message: error.message,
data: {}
})
+2 -2
View File
@@ -39,7 +39,7 @@ const controller = async (req, res) => {
respData1 = generate.getResponseData(respData);
return res.status(200).send({
status: "00",
code: "00",
message: "End Transaction Success",
data: {
trxID: generate.buf2hex(transactionId),
@@ -49,7 +49,7 @@ const controller = async (req, res) => {
} catch (error) {
return res.status(200).send({
status: "404",
code: "404",
message: error.message,
data: {}
})
+2 -2
View File
@@ -39,7 +39,7 @@ const controller = async (req, res) => {
respData1 = generate.getResponseData(respData);
return res.status(200).send({
status: "00",
code: "00",
message: 'Read Succeess',
data: {
trxID: generate.buf2hex(transactionId),
@@ -51,7 +51,7 @@ const controller = async (req, res) => {
} catch (error) {
return res.status(200).send({
status: "404",
code: "404",
message: error.message,
data: {}
})
+3 -3
View File
@@ -10,7 +10,7 @@ const controller = async (req, res) => {
let _stopMessage = 1;
if (packet[0] != 0x45) {
return {
status: "03",
code: "03",
message: "Respone Card Wrong",
data: {}
}
@@ -45,7 +45,7 @@ const controller = async (req, res) => {
respData1 = generate.getResponseData(respData);
return res.status(200).send({
status: "00",
code: "00",
message: 'Read Succeess',
data: {
trxID: generate.buf2hex(transactionId),
@@ -57,7 +57,7 @@ const controller = async (req, res) => {
} catch (error) {
return res.status(200).send({
status: "404",
code: "404",
message: error.message,
data: {}
})
+1 -1
View File
@@ -8,7 +8,7 @@ const controller = async (req, res) => {
let blockReadS = "80008200"
let blockWrite = "800081008200"
return res.status(200).send({
status: "00",
code: "00",
message: 'Get Service Succeess',
data: {
sysCode: sytemCode,
+2 -2
View File
@@ -39,7 +39,7 @@ const controller = async (req, res) => {
respData1 = generate.getResponseData(respData);
return res.status(200).send({
status: "00",
code: "00",
message: 'Generate Write Succeess',
data: {
trxID: generate.buf2hex(transactionId),
@@ -51,7 +51,7 @@ const controller = async (req, res) => {
} catch (error) {
return res.status(200).send({
status: "404",
code: "404",
message: error.message,
data: {}
})
+4 -4
View File
@@ -10,7 +10,7 @@ const controller = async (req, res) => {
let _stopMessage = 1;
if (packet[0] != 0x47) {
return {
status: "03",
code: "03",
message: "Respone Card Wrong",
data: {}
}
@@ -46,7 +46,7 @@ const controller = async (req, res) => {
if (respData[6] != 0x47 || (respData1[9] != 0x00 && respData1[10] != 0x00)){
return res.status(200).send({
status: "02",
code: "02",
message: "Gagal",
data: {
trxID: generate.buf2hex(transactionId),
@@ -57,7 +57,7 @@ const controller = async (req, res) => {
}
return res.status(200).send({
status: "00",
code: "00",
message: 'Topup Succeess',
data: {
trxID: generate.buf2hex(transactionId),
@@ -69,7 +69,7 @@ const controller = async (req, res) => {
} catch (error) {
return res.status(200).send({
status: "404",
code: "404",
message: error.message,
data: {}
})
@@ -215,101 +215,6 @@ const loadingBalanceRequest = async (req, res) => {
}
};
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 {
@@ -446,6 +351,7 @@ const loadingBalance = async (req, res) => {
i_topup_amount: amount,
c_return_sap: null,
i_load_balance_no_seq: loadBalanceNoSequence,
c_idm: uid,
c_status: write_status ? "F" : "A",
c_status_name: write_status ? "FAILED" : "SUCCESS",
d_create: now,
@@ -617,6 +523,102 @@ const inquiryLoadingBalance = async (req, res) => {
}
};
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
);
}
};
module.exports = {
validate,
loadingBalanceRequest,