From adfb98a7c166000da15471c9958964c13b8e0b69 Mon Sep 17 00:00:00 2001 From: Sumate Kongpui Date: Wed, 15 Aug 2018 11:29:20 +0700 Subject: [PATCH] merge --- ais-structure/src/modules/helper/validator.js | 50 ++++++++++++++++++++++++++++++++++++++++---------- ais-structure/src/modules/vizcard/vizCard.ctrl.js | 61 +++++++++++++++++++++++++++++++++++-------------------------- 2 files changed, 75 insertions(+), 36 deletions(-) diff --git a/ais-structure/src/modules/helper/validator.js b/ais-structure/src/modules/helper/validator.js index 1cb886f..695020f 100644 --- a/ais-structure/src/modules/helper/validator.js +++ b/ais-structure/src/modules/helper/validator.js @@ -1,22 +1,47 @@ var stats = require('../helper/stats.js'); -module.exports = function (req,mandatoryList,api){ +module.exports = function (req,list,api){ var err = []; - - for(var i=0;i 0) @@ -29,3 +54,8 @@ module.exports = function (req,mandatoryList,api){ return err; }; +function checkReg(reg,value) +{ + return true; +} + diff --git a/ais-structure/src/modules/vizcard/vizCard.ctrl.js b/ais-structure/src/modules/vizcard/vizCard.ctrl.js index 772d023..349acd9 100644 --- a/ais-structure/src/modules/vizcard/vizCard.ctrl.js +++ b/ais-structure/src/modules/vizcard/vizCard.ctrl.js @@ -19,6 +19,8 @@ exports.vizcard = async function (req, res, next) { if(err.length > 0) { + console.log(err); + var response = { resultCode : "40300", developerMessage : "Missing or invalid parameter" @@ -64,22 +66,27 @@ exports.vizcard = async function (req, res, next) { method : 'POST' }); - // parseString(result.body, function (err, result1) { - // console.log(result1); - // }); - - var resultSoap = parseJson.xml2json(result.body, {compact: true, spaces: 4}) - resultSoap = JSON.parse(resultSoap) - resultSoap = resultSoap['soap:Envelope']['soap:Body']['tem:SearchCustomerResponse']['tem:SearchCustomerResult']['tem:CustomerSearchResult']; - - var resultData = messageSOAP.soapToArray(req,resultSoap); - - var response = { - resultCode : "20000", - developerMessage : "Success", - resultData : resultData, - rowCount : resultData.length - }; + // console.log(result.err) + + if(typeof result.err === 'undefined'){ + var resultSoap = parseJson.xml2json(result.body, {compact: true, spaces: 4}) + resultSoap = JSON.parse(resultSoap) + resultSoap = resultSoap['soap:Envelope']['soap:Body']['tem:SearchCustomerResponse']['tem:SearchCustomerResult']['tem:CustomerSearchResult']; + + var resultData = messageSOAP.soapToArray(req,resultSoap); + + var response = { + resultCode : "20000", + developerMessage : "Success", + resultData : resultData, + rowCount : resultData.length + }; + } else { + var response = { + resultCode : "50000", + developerMessage : "System error" + }; + } res.status(200).json(response); } @@ -89,11 +96,12 @@ exports.vizcard = async function (req, res, next) { function validator(req,api) { var list = []; - list.push("commandId"); - list.push("firstName"); - list.push("lastName"); - list.push("emailAddress"); - list.push("mobileNo"); + list.push([true,"commandId","int"]); + list.push([true,"firstName","string"]); + list.push([true,"lastName","string"]); + list.push([true,"emailAddress","string"]); + list.push([true,"mobileNo","string"]); + list.push([false,"mobileNo","string"]); return validatorHelper(req,list,api); } @@ -103,15 +111,16 @@ function asyncRequest (params = {}) { return new Promise((resolve, reject) => { request(params, function (error, response, body) { if (error) { - // reject(error); + console.log("error"); resolve({ - 'body' : body, - 'err': error + 'body' : body, + 'err' : error }); } else { + console.log("normal"); resolve({ - 'body' : body, - 'response': response + 'body' : body, + 'response' : response }); } }); -- libgit2 0.21.2