diff --git a/application/modules/hsm/clear_card/clear_1.js b/application/modules/hsm/clear_card/clear_1.js index 7e8ecee..127e8f9 100644 --- a/application/modules/hsm/clear_card/clear_1.js +++ b/application/modules/hsm/clear_card/clear_1.js @@ -81,7 +81,7 @@ const controller = async (req, res) => { // log info winston.logger.info( - `${uniqueCode} [ REQUEST CLEAR CARD KATEGORI PEGAWAI-1 ]: STARTING TOP UP...` + `${uniqueCode} [ REQUEST CLEAR CARD KATEGORI PEGAWAI-1 ]: STARTING CLEAR...` ); // log debug diff --git a/application/modules/hsm/clear_card/clear_6.js b/application/modules/hsm/clear_card/clear_6.js index 80f51aa..11c2851 100644 --- a/application/modules/hsm/clear_card/clear_6.js +++ b/application/modules/hsm/clear_card/clear_6.js @@ -1,7 +1,6 @@ const { param, body, validationResult } = require('express-validator'); const winston = require('../../../helpers/winston.logger'); const generate = require('../utils/utils'); -const loadBalance = require('../../loadbalance/loadbalance.controller'); const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); require('dotenv').config(); @@ -24,28 +23,10 @@ if (process.env.NUMBER_SERVER_ACTIVE == '1') { // VALIDATION const validate = (method) => { switch (method) { - case 'topup': + case 'clear': 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() - .withMessage('Card Number is required'), - body('amount') - .not() - .isEmpty() - .withMessage('Amount is required') - .isNumeric() - .withMessage('Amount is invalid format'), - body('reservation_number') - .not() - .isEmpty() - .withMessage('Reservation Number is required') - .isArray() - .withMessage('Reservation Number is invalid request format'), ]; default: break; @@ -55,22 +36,7 @@ const validate = (method) => { const controller = async (req, res) => { try { // param - let { - mid, - tid, - card_number, - amount, - reservation_number, - ref_no, - write_status, - uid, - balance, - flag, - execution_id, - unique_code, - trxID, - requestData, - } = req.body; + let { mid, tid, unique_code, trxID, requestData } = req.body; let uniqueCode = unique_code; let result = {}; @@ -127,14 +93,6 @@ const controller = async (req, res) => { let transactionId = Buffer.from(generate.hexToBytes(trxID)); let trxrequestData = Buffer.from(generate.hexToBytes(requestData)); let _stopMessage = 1; - let execID; - if (execution_id) { - execID = execution_id; - } else { - let execByte = Buffer.alloc(2); - trxrequestData.copy(execByte, 0, 24, 26); - execID = generate.buf2hex(execByte); - } let apiId = Buffer.from([0x04]); let reqData = generate.makeRequestData( @@ -184,56 +142,17 @@ const controller = async (req, res) => { respCode = generate.getResponseCode(respData); respData1 = generate.getResponseData(respData); - // log debug - winston.logger.debug( - `${uniqueCode} [ PROCESSING CLEAR CARD KATEGORI PEGAWAI-6 ]: inserting load balance transaction...` - ); - - let data = { - mid: mid, - tid: tid, - card_number: card_number, - amount: amount, - reservation_number: reservation_number, - ref_no: ref_no, - write_status: write_status, - uid: uid, - balance: balance, - flag: flag, - unique_code: unique_code, - execution_id: execID, + result = { + code: '00', + message: 'Cleared Succeess', + data: { + trxID: generate.buf2hex(transactionId), + responseCode: respCode, + responseData: respData1, + responseLength: respData1.length / 2, + }, }; - // insert data load balance - let insert = await loadBalance.loadingBalanceInsert(req, data); - if (insert) { - if (insert.code == '00') { - result = { - code: '00', - message: 'Generate Write Succeess', - data: { - trxID: generate.buf2hex(transactionId), - responseCode: respCode, - responseData: respData1, - responseLength: respData1.length / 2, - load_balance_number: insert.data.load_balance_number, - }, - }; - } else { - result = { - code: insert.code, - message: insert.message, - data: {}, - }; - } - } else { - result = { - code: '423', - message: 'update/insert failed', - data: {}, - }; - } - // log debug winston.logger.debug( `${uniqueCode} [ RESPONSE CLEAR CARD KATEGORI PEGAWAI-6 ]: ${JSON.stringify( diff --git a/application/modules/hsm/clear_card/clear_7.js b/application/modules/hsm/clear_card/clear_7.js index 6b33558..1543ca3 100644 --- a/application/modules/hsm/clear_card/clear_7.js +++ b/application/modules/hsm/clear_card/clear_7.js @@ -1,7 +1,6 @@ const { param, body, validationResult } = require('express-validator'); const winston = require('../../../helpers/winston.logger'); const generate = require('../utils/utils'); -const loadBalance = require('../../loadbalance/loadbalance.controller'); const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); require('dotenv').config(); @@ -24,32 +23,10 @@ if (process.env.NUMBER_SERVER_ACTIVE == '1') { // VALIDATION const validate = (method) => { switch (method) { - case 'topupResponse': + case 'clearResponse': 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() - .withMessage('Card Number is required'), - body('amount') - .not() - .isEmpty() - .withMessage('Amount is required') - .isNumeric() - .withMessage('Amount is invalid format'), - body('reservation_number') - .not() - .isEmpty() - .withMessage('Reservation Number is required') - .isArray() - .withMessage('Reservation Number is invalid request format'), - body('load_balance_number') - .not() - .isEmpty() - .withMessage('Load Balance Number is required'), ]; default: break; @@ -59,21 +36,7 @@ const validate = (method) => { const controller = async (req, res) => { try { // param - let { - mid, - tid, - card_number, - amount, - reservation_number, - ref_no, - uid, - balance, - flag, - unique_code, - load_balance_number, - trxID, - requestData, - } = req.body; + let { mid, tid, unique_code, trxID, requestData } = req.body; let uniqueCode = unique_code; let result = {}; @@ -104,7 +67,7 @@ const controller = async (req, res) => { // case success write to the card but loss contact with device // result = { // code: "100", - // message: "failed topup", + // message: "failed clear", // data: {}, // }; // return res.status(200).send(result); @@ -188,106 +151,35 @@ const controller = async (req, res) => { data = { mid: mid, tid: tid, - card_number: card_number, - amount: amount, - reservation_number: reservation_number, - ref_no: ref_no, - write_status: 'FW', - uid: uid, - balance: parseInt(balance) + parseInt(amount), - flag: parseInt(flag), unique_code: unique_code, - load_balance_number: load_balance_number, }; - // log debug - winston.logger.debug( - `${uniqueCode} [ PROCESSING CLEAR CARD KATEGORI PEGAWAI-7 ]: updating load balance transaction is FW...` - ); - - // update data load balance - let update = await loadBalance.loadingBalanceUpdate(data); - if (update) { - if (update.code == '00') { - result = { - code: '5002', - message: 'failed from HSM', - data: { - trxID: generate.buf2hex(transactionId), - responseCode: respData1.slice(6, 10), - transcode: null, - load_balance_number: update.data.load_balance_number, - }, - }; - } else { - result = { - code: update.code, - message: update.message, - data: {}, - }; - } - } else { - result = { - code: '423', - message: 'update/insert failed', - data: {}, - }; - } + result = { + code: '5002', + message: 'failed from HSM', + data: { + trxID: generate.buf2hex(transactionId), + responseCode: respData1.slice(6, 10), + transcode: null, + }, + }; } else { - // jika sudah mencapai maksimum counting flag, maka reset flag ke awal - if (flag >= 255) { - flag = -1; - } - data = { mid: mid, tid: tid, - card_number: card_number, - amount: amount, - reservation_number: reservation_number, - ref_no: ref_no, - write_status: null, - uid: uid, - balance: balance, - flag: flag ? parseInt(flag) + 1 : flag, unique_code: unique_code, - load_balance_number: load_balance_number, }; - // log debug - winston.logger.debug( - `${uniqueCode} [ PROCESSING CLEAR CARD KATEGORI PEGAWAI-7 ]: updating load balance transaction...` - ); - - // update data load balance - let update = await loadBalance.loadingBalanceUpdate(data); - if (update) { - if (update.code == '00') { - result = { - code: '00', - message: 'Topup Succeess', - data: { - trxID: generate.buf2hex(transactionId), - responseCode: respCode, - responseData: respData1, - responseLength: respData1.length / 2, - load_balance_number: update.data.load_balance_number, - }, - }; - } else { - result = { - code: update.code, - message: update.message, - data: {}, - }; - } - } else { - result = { - code: '423', - message: 'update/insert failed', - data: {}, - }; - } + result = { + code: '00', + message: 'Cleared Response Succeess', + data: { + trxID: generate.buf2hex(transactionId), + responseCode: respCode, + responseData: respData1, + responseLength: respData1.length / 2, + }, + }; } // log debug diff --git a/application/routes/hsm.routes.js b/application/routes/hsm.routes.js index 79c36fa..c933b43 100644 --- a/application/routes/hsm.routes.js +++ b/application/routes/hsm.routes.js @@ -1,43 +1,82 @@ -const { Router } = require("express"); +const { Router } = require('express'); const router = Router(); -const auth = require("../middlewares/jwt.middleware"); -const _readData = require("../modules/hsm/readData"); -const _readDataResp = require("../modules/hsm/readDataResp"); +const auth = require('../middlewares/jwt.middleware'); -const _auth1 = require("../modules/hsm/authenticate1"); -const _auth2 = require("../modules/hsm/authenticate2"); -const _authResp = require("../modules/hsm/authenticateResp"); +// Topup +const _auth1 = require('../modules/hsm/topup/topup_1'); +const _auth2 = require('../modules/hsm/topup/topup_2'); +const _authResp = require('../modules/hsm/topup/topup_3'); -const _topup = require("../modules/hsm/topup"); -const _topupResp = require("../modules/hsm/topupResp"); +const _readData = require('../modules/hsm/topup/topup_4'); +const _readDataResp = require('../modules/hsm/topup/topup_5'); -const _end = require("../modules/hsm/endTranscation"); +const _topup = require('../modules/hsm/topup/topup_6'); +const _topupResp = require('../modules/hsm/topup/topup_7'); -const _getService = require("../modules/hsm/service_block"); +const _end = require('../modules/hsm/topup/topup_8'); +const _getService = require('../modules/hsm/topup/service_block'); -router.post("/topup1", auth.authenticateToken, _auth1); -router.post("/topup2", auth.authenticateToken, _auth2); -router.post("/topup3", auth.authenticateToken, _authResp); -router.post("/topup4", auth.authenticateToken, _readData); -router.post("/topup5", auth.authenticateToken, _readDataResp); +router.post('/topup1', auth.authenticateToken, _auth1); +router.post('/topup2', auth.authenticateToken, _auth2); +router.post('/topup3', auth.authenticateToken, _authResp); +router.post('/topup4', auth.authenticateToken, _readData); +router.post('/topup5', auth.authenticateToken, _readDataResp); router.post( - "/topup6", + '/topup6', auth.authenticateToken, - _topup.validate("topup"), + _topup.validate('topup'), _topup.controller ); router.post( - "/topup7", + '/topup7', auth.authenticateToken, - _topupResp.validate("topupResponse"), + _topupResp.validate('topupResponse'), _topupResp.controller ); -router.post("/topup8", auth.authenticateToken, _end); +router.post('/topup8', auth.authenticateToken, _end); -router.get("/getservice", auth.authenticateToken, _getService); +router.get('/getservice', auth.authenticateToken, _getService); + +// Clear Card +const _authClear1 = require('../modules/hsm/clear_card/clear_1'); +const _authClear2 = require('../modules/hsm/clear_card/clear_2'); +const _authRespClear = require('../modules/hsm/clear_card/clear_3'); + +const _readDataClear = require('../modules/hsm/clear_card/clear_4'); +const _readDataRespClear = require('../modules/hsm/clear_card/clear_5'); + +const _clear = require('../modules/hsm/clear_card/clear_6'); +const _clearResp = require('../modules/hsm/clear_card/clear_7'); + +const _endClear = require('../modules/hsm/clear_card/clear_8'); + +const _getServiceClear = require('../modules/hsm/clear_card/service_block'); + +router.post('/clear1', auth.authenticateToken, _authClear1); +router.post('/clear2', auth.authenticateToken, _authClear2); +router.post('/clear3', auth.authenticateToken, _authRespClear); +router.post('/clear4', auth.authenticateToken, _readDataClear); +router.post('/clear5', auth.authenticateToken, _readDataRespClear); + +router.post( + '/clear6', + auth.authenticateToken, + _clear.validate('clear'), + _clear.controller +); +router.post( + '/clear7', + auth.authenticateToken, + _clearResp.validate('clearResponse'), + _clearResp.controller +); + +router.post('/clear8', auth.authenticateToken, _endClear); + +router.get('/getservice', auth.authenticateToken, _getServiceClear); module.exports = router;