var stats = require('../helper/stats.js'); var validatorHelper = require('../helper/validator.js'); var connection = require('../helper/connection.js'); var responseMsg = require('../helper/responseMsg.js'); exports.customer = async function (req, res, next) { var getCmd = "Customer"; var sendCmd = "Customer"; var err = validator(req,getCmd); if(err.length > 0) { console.log(err); var response = responseMsg.error(req,getCmd,40300); // res.status(200).json(response); }else { var objectData = req.query; const result = await connection.requestJsonToD01(objectData,sendCmd,"GET"); if(typeof result.err === 'undefined'){ // console.log(result.response.body); var resultObj = JSON.parse(result.response.body); if(resultObj.resultCode == "20000") { if(resultObj.resultData && resultObj.resultData.length>0) { var response = responseMsg.success(req,getCmd,resultObj); }else { var response = responseMsg.error(req,getCmd,40300); } } } } if(!response) var response = responseMsg.error(req,getCmd,50000); res.status(200).json(response); }; function validator(req,api) { var list = []; list.push([true,"queryStr","commandId","String"]); var err = validatorHelper(req,list,api) //oc if((typeof req.query["customerId"] === 'undefined') && (typeof req.query["userType"] === 'undefined')) { var errDes = { Param : "customerId or userType", Reason : "Missing" } err.push(errDes); }else { if((typeof req.query["userType"] !== 'undefined') && (typeof req.query["userData"] === 'undefined')) { var errDes = { Param : "userData", Reason : "Missing" } err.push(errDes); } } if(err.length > 0) stats.reciveRequest(req.method,api,false); else stats.reciveRequest(req.method,api,true); return err; }