Commit adfb98a7c166000da15471c9958964c13b8e0b69

Authored by sumatek
1 parent f138f801
Exists in master and in 1 other branch dev

merge

ais-structure/src/modules/helper/validator.js
1 var stats = require('../helper/stats.js'); 1 var stats = require('../helper/stats.js');
2 2
3 -module.exports = function (req,mandatoryList,api){ 3 +module.exports = function (req,list,api){
4 4
5 var err = []; 5 var err = [];
6 -  
7 - for(var i=0;i<mandatoryList.length;i++) 6 +
  7 + var row = [];
  8 + for(var i=0;i<list.length;i++)
8 { 9 {
9 - if(typeof req.query[mandatoryList[i]] === 'undefined') 10 + row = list[i];
  11 + if(typeof req.query[row[1]] === 'undefined')
10 { 12 {
11 - var errDes = {  
12 - Param : mandatoryList[i],  
13 - Reason : "Missing"  
14 - }  
15 - err.push(errDes); 13 + if(row[0])
  14 + {
  15 + var errDes = {
  16 + Param : row,
  17 + Reason : "Missing"
  18 + }
  19 + err.push(errDes);
  20 + }else
  21 + {
  22 + if(!checkReg(row[2],req.query[row[1]]))
  23 + {
  24 + var errDes = {
  25 + Param : row,
  26 + Reason : "Invalid"
  27 + }
  28 + err.push(errDes);
  29 + }
  30 + }
  31 +
16 }else 32 }else
17 { 33 {
18 - // invaild 34 + if(!checkReg(row[2],req.query[row[1]]))
  35 + {
  36 + var errDes = {
  37 + Param : row,
  38 + Reason : "Invalid"
  39 + }
  40 + err.push(errDes);
  41 + }
19 } 42 }
  43 +
  44 +
20 } 45 }
21 46
22 if(err.length > 0) 47 if(err.length > 0)
@@ -29,3 +54,8 @@ module.exports = function (req,mandatoryList,api){ @@ -29,3 +54,8 @@ module.exports = function (req,mandatoryList,api){
29 return err; 54 return err;
30 }; 55 };
31 56
  57 +function checkReg(reg,value)
  58 +{
  59 + return true;
  60 +}
  61 +
ais-structure/src/modules/vizcard/vizCard.ctrl.js
@@ -19,6 +19,8 @@ exports.vizcard = async function (req, res, next) { @@ -19,6 +19,8 @@ exports.vizcard = async function (req, res, next) {
19 19
20 if(err.length > 0) 20 if(err.length > 0)
21 { 21 {
  22 + console.log(err);
  23 +
22 var response = { 24 var response = {
23 resultCode : "40300", 25 resultCode : "40300",
24 developerMessage : "Missing or invalid parameter" 26 developerMessage : "Missing or invalid parameter"
@@ -64,22 +66,27 @@ exports.vizcard = async function (req, res, next) { @@ -64,22 +66,27 @@ exports.vizcard = async function (req, res, next) {
64 method : 'POST' 66 method : 'POST'
65 }); 67 });
66 68
67 - // parseString(result.body, function (err, result1) {  
68 - // console.log(result1);  
69 - // });  
70 -  
71 - var resultSoap = parseJson.xml2json(result.body, {compact: true, spaces: 4})  
72 - resultSoap = JSON.parse(resultSoap)  
73 - resultSoap = resultSoap['soap:Envelope']['soap:Body']['tem:SearchCustomerResponse']['tem:SearchCustomerResult']['tem:CustomerSearchResult'];  
74 -  
75 - var resultData = messageSOAP.soapToArray(req,resultSoap);  
76 -  
77 - var response = {  
78 - resultCode : "20000",  
79 - developerMessage : "Success",  
80 - resultData : resultData,  
81 - rowCount : resultData.length  
82 - }; 69 + // console.log(result.err)
  70 +
  71 + if(typeof result.err === 'undefined'){
  72 + var resultSoap = parseJson.xml2json(result.body, {compact: true, spaces: 4})
  73 + resultSoap = JSON.parse(resultSoap)
  74 + resultSoap = resultSoap['soap:Envelope']['soap:Body']['tem:SearchCustomerResponse']['tem:SearchCustomerResult']['tem:CustomerSearchResult'];
  75 +
  76 + var resultData = messageSOAP.soapToArray(req,resultSoap);
  77 +
  78 + var response = {
  79 + resultCode : "20000",
  80 + developerMessage : "Success",
  81 + resultData : resultData,
  82 + rowCount : resultData.length
  83 + };
  84 + } else {
  85 + var response = {
  86 + resultCode : "50000",
  87 + developerMessage : "System error"
  88 + };
  89 + }
83 90
84 res.status(200).json(response); 91 res.status(200).json(response);
85 } 92 }
@@ -89,11 +96,12 @@ exports.vizcard = async function (req, res, next) { @@ -89,11 +96,12 @@ exports.vizcard = async function (req, res, next) {
89 function validator(req,api) 96 function validator(req,api)
90 { 97 {
91 var list = []; 98 var list = [];
92 - list.push("commandId");  
93 - list.push("firstName");  
94 - list.push("lastName");  
95 - list.push("emailAddress");  
96 - list.push("mobileNo"); 99 + list.push([true,"commandId","int"]);
  100 + list.push([true,"firstName","string"]);
  101 + list.push([true,"lastName","string"]);
  102 + list.push([true,"emailAddress","string"]);
  103 + list.push([true,"mobileNo","string"]);
  104 + list.push([false,"mobileNo","string"]);
97 105
98 return validatorHelper(req,list,api); 106 return validatorHelper(req,list,api);
99 } 107 }
@@ -103,15 +111,16 @@ function asyncRequest (params = {}) { @@ -103,15 +111,16 @@ function asyncRequest (params = {}) {
103 return new Promise((resolve, reject) => { 111 return new Promise((resolve, reject) => {
104 request(params, function (error, response, body) { 112 request(params, function (error, response, body) {
105 if (error) { 113 if (error) {
106 - // reject(error); 114 + console.log("error");
107 resolve({ 115 resolve({
108 - 'body' : body,  
109 - 'err': error 116 + 'body' : body,
  117 + 'err' : error
110 }); 118 });
111 } else { 119 } else {
  120 + console.log("normal");
112 resolve({ 121 resolve({
113 - 'body' : body,  
114 - 'response': response 122 + 'body' : body,
  123 + 'response' : response
115 }); 124 });
116 } 125 }
117 }); 126 });