Commit dd6ce15e873312a98a69fba9747fa05e96837105

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

add customer

ais-structure/src/config/config.js
@@ -16,10 +16,23 @@ var config = { @@ -16,10 +16,23 @@ var config = {
16 KEY: "./PANDORA_CERT/server.key", 16 KEY: "./PANDORA_CERT/server.key",
17 CERT: "./PANDORA_CERT/server.pem", 17 CERT: "./PANDORA_CERT/server.pem",
18 PREFIX: "/phxPartner/v1/partner" 18 PREFIX: "/phxPartner/v1/partner"
  19 + },
  20 + SPW:{
  21 + Name : "SPW API",
  22 + POST_SearchCustomer_URL : "http://10.1.3.172:8080",
  23 + POST_SearchCustomer_Timeout : 10
  24 +
  25 + },
  26 + D01:{
  27 + Name : "CMF DB",
  28 + GET_Customer_URL : "http://10.1.3.74:8080",
  29 + GET_Customer_Timeout : 10
  30 +
19 } 31 }
20 }, 32 },
21 http_req_timeout: 120, 33 http_req_timeout: 120,
22 - session: 30 //minutes 34 + session: 30, //minutes
  35 + Default_Timeout: 10
23 } 36 }
24 }; 37 };
25 /* ------------- [END SERVER CONFIG VARIABLES] ------------ */ 38 /* ------------- [END SERVER CONFIG VARIABLES] ------------ */
ais-structure/src/modules/customer/customer.ctrl.js 0 → 100644
@@ -0,0 +1,90 @@ @@ -0,0 +1,90 @@
  1 +var stats = require('../helper/stats.js');
  2 +var validatorHelper = require('../helper/validator.js');
  3 +var connection = require('../helper/connection.js');
  4 +var responseMsg = require('../helper/responseMsg.js');
  5 +
  6 +exports.customer = async function (req, res, next) {
  7 + var getCmd = "Customer";
  8 + var sendCmd = "Customer";
  9 +
  10 + var err = validator(req,getCmd);
  11 +
  12 + if(err.length > 0)
  13 + {
  14 + console.log(err);
  15 +
  16 + var response = responseMsg.error(req,getCmd,40300);
  17 +
  18 + res.status(200).json(response);
  19 + }else
  20 + {
  21 +
  22 + var objectData = req.query;
  23 +
  24 + const result = await connection.requestJsonToD01(objectData,sendCmd,"GET");
  25 +
  26 + // console.log(result.err)
  27 +
  28 + if(typeof result.err === 'undefined'){
  29 +
  30 + if(result.response.resultCode == "20000")
  31 + {
  32 + if(result.response.resultData && result.response.resultData.length>0)
  33 + {
  34 + var response = responseMsg.success(req,getCmd,result.response);
  35 + }else
  36 + {
  37 + var response = responseMsg.error(req,getCmd,40300);
  38 + }
  39 +
  40 + }
  41 +
  42 +
  43 + }
  44 +
  45 + if(!response)
  46 + var response = responseMsg.error(req,getCmd,5000);
  47 +
  48 + res.status(200).json(response);
  49 + }
  50 +};
  51 +
  52 +
  53 +function validator(req,api)
  54 +{
  55 + var list = [];
  56 + list.push([true,"commandId","String"]);
  57 +
  58 + var err = validatorHelper(req,list,api)
  59 +
  60 + //oc
  61 + if((typeof req.query["customerId"] === 'undefined') && (typeof req.query["userType"] === 'undefined'))
  62 + {
  63 + var errDes = {
  64 + Param : "customerId or userType",
  65 + Reason : "Missing"
  66 + }
  67 + err.push(errDes);
  68 +
  69 + }else
  70 + {
  71 + if((typeof req.query["userType"] !== 'undefined') && (typeof req.query["userData"] === 'undefined'))
  72 + {
  73 + var errDes = {
  74 + Param : "userData",
  75 + Reason : "Missing"
  76 + }
  77 + err.push(errDes);
  78 + }
  79 +
  80 + }
  81 +
  82 + if(err.length > 0)
  83 + stats.reciveRequest(req.method,api,false);
  84 + else
  85 + stats.reciveRequest(req.method,api,true);
  86 +
  87 + return err;
  88 +}
  89 +
  90 +
ais-structure/src/modules/customer/customer.route.js 0 → 100644
@@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
  1 +module.exports = function (app) {
  2 + var customerCtrl = app.modules.customer.customerCtrl;
  3 +
  4 + app.get('/cmf/v2/customer/customerId.json',
  5 + customerCtrl.customer
  6 + );
  7 +
  8 +
  9 +};
ais-structure/src/modules/helper/connection.js 0 → 100644
@@ -0,0 +1,62 @@ @@ -0,0 +1,62 @@
  1 +var env = process.env.NODE_ENV || 'development';
  2 +var cfg = require('../../config/config.js').get(env);
  3 +var stats = require('../helper/stats.js');
  4 +var request = require('request');
  5 +var messageSOAP = require('../helper/messageSOAP.js');
  6 +var connection = [];
  7 +
  8 +connection.requestSoapToSPW = function (soap,cmd,myMethod) {
  9 +
  10 + var params = {
  11 + url : cfg.service.SPW[myMethod+"_"+cmd+"_URL"],
  12 + body : messageSOAP.objectToSOAP(soap,cmd),
  13 + method : myMethod
  14 + }
  15 +
  16 + return asyncRequest(params,cmd,cfg.service.SPW.Name);
  17 +};
  18 +connection.requestJsonToD01 = function (json,cmd,myMethod) {
  19 +
  20 + var params = {
  21 + url : cfg.service.D01[myMethod+"_"+cmd+"_URL"],
  22 + body : JSON.stringify(json),
  23 + method : myMethod
  24 + }
  25 +
  26 + return asyncRequest(params,cmd,cfg.service.D01.Name);
  27 +
  28 +
  29 +};
  30 +
  31 +function asyncRequest (params = {},cmd,node) {
  32 +
  33 +
  34 +
  35 + // console.log(params);
  36 + return new Promise((resolve, reject) => {
  37 + request(params, function (error, response, body) {
  38 +
  39 + stats.sendRequest(node,cmd);
  40 +
  41 + if (error) {
  42 + // console.log("error");
  43 + stats.reciveResponse(node,cmd,"Error");
  44 + resolve({
  45 + 'body' : body,
  46 + 'err' : error
  47 + });
  48 + } else {
  49 + // console.log("normal");
  50 + stats.reciveResponse(node,cmd,"Success");
  51 + resolve({
  52 + 'body' : body,
  53 + 'response' : response
  54 + });
  55 + }
  56 + });
  57 + });
  58 +};
  59 +
  60 +
  61 +
  62 +module.exports = connection;
0 \ No newline at end of file 63 \ No newline at end of file
ais-structure/src/modules/helper/responseMsg.js 0 → 100644
@@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
  1 +var stats = require('../helper/stats.js');
  2 +var responseMsg = [];
  3 +
  4 +
  5 +responseMsg.error = function (req,cmd,code){
  6 +
  7 + var devMsg = "System error";
  8 + switch(code) {
  9 + case 50000:
  10 + devMsg = "System error";
  11 + break;
  12 + case 40300:
  13 + devMsg = "Missing or invalid parameter";
  14 + break;
  15 + }
  16 +
  17 + var response = {
  18 + resultCode : code,
  19 + developerMessage : devMsg
  20 + };
  21 +
  22 + stats.sendResponse(req.method,cmd,"Error");
  23 + return response;
  24 +};
  25 +
  26 +responseMsg.success = function (req,cmd,data){
  27 +
  28 + var response = {
  29 + resultCode : 20000,
  30 + developerMessage : "Success",
  31 + resultData : data.resultData,
  32 + rowCount : data.rowCount
  33 + };
  34 +
  35 + stats.sendResponse(req.method,cmd,"Success");
  36 + return response;
  37 +};
  38 +
  39 +module.exports = responseMsg;
0 \ No newline at end of file 40 \ No newline at end of file
ais-structure/src/modules/helper/stats.js
@@ -6,23 +6,23 @@ var stat = []; @@ -6,23 +6,23 @@ var stat = [];
6 6
7 7
8 8
9 -stat.reciveRequest = function (api,pass){ 9 +stat.reciveRequest = function (method,cmd,pass){
10 if(pass) 10 if(pass)
11 - writeStats(nodeName+" Recive "+api+" Request"); 11 + writeStats(nodeName+" Recive "+method+" "+cmd+" Request");
12 else 12 else
13 - writeStats(nodeName+" Recive Bad "+api+" Request"); 13 + writeStats(nodeName+" Recive Bad "+method+" "+cmd+" Request");
14 }; 14 };
15 15
16 -stat.reciveResponse = function (fromNode,api,result){  
17 - writeStats(nodeName+" Recive "+fromNode+" "+api+" Response "+result); 16 +stat.reciveResponse = function (fromNode,cmd,result){
  17 + writeStats(nodeName+" Recive "+fromNode+" "+cmd+" Response "+result);
18 }; 18 };
19 19
20 -stat.sendRequest = function (toNode,api){  
21 - writeStats(nodeName+" Send "+toNode+" "+api+" Request"); 20 +stat.sendRequest = function (toNode,cmd){
  21 + writeStats(nodeName+" Send "+toNode+" "+cmd+" Request");
22 }; 22 };
23 23
24 -stat.sendResponse = function (api,result){  
25 - writeStats(nodeName+" Send "+api+" Response "+result); 24 +stat.sendResponse = function (method,cmd,result){
  25 + writeStats(nodeName+" Send "+method+" "+cmd+" Response "+result);
26 }; 26 };
27 27
28 function writeStats(string) { 28 function writeStats(string) {
ais-structure/src/modules/helper/validator.js
1 -var stats = require('../helper/stats.js');  
2 -  
3 -module.exports = function (req,list,api){ 1 +module.exports = function (req,list){
4 2
5 var err = []; 3 var err = [];
6 4
@@ -13,7 +11,7 @@ module.exports = function (req,list,api){ @@ -13,7 +11,7 @@ module.exports = function (req,list,api){
13 if(row[0]) 11 if(row[0])
14 { 12 {
15 var errDes = { 13 var errDes = {
16 - Param : row, 14 + Param : row[1],
17 Reason : "Missing" 15 Reason : "Missing"
18 } 16 }
19 err.push(errDes); 17 err.push(errDes);
@@ -22,7 +20,7 @@ module.exports = function (req,list,api){ @@ -22,7 +20,7 @@ module.exports = function (req,list,api){
22 if(!checkReg(row[2],req.query[row[1]])) 20 if(!checkReg(row[2],req.query[row[1]]))
23 { 21 {
24 var errDes = { 22 var errDes = {
25 - Param : row, 23 + Param : row[1],
26 Reason : "Invalid" 24 Reason : "Invalid"
27 } 25 }
28 err.push(errDes); 26 err.push(errDes);
@@ -34,7 +32,7 @@ module.exports = function (req,list,api){ @@ -34,7 +32,7 @@ module.exports = function (req,list,api){
34 if(!checkReg(row[2],req.query[row[1]])) 32 if(!checkReg(row[2],req.query[row[1]]))
35 { 33 {
36 var errDes = { 34 var errDes = {
37 - Param : row, 35 + Param : row[1],
38 Reason : "Invalid" 36 Reason : "Invalid"
39 } 37 }
40 err.push(errDes); 38 err.push(errDes);
@@ -44,10 +42,7 @@ module.exports = function (req,list,api){ @@ -44,10 +42,7 @@ module.exports = function (req,list,api){
44 42
45 } 43 }
46 44
47 - if(err.length > 0)  
48 - stats.reciveRequest(api,false);  
49 - else  
50 - stats.reciveRequest(api,true); 45 +
51 46
52 // console.log(err); 47 // console.log(err);
53 48
ais-structure/src/modules/vizcard/vizCard.ctrl.js
1 -var fs = require('fs');  
2 -var moment = require('moment');  
3 -var _ = require('lodash');  
4 -var env = process.env.NODE_ENV || 'development';  
5 -var rp = require('request-promise');  
6 -var logger = require('../../logger/logger');  
7 -var cfg = require('../../config/config.js').get(env);  
8 -var request = require('request');  
9 var parseJson = require('xml-js'); 1 var parseJson = require('xml-js');
10 -var _url = `http://10.1.3.74:8080`;  
11 2
12 var stats = require('../helper/stats.js'); 3 var stats = require('../helper/stats.js');
13 var messageSOAP = require('../helper/messageSOAP.js'); 4 var messageSOAP = require('../helper/messageSOAP.js');
14 var validatorHelper = require('../helper/validator.js'); 5 var validatorHelper = require('../helper/validator.js');
  6 +var connection = require('../helper/connection.js');
  7 +var responseMsg = require('../helper/responseMsg.js');
15 8
16 exports.vizcard = async function (req, res, next) { 9 exports.vizcard = async function (req, res, next) {
  10 + var getCmd = "VIZCard";
  11 + var sendCmd = "SearchCustomer";
17 12
18 - var err = validator(req,"GET VIZCard"); 13 + var err = validator(req,getCmd);
19 14
20 if(err.length > 0) 15 if(err.length > 0)
21 { 16 {
22 console.log(err); 17 console.log(err);
23 18
24 - var response = {  
25 - resultCode : "40300",  
26 - developerMessage : "Missing or invalid parameter"  
27 - }; 19 + var response = responseMsg.error(req,getCmd,40300);
28 20
29 res.status(200).json(response); 21 res.status(200).json(response);
30 }else 22 }else
31 { 23 {
32 - // var requestXml = `<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">  
33 - // <soap:Header/>  
34 - // <soap:Body>  
35 - // <tem:SearchCustomer>  
36 - // <tem:username>axviz</tem:username>  
37 - // <tem:password>1234</tem:password>  
38 - // <tem:systemName>30</tem:systemName>  
39 - // <tem:queryType>1</tem:queryType>  
40 - // <tem:cardId>${req.params.id}</tem:cardId>  
41 - // </tem:SearchCustomer>  
42 - // </soap:Body>  
43 - // </soap:Envelope>`  
44 - 24 +
45 var objectData = { 25 var objectData = {
46 Username : "axviz", 26 Username : "axviz",
47 Password : "1234", 27 Password : "1234",
@@ -54,46 +34,30 @@ exports.vizcard = async function (req, res, next) { @@ -54,46 +34,30 @@ exports.vizcard = async function (req, res, next) {
54 moblieNo : req.query.moblieNo 34 moblieNo : req.query.moblieNo
55 }; 35 };
56 36
57 - var soap = messageSOAP.objectToSOAP(objectData,"SearchCustomer")  
58 - // console.log(soap);  
59 -  
60 - // console.log(requestXml);  
61 - // console.log(req.query.fields)  
62 -  
63 - const result = await asyncRequest({  
64 - url : _url,  
65 - body : soap,  
66 - method : 'POST'  
67 - }); 37 + const result = await connection.requestSoapToSPW(objectData,sendCmd,"POST");
68 38
69 // console.log(result.err) 39 // console.log(result.err)
70 40
71 - if(typeof result.err === 'undefined'){ 41 + if(typeof result.err === 'undefined'){
72 var resultSoap = parseJson.xml2json(result.body, {compact: true, spaces: 4}) 42 var resultSoap = parseJson.xml2json(result.body, {compact: true, spaces: 4})
73 resultSoap = JSON.parse(resultSoap) 43 resultSoap = JSON.parse(resultSoap)
74 resultSoap = resultSoap['soap:Envelope']['soap:Body']['tem:SearchCustomerResponse']['tem:SearchCustomerResult']['tem:CustomerSearchResult']; 44 resultSoap = resultSoap['soap:Envelope']['soap:Body']['tem:SearchCustomerResponse']['tem:SearchCustomerResult']['tem:CustomerSearchResult'];
75 45
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 - }; 46 + var resultSet = messageSOAP.soapToArray(req,resultSoap);
  47 +
  48 + var response = responseMsg.success(req,getCmd,{resultData:resultSet,rowCount:resultSet.length});
  49 +
89 } 50 }
90 51
  52 + if(!response)
  53 + var response = responseMsg.error(req,getCmd,50000);
  54 +
91 res.status(200).json(response); 55 res.status(200).json(response);
92 } 56 }
93 }; 57 };
94 58
95 59
96 -function validator(req,api) 60 +function validator(req,cmd)
97 { 61 {
98 var list = []; 62 var list = [];
99 list.push([true,"commandId","int"]); 63 list.push([true,"commandId","int"]);
@@ -103,26 +67,13 @@ function validator(req,api) @@ -103,26 +67,13 @@ function validator(req,api)
103 list.push([true,"mobileNo","string"]); 67 list.push([true,"mobileNo","string"]);
104 list.push([false,"mobileNo","string"]); 68 list.push([false,"mobileNo","string"]);
105 69
106 - return validatorHelper(req,list,api); 70 + var err = validatorHelper(req,list);
  71 + if(err.length > 0)
  72 + stats.reciveRequest(req.method,cmd,false);
  73 + else
  74 + stats.reciveRequest(req.method,cmd,true);
  75 +
  76 + return err;
107 } 77 }
108 78
109 79
110 -function asyncRequest (params = {}) {  
111 - return new Promise((resolve, reject) => {  
112 - request(params, function (error, response, body) {  
113 - if (error) {  
114 - console.log("error");  
115 - resolve({  
116 - 'body' : body,  
117 - 'err' : error  
118 - });  
119 - } else {  
120 - console.log("normal");  
121 - resolve({  
122 - 'body' : body,  
123 - 'response' : response  
124 - });  
125 - }  
126 - });  
127 - });  
128 -}  
129 \ No newline at end of file 80 \ No newline at end of file