From c4ff18473b6b1ccef75697b073de3eb6d762a7da Mon Sep 17 00:00:00 2001 From: Mohamad Ihsan Date: Sat, 9 Jul 2022 05:48:34 +0700 Subject: [PATCH] update --- ...e727b13210eef32232709400762e5fb-audit.json | 5 + .../dongleorder/dongleorder.controller.js | 176 ++++++++++++++++++ .../modules/dongleorder/dongleorder.model.js | 27 +++ .../loadbalance/loadbalance.controller.js | 26 +-- application/routes/dongleorder.routes.js | 19 ++ docs/error_code | 10 +- index.js | 2 + 7 files changed, 247 insertions(+), 18 deletions(-) create mode 100644 application/modules/dongleorder/dongleorder.controller.js create mode 100644 application/modules/dongleorder/dongleorder.model.js create mode 100644 application/routes/dongleorder.routes.js diff --git a/.71c131f2ce727b13210eef32232709400762e5fb-audit.json b/.71c131f2ce727b13210eef32232709400762e5fb-audit.json index cb856ea..306fdde 100644 --- a/.71c131f2ce727b13210eef32232709400762e5fb-audit.json +++ b/.71c131f2ce727b13210eef32232709400762e5fb-audit.json @@ -9,6 +9,11 @@ "date": 1657267492554, "name": "2022-07-08-onlinetopup.log", "hash": "eb050e1a7fc373dd45fbb3ee982333f4e68d3a957348426026df54964e032f3f" + }, + { + "date": 1657318223033, + "name": "2022-07-09-onlinetopup.log", + "hash": "0b91d47db406a098e198aa5e145df01f47f203c04a28b151f50a3bbb7deff454" } ], "hashType": "sha256" diff --git a/application/modules/dongleorder/dongleorder.controller.js b/application/modules/dongleorder/dongleorder.controller.js new file mode 100644 index 0000000..1952d87 --- /dev/null +++ b/application/modules/dongleorder/dongleorder.controller.js @@ -0,0 +1,176 @@ +const { param, body, validationResult } = require("express-validator"); +const helper = require("../../helpers/helper"); +const winston = require("../../helpers/winston.logger"); +const model = require("./dongleorder.model"); +const moment = require("moment"); +moment.locale("id"); + +var result = {}; +var uniqueCode; + +// VALIDATION +const validate = (method) => { + switch (method) { + case "dongleOrderUpdate": + return [ + body("dongle_id").not().isEmpty().withMessage("Dongle ID is required"), + ]; + default: + break; + } +}; + +// GET DONGLE ORDER +const getDongleOrder = async (req, res) => { + try { + + uniqueCode = await helper.getUniqueCode(); + + // log debug + winston.logger.debug(`${uniqueCode} get RO...`); + + // get RO + let getRO = await model.getRO(); + if (!getRO) { + result = { + code: "422", + message: "data doesn't exists'", + data: {}, + }; + + // log warn + winston.logger.warn( + `${uniqueCode} RESPONSE get RO and dongle order: ${JSON.stringify( + result + )}` + ); + + return res.status(200).json(result); + } + + result = { + code: "00", + message: "success", + data: getRO, + }; + + // log info + winston.logger.info( + `${uniqueCode} RESPONSE get RO and dongle order: ${JSON.stringify(result)}` + ); + + return res.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: {}, + }); + } +}; + +// UPDATE DONGLE ORDER +const updateDongleOrder = async (req, res) => { + try { + // param + let { + dongle_id, status + } = req.body; + + uniqueCode = await helper.getUniqueCode(); + + // log info + winston.logger.info( + `${uniqueCode} REQUEST update dongle order: ${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 update dongle order: ${JSON.stringify(result)}` + ); + + return res.status(200).json(result); + } + + // time + let now = moment().format("YYYY-MM-DD HH:mm:ss"); + + // log debug + winston.logger.debug(`${uniqueCode} updating dongle order...`); + + let data = { + c_status: status == "G" ? "G" : "C", + c_status_name: status == "G" ? "GENERATED" : "CREATED", + d_modify: now, + } + + // get partner, merchant, terminal from tid + let updateDongleOrderStatus = await model.updateDongleOrderStatus(data, dongle_id); + if (!updateDongleOrderStatus) { + result = { + code: "423", + message: "update failed", + data: {}, + }; + + // log warn + winston.logger.warn( + `${uniqueCode} RESPONSE update dongle order: ${JSON.stringify( + result + )}` + ); + + return res.status(200).json(result); + } + + result = { + code: "00", + message: "updated successfully", + data: {}, + }; + + // log info + winston.logger.info( + `${uniqueCode} RESPONSE update dongle order: ${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: {}, + }); + } +}; + +module.exports = { + validate, + getDongleOrder, + updateDongleOrder, +}; diff --git a/application/modules/dongleorder/dongleorder.model.js b/application/modules/dongleorder/dongleorder.model.js new file mode 100644 index 0000000..3a5887b --- /dev/null +++ b/application/modules/dongleorder/dongleorder.model.js @@ -0,0 +1,27 @@ +const knex = require("../../../infrastructure/database/knex"); + +// GET RO +const getRO = () => { + let result = knex("trx.t_d_dongle_order") + .select("trx.t_d_dongle_order.*") + .leftJoin( + "trx.t_d_request_order", + "trx.t_d_dongle_order.i_request_order", + "trx.t_d_request_order.i_request_order" + ) + .where("trx.t_d_request_order.c_status", "!=", "X"); + return result; +}; + +// UPDATE DONGLE ORDER STATUS +const updateDongleOrderStatus = (data, dongleID) => { + let result = knex("trx.t_d_dongle_order") + .update(data) + .where("c_dongle_id", dongleID); + return result; +}; + +module.exports = { + getRO, + updateDongleOrderStatus, +}; diff --git a/application/modules/loadbalance/loadbalance.controller.js b/application/modules/loadbalance/loadbalance.controller.js index 30be66b..c7ce03a 100644 --- a/application/modules/loadbalance/loadbalance.controller.js +++ b/application/modules/loadbalance/loadbalance.controller.js @@ -490,7 +490,7 @@ const loadingBalance = async (req, res) => { // log warn winston.logger.warn( - `${uniqueCode} RESPONSE load balance validate: ${JSON.stringify( + `${uniqueCode} RESPONSE load balance insert: ${JSON.stringify( result )}` ); @@ -516,7 +516,7 @@ const loadingBalance = async (req, res) => { // log warn winston.logger.warn( - `${uniqueCode} RESPONSE load balance validate: ${JSON.stringify( + `${uniqueCode} RESPONSE load balance insert: ${JSON.stringify( result )}` ); @@ -542,7 +542,7 @@ const loadingBalance = async (req, res) => { // log info winston.logger.info( - `${uniqueCode} RESPONSE load balance validate: ${JSON.stringify( + `${uniqueCode} RESPONSE load balance insert: ${JSON.stringify( result )}` ); @@ -570,7 +570,7 @@ const loadingBalance = async (req, res) => { // log warn winston.logger.warn( - `${uniqueCode} RESPONSE load balance validate: ${JSON.stringify( + `${uniqueCode} RESPONSE load balance insert: ${JSON.stringify( result )}` ); @@ -596,7 +596,7 @@ const loadingBalance = async (req, res) => { // log warn winston.logger.warn( - `${uniqueCode} RESPONSE load balance validate: ${JSON.stringify( + `${uniqueCode} RESPONSE load balance insert: ${JSON.stringify( result )}` ); @@ -703,7 +703,7 @@ const loadingBalance = async (req, res) => { // log warn winston.logger.warn( - `${uniqueCode} RESPONSE load balance validate: ${JSON.stringify( + `${uniqueCode} RESPONSE load balance insert: ${JSON.stringify( result )}` ); @@ -885,7 +885,7 @@ const loadingBalanceInsert = async (param) => { // log warn winston.logger.warn( - `${uniqueCode} RESPONSE load balance validate: ${JSON.stringify( + `${uniqueCode} RESPONSE load balance insert: ${JSON.stringify( result )}` ); @@ -911,7 +911,7 @@ const loadingBalanceInsert = async (param) => { // log warn winston.logger.warn( - `${uniqueCode} RESPONSE load balance validate: ${JSON.stringify( + `${uniqueCode} RESPONSE load balance insert: ${JSON.stringify( result )}` ); @@ -937,7 +937,7 @@ const loadingBalanceInsert = async (param) => { // log info winston.logger.info( - `${uniqueCode} RESPONSE load balance validate: ${JSON.stringify( + `${uniqueCode} RESPONSE load balance insert: ${JSON.stringify( result )}` ); @@ -965,7 +965,7 @@ const loadingBalanceInsert = async (param) => { // log warn winston.logger.warn( - `${uniqueCode} RESPONSE load balance validate: ${JSON.stringify( + `${uniqueCode} RESPONSE load balance insert: ${JSON.stringify( result )}` ); @@ -991,7 +991,7 @@ const loadingBalanceInsert = async (param) => { // log warn winston.logger.warn( - `${uniqueCode} RESPONSE load balance validate: ${JSON.stringify( + `${uniqueCode} RESPONSE load balance insert: ${JSON.stringify( result )}` ); @@ -1098,7 +1098,7 @@ const loadingBalanceInsert = async (param) => { // log warn winston.logger.warn( - `${uniqueCode} RESPONSE load balance validate: ${JSON.stringify( + `${uniqueCode} RESPONSE load balance insert: ${JSON.stringify( result )}` ); @@ -1239,7 +1239,7 @@ const loadingBalanceUpdate = async (param) => { // log warn winston.logger.warn( - `${uniqueCode} RESPONSE load balance validate: ${JSON.stringify( + `${uniqueCode} RESPONSE load balance update: ${JSON.stringify( result )}` ); diff --git a/application/routes/dongleorder.routes.js b/application/routes/dongleorder.routes.js new file mode 100644 index 0000000..871ef6e --- /dev/null +++ b/application/routes/dongleorder.routes.js @@ -0,0 +1,19 @@ +const express = require("express"); +const router = express.Router(); +const auth = require("../middlewares/jwt.middleware"); +const controller = require("../modules/dongleorder/dongleorder.controller"); + +router.get( + "/dongleorder/ro", + auth.authenticateToken, + controller.getDongleOrder +); + +router.put( + "/dongleorder/update", + auth.authenticateToken, + controller.validate("dongleOrderUpdate"), + controller.updateDongleOrder +); + +module.exports = router; diff --git a/docs/error_code b/docs/error_code index 53b5bad..5ff7e21 100644 --- a/docs/error_code +++ b/docs/error_code @@ -3,7 +3,7 @@ 01 Success Without Write to the card 02 Success without reservation pending or in progress status 03 Success with reservation pending or in progress status - 04 Success. Transaction has been recon + 04 Success. Transaction has been recon previously # ERROR MESSAGE CODE TOPUP ONLINE SERVICE 400 Bad Request Parameter or Validation Parameter Error @@ -22,11 +22,11 @@ 419 load balance doesn't exist 420 your card number has incomplete transaction. Please unload your balance! 421 your card number has some pending transaction. Please finished it! - 422 history doesn't exist + 422 data doesn't exist 423 update/insert failed - 424 Duplicate Ref No - 425 Total amount is different - 426 Partner doesn't exists + 424 duplicate Ref No + 425 total amount is different + 426 partner doesn't exists 427 transaction doesn't exists 428 failed recon. The other transaction with same data is running 500 Error Catch diff --git a/index.js b/index.js index c5196ca..4c2dfc4 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,7 @@ const cors = require("cors"); const helper = require("./application/helpers/helper"); const winston = require("./application/helpers/winston.logger"); const authRoute = require("./application/routes/auth.routes"); +const dongleOrderRoute = require("./application/routes/dongleorder.routes"); const reservationRoute = require("./application/routes/reservebalance.routes"); const loadBalanceRoute = require("./application/routes/loadbalance.routes"); const hsmRoute = require("./application/routes/hsm.routes"); @@ -38,6 +39,7 @@ app.get("/", (req, res) => { }); app.use("/api/", authRoute); +app.use("/api/", dongleOrderRoute); app.use("/api/", historyRoute); app.use("/api/", hsmRoute); app.use("/api/", loadBalanceRoute);