diff --git a/application/modules/history/history.controller.js b/application/modules/history/history.controller.js index bf3e5f6..b6c9a1f 100644 --- a/application/modules/history/history.controller.js +++ b/application/modules/history/history.controller.js @@ -11,6 +11,8 @@ var uniqueCode; // VALIDATION const validate = (method) => { switch (method) { + case "cardHistory": + return [body("data").not().isEmpty().withMessage("Data is required")]; case "history": return [ body("mid").not().isEmpty().withMessage("MID is required"), @@ -26,7 +28,70 @@ const validate = (method) => { } }; -// HISTORY +// HISTORY FROM CARD +const cardHistory = async (req, res) => { + try { + // generate unique code + uniqueCode = await helper.getUniqueCode(); + + // param + let { data } = req.body; + + // log info + winston.logger.info( + `${uniqueCode} REQUEST card history: ${JSON.stringify(req.body)}` + ); + + // check validator + const err = validationResult(req, res); + if (!err.isEmpty()) { + result = { + code: "400", + message: err.errors[0].msg, + data: {}, + }; + + // log warn + winston.logger.warn( + `${uniqueCode} RESPONSE card history: ${JSON.stringify(result)}` + ); + + return res.status(200).json(result); + } + + // parsing data from card + // PARSING DISINI ZEN + + result = { + code: "00", + message: "success", + data: {}, + }; + + // log info + winston.logger.info( + `${uniqueCode} RESPONSE card history: ${JSON.stringify(result)}` + ); + + return res.status(200).json(result); + } catch (error) { + // create log + winston.logger.error( + `500 internal server error - backend server | ${error.message}` + ); + + return res.status(200).json({ + code: "500", + message: + process.env.NODE_ENV != "production" + ? error.message + : "500 internal server error - backend server.", + data: {}, + }); + } +}; + +// HISTORY FROM CMS const history = async (req, res) => { try { // check validator @@ -64,7 +129,7 @@ const history = async (req, res) => { }); } - // check reservation and load balance transaction + // card history and load balance transaction let result = await model.historyByCardNumber( mid, tid, @@ -100,5 +165,6 @@ const history = async (req, res) => { module.exports = { validate, + cardHistory, history, }; diff --git a/application/routes/history.routes.js b/application/routes/history.routes.js index c1e88da..4ea71bb 100644 --- a/application/routes/history.routes.js +++ b/application/routes/history.routes.js @@ -3,6 +3,12 @@ const router = express.Router(); const auth = require("../middlewares/jwt.middleware"); const controller = require("../modules/history/history.controller"); +router.post( + "/card-history", + auth.authenticateToken, + controller.validate("cardHistory"), + controller.cardHistory +); router.post( "/history", auth.authenticateToken,