This commit is contained in:
2022-07-08 13:07:46 +07:00
parent 9d3fdebea2
commit 41bbc7b2d1
2 changed files with 74 additions and 2 deletions
@@ -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,
};
+6
View File
@@ -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,