Commit 818cf50b0bb78ac35f3fa257f43e72911181495c
1 parent
05183f06
Exists in
master
and in
1 other branch
update get customer membership and fix bug
Showing
4 changed files
with
61 additions
and
51 deletions
Show diff stats
ais-structure/src/modules/customer/customer.ctrl.js
... | ... | @@ -11,11 +11,13 @@ exports.customer = async function (req, res, next) { |
11 | 11 | var d01 = "D01" |
12 | 12 | var method = constant.METHOD.GET |
13 | 13 | |
14 | + console.log(req.params); | |
15 | + | |
14 | 16 | if(req.params.customerId){ |
15 | 17 | var customerId = req.params.customerId |
16 | 18 | } else if(req.params.userData && req.params.userType){ |
17 | 19 | var customerId = req.params.userData+"@"+req.params.userType |
18 | - } else { | |
20 | + } else if(req.query.clientName && req.query.commandId){ | |
19 | 21 | var customerId = req.query.clientName+"@"+req.query.commandId; |
20 | 22 | } |
21 | 23 | |
... | ... | @@ -33,7 +35,7 @@ exports.customer = async function (req, res, next) { |
33 | 35 | }else |
34 | 36 | { |
35 | 37 | log.addSuccessSummary(req.query.clientName,method+"_"+getCmd,"null",constant.SUCCESS); |
36 | - var objectData = req.query; | |
38 | + var objectData = Object.assign(req.query,req.params); | |
37 | 39 | const result = await connection.requestJsonToD01(objectData,sendCmd,method); |
38 | 40 | // console.log(Object.keys(result)) |
39 | 41 | log.logDetail.addInput(d01,method+"_"+sendCmd,constant.RESPONSE,result,result.response); | ... | ... |
ais-structure/src/modules/helper/connection.js
... | ... | @@ -36,7 +36,7 @@ connection.requestSoapToSACF = async function (soap,cmd,myMethod) { |
36 | 36 | |
37 | 37 | var funStats = { |
38 | 38 | start : funS, |
39 | - error : function(response){log.addErrorSummary(service.Name,myMethod+"_"+cmd,response);} | |
39 | + error : function(response){log.addErrorSummary(service.Name,myMethod+"_"+cmd,response.resultCode,response.resultDescription);} | |
40 | 40 | }; |
41 | 41 | |
42 | 42 | ... | ... |
ais-structure/src/modules/membercard/getMembership.ctrl.js
... | ... | @@ -9,12 +9,19 @@ var log = require('../helper/log.js'); |
9 | 9 | var constant = require('../helper/constants.js') |
10 | 10 | |
11 | 11 | exports.getMembership = async function (req, res, next) { |
12 | - var getCmd = "VIZCard"; | |
13 | - var sendCmd = "SearchCustomer"; | |
14 | - var sacf = "SACF"; | |
12 | + var getCmd = "CustomerMembership"; | |
13 | + var sendCusCmd = "Customer"; | |
14 | + var sendMemCmd = "MemberCard"; | |
15 | + var d01 = "D01"; | |
15 | 16 | var method = constant.METHOD.GET; |
16 | 17 | |
17 | - var customerId = req.query.clientName+"@"+req.query.commandId; | |
18 | + if(req.params.customerId){ | |
19 | + var customerId = req.params.customerId | |
20 | + } else if(req.params.userData && req.params.userType){ | |
21 | + var customerId = req.params.userData+"@"+req.params.userType | |
22 | + } else if(req.query.clientName && req.query.commandId){ | |
23 | + var customerId = req.query.clientName+"@"+req.query.commandId; | |
24 | + } | |
18 | 25 | |
19 | 26 | log.startlog(method+"_"+getCmd,req.query.commandId,customerId); |
20 | 27 | log.logDetail.addInput(req.query.clientName,method+"_"+getCmd,constant.REQUEST,req,req.body); |
... | ... | @@ -30,56 +37,58 @@ exports.getMembership = async function (req, res, next) { |
30 | 37 | }else |
31 | 38 | { |
32 | 39 | log.addSuccessSummary(req.query.clientName,method+"_"+getCmd,"null","Success"); |
33 | - var objectData = { | |
34 | - Username : "axviz", | |
35 | - Password : "1234", | |
36 | - SystemName : "30", | |
37 | - QueryType : "1", | |
38 | - CardId : req.query.commandId, | |
39 | - firstName : req.query.firstName, | |
40 | - lastName : req.query.lastName, | |
41 | - emailAddress : req.query.emailAddress, | |
42 | - moblieNo : req.query.moblieNo | |
43 | - }; | |
44 | - | |
45 | - const result = await connection.requestSoapToSACF(objectData,sendCmd,constant.METHOD.POST); | |
46 | - // console.log(result.err) | |
47 | - | |
40 | + var objectData = Object.assign(req.query,req.params); | |
41 | + const result = await connection.requestJsonToD01(objectData,sendCusCmd,method); | |
42 | + log.logDetail.addInput(d01,method+"_"+sendCusCmd,constant.RESPONSE,result,result.response); | |
48 | 43 | if(typeof result.err === 'undefined'){ |
49 | - | |
50 | - try { | |
51 | - var resultSoap = parseJson.xml2json(result.body, {compact: true, spaces: 4}) | |
52 | - resultSoap = JSON.parse(resultSoap) | |
53 | - resultSoap = resultSoap['soap:Envelope']['soap:Body']['tem:SearchCustomerResponse']['tem:SearchCustomerResult']['tem:CustomerSearchResult']; | |
54 | - | |
55 | - var resultSet = messageSOAP.soapToArray(req,resultSoap); | |
56 | - stats.receiveSACFResponse(sacf,sendCmd,"Success"); | |
57 | - var response = responseMsg.success(req,getCmd,{resultData:resultSet.returnData,rowCount:resultSet.returnData.length}); | |
58 | - | |
59 | - log.addSuccessSummary(sacf,method+"_"+sendCmd,response.resultCode,response.developerMessage); | |
44 | + var resultObj = result.response; | |
45 | + if(resultObj.resultCode.startsWith("2")) | |
46 | + { | |
47 | + if(resultObj.resultData && resultObj.resultData.length>0) | |
48 | + { | |
49 | + log.addSuccessSummary(d01,method+"_"+sendCusCmd,resultObj.resultCode,resultObj.resultDescription); | |
50 | + var cusIdArr = []; | |
51 | + stats.receiveRestResponse(d01,method,sendCusCmd,constant.SUCCESS); | |
52 | + for(var i = 0; i < resultObj.resultData.length; i++){ | |
53 | + cusIdArr.push(resultObj.resultData[i].customerId) | |
54 | + } | |
55 | + objectData = {customerId : cusIdArr} | |
56 | + // console.log(objectData) | |
57 | + const resultMemberCard = await connection.requestJsonToD01(objectData,sendMemCmd,method); | |
58 | + stats.receiveRestResponse(d01,method,sendMemCmd,constant.SUCCESS); | |
59 | + log.logDetail.addInput(d01,method+"_"+sendCusCmd,constant.RESPONSE,resultMemberCard,resultMemberCard.response); | |
60 | + // console.log(JSON.stringify(resultMemberCard)); | |
61 | + var resultMemberCardObj = resultMemberCard.response; | |
62 | + log.addSuccessSummary(d01,method+"_"+sendMemCmd,resultMemberCardObj.resultCode,resultMemberCardObj.resultDescription); | |
63 | + | |
64 | + for(var i = 0; i < resultObj.resultData.length; i++){ | |
65 | + for(var j = 0; j < resultMemberCardObj.resultData.length; j++){ | |
66 | + if(resultMemberCardObj.resultData[j].cardOwnerIdList.includes(resultObj.resultData[i].customerId)){ | |
67 | + resultObj.resultData[i] = Object.assign(resultObj.resultData[i],{cardId : resultMemberCardObj.resultData[j].cardId}); | |
68 | + } | |
69 | + } | |
70 | + } | |
71 | + var response = responseMsg.success(req,getCmd,resultObj); | |
72 | + }else | |
73 | + { | |
74 | + stats.receiveRestResponse(d01,method,sendCusCmd,constant.RESPONSERESULT.DATA_NOT_FOUND.developerMessage); | |
75 | + var response = responseMsg.error(req,getCmd,40300); | |
76 | + log.addErrorSummary(d01,method+"_"+sendCusCmd,response.resultCode,response.developerMessage); | |
77 | + } | |
78 | + } else { | |
79 | + stats.receiveRestResponse(d01,method,sendCusCmd,constant.ERROR); | |
80 | + var response = responseMsg.direct(req,getCmd,resultObj); | |
81 | + log.addErrorSummary(d01,method+"_"+sendCusCmd,resultObj.resultCode,resultObj.developerMessage); | |
60 | 82 | } |
61 | - catch(error) { | |
62 | - result.response = constant.RESPONSERESULT.ERROR | |
63 | - | |
64 | - stats.receiveSACFBadResponse(sacf,sendCmd); | |
65 | - response = responseMsg.direct(req,getCmd,result.response); | |
66 | - log.addErrorSummary(sacf,method+"_"+sendCmd,response.resultCode,response.developerMessage); | |
67 | - | |
68 | - var resultSet = {rawDataJson : ""} | |
69 | - } | |
70 | - | |
71 | 83 | } else { |
72 | - stats.receiveSACFResponse(sacf,sendCmd,"Error"); | |
73 | - response = responseMsg.direct(req,getCmd,result.response); | |
74 | - log.addErrorSummary(sacf,method+"_"+sendCmd,response.resultCode,response.developerMessage); | |
75 | - var resultSet = {rawDataJson : ""} | |
84 | + stats.receiveRestResponse(d01,method,sendCusCmd,constant.ERROR); | |
85 | + var response = responseMsg.error(req,getCmd,50000); | |
86 | + // log.addErrorSummary(d01,method+"_"+sendCmd,response.resultCode,response.developerMessage); | |
76 | 87 | } |
77 | - | |
78 | - log.logDetail.addInput(sacf,method+"_"+sendCmd,constant.RESPONSE,result,resultSet.rawDataJson); | |
79 | 88 | } |
80 | 89 | |
81 | 90 | // console.log(response); |
82 | - log.logDetail.addOutput(sacf,method+"_"+getCmd,constant.RESPONSE,response,response); | |
91 | + log.logDetail.addOutput(req.query.clientName,method+"_"+getCmd,constant.RESPONSE,response,response); | |
83 | 92 | res.status(200).json(response); |
84 | 93 | next(); |
85 | 94 | }; | ... | ... |
ais-structure/src/modules/vizcard/vizCard.route.js
... | ... | @@ -3,7 +3,6 @@ var cfg = require('../../config/config.js').get(env); |
3 | 3 | |
4 | 4 | module.exports = function (app) { |
5 | 5 | var vizcardCtrl = app.modules.vizcard.vizCardCtrl; |
6 | - var postVizcardCtrl = app.modules.vizcard.postVizCardCtrl; | |
7 | 6 | |
8 | 7 | app.get(cfg.service.CMF.GET_VIZCard_URL[0], |
9 | 8 | vizcardCtrl.vizcard | ... | ... |