Commit 1f123eb14d93c1fda5dc73f24342fc78ba531f8a
1 parent
c4a567d0
Exists in
master
and in
1 other branch
update post membership
Showing
6 changed files
with
116 additions
and
72 deletions
Show diff stats
ais-structure/src/modules/customer/postCustomer.ctrl.js
... | ... | @@ -15,19 +15,19 @@ exports.postCustomer = async function (req, res, next){ |
15 | 15 | var customerId = req.body.user.userData+"@"+req.body.user.userType; |
16 | 16 | } |
17 | 17 | |
18 | - log.startlog(method+"_"+getCmd,req.body.commandId,customerId); | |
19 | - log.logDetail.addInput(req.body.clientName,method+"_"+getCmd,constant.REQUEST,req,req.body); | |
18 | + log.startlog(req,method+"_"+getCmd,req.body.commandId,customerId); | |
19 | + log.logDetail.addInput(req,req.body.clientName,method+"_"+getCmd,constant.REQUEST,req,req.body); | |
20 | 20 | |
21 | 21 | var err = validator(req,getCmd); |
22 | 22 | |
23 | 23 | if(err.length > 0) |
24 | 24 | { |
25 | - log.addErrorSummary(req.body.clientName,method+"_"+getCmd,"null",constant.FAIL); | |
25 | + log.addErrorSummary(req,req.body.clientName,method+"_"+getCmd,"null",constant.FAIL); | |
26 | 26 | console.log(err); |
27 | 27 | var response = responseMsg.error(req,getCmd,40300); |
28 | 28 | }else |
29 | 29 | { |
30 | - log.addSuccessSummary(req.body.clientName,method+"_"+getCmd,"null",constant.SUCCESS); | |
30 | + log.addSuccessSummary(req,req.body.clientName,method+"_"+getCmd,"null",constant.SUCCESS); | |
31 | 31 | var objectData = { |
32 | 32 | customerId : customerId, |
33 | 33 | userIdData : req.body.user.userData, |
... | ... | @@ -39,23 +39,23 @@ exports.postCustomer = async function (req, res, next){ |
39 | 39 | dateCreated : req.body.dateCreated |
40 | 40 | }; |
41 | 41 | |
42 | - const result = await connection.requestJsonToD01(objectData,sendCmd,method); | |
43 | - log.logDetail.addInput(d01,method+"_"+sendCmd,constant.RESPONSE,result,result.response); | |
42 | + const result = await connection.requestJsonToD01(req,objectData,sendCmd,method); | |
43 | + log.logDetail.addInput(req,d01,method+"_"+sendCmd,constant.RESPONSE,result,result.response); | |
44 | 44 | if(typeof result.err === 'undefined'){ |
45 | 45 | // console.log(result.response.body); |
46 | 46 | var resultObj = result.response; |
47 | 47 | if(resultObj.resultCode.startsWith("2")){ |
48 | 48 | stats.receiveRestResponse(d01,method,sendCmd,constant.SUCCESS); |
49 | 49 | var response = responseMsg.direct(req,getCmd,resultObj,{customerId:objectData.customerId}); |
50 | - log.addSuccessSummary(d01,method+"_"+sendCmd,response.resultCode,response.developerMessage); | |
50 | + log.addSuccessSummary(req,d01,method+"_"+sendCmd,response.resultCode,response.developerMessage); | |
51 | 51 | } else if(resultObj.resultCode.startsWith("404")){ |
52 | 52 | stats.receiveRestResponse(d01,method,sendCmd,constant.RESPONSERESULT.DATA_NOT_FOUND.developerMessage); |
53 | 53 | var response = responseMsg.direct(req,getCmd,resultObj); |
54 | - log.addErrorSummary(d01,method+"_"+sendCmd,resultObj.resultCode,resultObj.developerMessage); | |
54 | + log.addErrorSummary(req,d01,method+"_"+sendCmd,resultObj.resultCode,resultObj.developerMessage); | |
55 | 55 | } else if(resultObj.resultCode.startsWith("5")){ |
56 | 56 | stats.receiveRestResponse(d01,method,sendCmd,constant.ERROR); |
57 | 57 | var response = responseMsg.direct(req,getCmd,resultObj); |
58 | - log.addErrorSummary(d01,method+"_"+sendCmd,resultObj.resultCode,resultObj.developerMessage); | |
58 | + log.addErrorSummary(req,d01,method+"_"+sendCmd,resultObj.resultCode,resultObj.developerMessage); | |
59 | 59 | } else { |
60 | 60 | stats.receiveRestResponse(d01,method,sendCmd,constant.ERROR); |
61 | 61 | var response = responseMsg.error(req,getCmd,50000); |
... | ... | @@ -66,7 +66,7 @@ exports.postCustomer = async function (req, res, next){ |
66 | 66 | } |
67 | 67 | } |
68 | 68 | |
69 | - log.logDetail.addOutput(req.body.clientName,method+"_"+getCmd,constant.RESPONSE,response,response); | |
69 | + log.logDetail.addOutput(req,req.body.clientName,method+"_"+getCmd,constant.RESPONSE,response,response); | |
70 | 70 | res.status(200).json(response); |
71 | 71 | next(); |
72 | 72 | }; | ... | ... |
ais-structure/src/modules/helper/connection.js
... | ... | @@ -173,8 +173,20 @@ connection.requestJsonToD01 = async function (req,obj,cmd,myMethod) { |
173 | 173 | } |
174 | 174 | |
175 | 175 | |
176 | - }else if(params.method == constants.METHOD.POST) | |
177 | - { | |
176 | + } else if(params.method == constants.METHOD.POST) { | |
177 | + params.body = JSON.stringify(params.body); | |
178 | + | |
179 | + var resultRes = await asyncRequest(params,objectData,funStats); | |
180 | + | |
181 | + if(resultRes.response){ | |
182 | + result.response = JSON.parse(resultRes.body); | |
183 | + } else { | |
184 | + result = resultRes; | |
185 | + } | |
186 | + } else if(params.method == constants.METHOD.PUT) { | |
187 | + | |
188 | + | |
189 | + | |
178 | 190 | params.body = JSON.stringify(params.body); |
179 | 191 | |
180 | 192 | var resultRes = await asyncRequest(params,objectData,funStats); |
... | ... | @@ -383,7 +395,7 @@ function getUrl(params,limit) |
383 | 395 | // console.log(fields); |
384 | 396 | |
385 | 397 | for(var i=0;i<returnData.length;i++) |
386 | - console.log("URL "+[i+1]+" : "+returnData[i]); | |
398 | + log.log("URL "+[i+1]+" : "+returnData[i]); | |
387 | 399 | |
388 | 400 | return returnData; |
389 | 401 | } | ... | ... |
ais-structure/src/modules/main.route.js
... | ... | @@ -49,28 +49,24 @@ module.exports = function (app) { |
49 | 49 | default: next(); |
50 | 50 | break; |
51 | 51 | } |
52 | - | |
53 | - | |
54 | - | |
55 | - | |
56 | 52 | }); |
57 | 53 | |
58 | 54 | function doVizcard(objectData) |
59 | 55 | { |
60 | - console.log("Route : "+objectData.pathname+" => doVizcard"); | |
56 | + log.log("Route : "+objectData.pathname+" => doVizcard"); | |
61 | 57 | objectData.next(); |
62 | 58 | } |
63 | 59 | |
64 | 60 | function doMembercards(objectData) |
65 | 61 | { |
66 | - console.log("Route : "+objectData.pathname+" => doMembercards"); | |
62 | + log.log("Route : "+objectData.pathname+" => doMembercards"); | |
67 | 63 | objectData.next(); |
68 | 64 | |
69 | 65 | } |
70 | 66 | |
71 | 67 | function doCustomers(objectData) |
72 | 68 | { |
73 | - console.log("Route : "+objectData.pathname+" => doCustomers"); | |
69 | + log.log("Route : "+objectData.pathname+" => doCustomers"); | |
74 | 70 | |
75 | 71 | // "/cmf/v1/customers/:customerId", |
76 | 72 | // "/cmf/v1/customers/:userType/:userData", |
... | ... | @@ -81,7 +77,7 @@ module.exports = function (app) { |
81 | 77 | if(objectData.method == constants.METHOD.GET) |
82 | 78 | objectData.modules.customerCtrl.customer(objectData.req,objectData.res,objectData.next); |
83 | 79 | else |
84 | - objectData.modules.postCustomerCtrl.customer(objectData.req,objectData.res,objectData.next); | |
80 | + objectData.modules.postCustomerCtrl.postCustomer(objectData.req,objectData.res,objectData.next); | |
85 | 81 | }; |
86 | 82 | |
87 | 83 | switch (objectData.splitPath.length) { | ... | ... |
ais-structure/src/modules/membercard/getMembership.ctrl.js
... | ... | @@ -23,22 +23,22 @@ exports.getMembership = async function (req, res, next) { |
23 | 23 | var customerId = req.query.clientName+"@"+req.query.commandId; |
24 | 24 | } |
25 | 25 | |
26 | - log.startlog(method+"_"+getCmd,req.query.commandId,customerId); | |
27 | - log.logDetail.addInput(req.query.clientName,method+"_"+getCmd,constant.REQUEST,req,req.body); | |
26 | + log.startlog(req,method+"_"+getCmd,req.query.commandId,customerId); | |
27 | + log.logDetail.addInput(req,req.query.clientName,method+"_"+getCmd,constant.REQUEST,req,req.body); | |
28 | 28 | |
29 | 29 | var err = validator(req,getCmd); |
30 | 30 | |
31 | 31 | if(err.length > 0) |
32 | 32 | { |
33 | - log.addErrorSummary(req.query.clientName,method+"_"+getCmd,"null","Fail"); | |
33 | + log.addErrorSummary(req,req.query.clientName,method+"_"+getCmd,"null","Fail"); | |
34 | 34 | log.log(err,'error'); |
35 | 35 | var response = responseMsg.error(req,getCmd,40300); |
36 | 36 | }else |
37 | 37 | { |
38 | - log.addSuccessSummary(req.query.clientName,method+"_"+getCmd,"null","Success"); | |
38 | + log.addSuccessSummary(req,req.query.clientName,method+"_"+getCmd,"null","Success"); | |
39 | 39 | var objectData = Object.assign(req.query,req.params); |
40 | - const result = await connection.requestJsonToD01(objectData,sendCusCmd,method); | |
41 | - log.logDetail.addInput(d01,method+"_"+sendCusCmd,constant.RESPONSE,result,result.response); | |
40 | + const result = await connection.requestJsonToD01(req,objectData,sendCusCmd,method); | |
41 | + log.logDetail.addInput(req,d01,method+"_"+sendCusCmd,constant.RESPONSE,result,result.response); | |
42 | 42 | |
43 | 43 | //Get Customer |
44 | 44 | if(typeof result.err === 'undefined'){ |
... | ... | @@ -47,23 +47,23 @@ exports.getMembership = async function (req, res, next) { |
47 | 47 | { |
48 | 48 | if(resultObj.resultData && resultObj.resultData.length>0) |
49 | 49 | { |
50 | - log.addSuccessSummary(d01,method+"_"+sendCusCmd,resultObj.resultCode,resultObj.resultDescription); | |
50 | + log.addSuccessSummary(req,d01,method+"_"+sendCusCmd,resultObj.resultCode,resultObj.resultDescription); | |
51 | 51 | var cusIdArr = []; |
52 | 52 | stats.receiveRestResponse(d01,method,sendCusCmd,constant.SUCCESS); |
53 | 53 | for(var i = 0; i < resultObj.resultData.length; i++){ |
54 | 54 | cusIdArr.push(resultObj.resultData[i].customerId) |
55 | 55 | } |
56 | 56 | objectData = {customerId : cusIdArr} |
57 | - const resultMemberCard = await connection.requestJsonToD01(objectData,sendMemCmd,method); | |
57 | + const resultMemberCard = await connection.requestJsonToD01(req,objectData,sendMemCmd,method); | |
58 | 58 | |
59 | 59 | //Get MemberCard handler |
60 | 60 | if(typeof resultMemberCard.err === 'undefined'){ |
61 | 61 | if(resultObj.resultCode.startsWith("2")){ |
62 | 62 | if(resultObj.resultData && resultObj.resultData.length>0){ |
63 | 63 | stats.receiveRestResponse(d01,method,sendMemCmd,constant.SUCCESS); |
64 | - log.logDetail.addInput(d01,method+"_"+sendCusCmd,constant.RESPONSE,resultMemberCard,resultMemberCard.response); | |
64 | + log.logDetail.addInput(req,d01,method+"_"+sendCusCmd,constant.RESPONSE,resultMemberCard,resultMemberCard.response); | |
65 | 65 | var resultMemberCardObj = resultMemberCard.response; |
66 | - log.addSuccessSummary(d01,method+"_"+sendMemCmd,resultMemberCardObj.resultCode,resultMemberCardObj.resultDescription); | |
66 | + log.addSuccessSummary(req,d01,method+"_"+sendMemCmd,resultMemberCardObj.resultCode,resultMemberCardObj.resultDescription); | |
67 | 67 | |
68 | 68 | for(var i = 0; i < resultObj.resultData.length; i++){ |
69 | 69 | for(var j = 0; j < resultMemberCardObj.resultData.length; j++){ |
... | ... | @@ -76,16 +76,16 @@ exports.getMembership = async function (req, res, next) { |
76 | 76 | } else { |
77 | 77 | stats.receiveRestResponse(d01,method,sendCusCmd,constant.RESPONSERESULT.DATA_NOT_FOUND.developerMessage); |
78 | 78 | var response = responseMsg.error(req,getCmd,40401); |
79 | - log.addErrorSummary(d01,method+"_"+sendCusCmd,response.resultCode,response.developerMessage); | |
79 | + log.addErrorSummary(req,d01,method+"_"+sendCusCmd,response.resultCode,response.developerMessage); | |
80 | 80 | } |
81 | 81 | } else if(resultObj.resultCode.startsWith("404")){ |
82 | 82 | stats.receiveRestResponse(d01,method,sendCusCmd,constant.RESPONSERESULT.DATA_NOT_FOUND.developerMessage); |
83 | 83 | var response = responseMsg.direct(req,getCmd,resultObj); |
84 | - log.addErrorSummary(d01,method+"_"+sendCusCmd,resultObj.resultCode,resultObj.developerMessage); | |
84 | + log.addErrorSummary(req,d01,method+"_"+sendCusCmd,resultObj.resultCode,resultObj.developerMessage); | |
85 | 85 | } else if(resultObj.resultCode.startsWith("5")){ |
86 | 86 | stats.receiveRestResponse(d01,method,sendCusCmd,constant.ERROR); |
87 | 87 | var response = responseMsg.direct(req,getCmd,resultObj); |
88 | - log.addErrorSummary(d01,method+"_"+sendCusCmd,resultObj.resultCode,resultObj.developerMessage); | |
88 | + log.addErrorSummary(req,d01,method+"_"+sendCusCmd,resultObj.resultCode,resultObj.developerMessage); | |
89 | 89 | } else { |
90 | 90 | stats.receiveRestResponse(d01,method,sendCusCmd,constant.ERROR); |
91 | 91 | var response = responseMsg.error(req,getCmd,50000); |
... | ... | @@ -100,16 +100,16 @@ exports.getMembership = async function (req, res, next) { |
100 | 100 | } else { |
101 | 101 | stats.receiveRestResponse(d01,method,sendCusCmd,constant.RESPONSERESULT.DATA_NOT_FOUND.developerMessage); |
102 | 102 | var response = responseMsg.error(req,getCmd,40300); |
103 | - log.addErrorSummary(d01,method+"_"+sendCusCmd,response.resultCode,response.developerMessage); | |
103 | + log.addErrorSummary(req,d01,method+"_"+sendCusCmd,response.resultCode,response.developerMessage); | |
104 | 104 | } |
105 | 105 | } else if(resultObj.resultCode.startsWith("404")){ |
106 | 106 | stats.receiveRestResponse(d01,method,sendMemCmd,constant.ERROR); |
107 | 107 | var response = responseMsg.direct(req,getCmd,resultObj); |
108 | - log.addErrorSummary(d01,method+"_"+sendMemCmd,resultObj.resultCode,resultObj.developerMessage); | |
108 | + log.addErrorSummary(req,d01,method+"_"+sendMemCmd,resultObj.resultCode,resultObj.developerMessage); | |
109 | 109 | } else if(resultObj.resultCode.startsWith("5")){ |
110 | 110 | stats.receiveRestResponse(d01,method,sendMemCmd,constant.ERROR); |
111 | 111 | var response = responseMsg.direct(req,getCmd,resultObj); |
112 | - log.addErrorSummary(d01,method+"_"+sendMemCmd,resultObj.resultCode,resultObj.developerMessage); | |
112 | + log.addErrorSummary(req,d01,method+"_"+sendMemCmd,resultObj.resultCode,resultObj.developerMessage); | |
113 | 113 | } else { |
114 | 114 | stats.receiveRestResponse(d01,method,sendMemCmd,constant.ERROR); |
115 | 115 | var response = responseMsg.error(req,getCmd,50000); |
... | ... | @@ -122,7 +122,7 @@ exports.getMembership = async function (req, res, next) { |
122 | 122 | } |
123 | 123 | |
124 | 124 | // console.log(response); |
125 | - log.logDetail.addOutput(req.query.clientName,method+"_"+getCmd,constant.RESPONSE,response,response); | |
125 | + log.logDetail.addOutput(req,req.query.clientName,method+"_"+getCmd,constant.RESPONSE,response,response); | |
126 | 126 | res.status(200).json(response); |
127 | 127 | next(); |
128 | 128 | }; | ... | ... |
ais-structure/src/modules/membercard/postMembership.ctrl.js
... | ... | @@ -26,19 +26,19 @@ exports.postMembership = async function (req, res, next){ |
26 | 26 | customerId = req.body.clientName+"@"+req.body.commandId; |
27 | 27 | } |
28 | 28 | |
29 | - log.startlog(postMethod+"_"+getCmd, req.body.commandId, customerId); | |
30 | - log.logDetail.addInput(req.body.clientName, postMethod+"_"+getCmd, constant.REQUEST, req, req.body); | |
29 | + log.startlog(req,postMethod+"_"+getCmd, req.body.commandId, customerId); | |
30 | + log.logDetail.addInput(req,req.body.clientName, postMethod+"_"+getCmd, constant.REQUEST, req, req.body); | |
31 | 31 | |
32 | 32 | var err = validator(req, getCmd); |
33 | 33 | |
34 | 34 | if(err.length > 0) |
35 | 35 | { |
36 | - log.addErrorSummary(req.body.clientName, postMethod+"_"+getCmd, "null", "Fail"); | |
36 | + log.addErrorSummary(req,req.body.clientName, postMethod+"_"+getCmd, "null", "Fail"); | |
37 | 37 | // console.log(err); |
38 | 38 | var response = responseMsg.error(req, getCmd, 40300); |
39 | 39 | }else |
40 | 40 | { |
41 | - log.addSuccessSummary(req.body.clientName, postMethod+"_"+getCmd, "null", "Success"); | |
41 | + log.addSuccessSummary(req,req.body.clientName, postMethod+"_"+getCmd, "null", "Success"); | |
42 | 42 | |
43 | 43 | var objectData = { |
44 | 44 | cardId : req.body.cardId, |
... | ... | @@ -47,8 +47,8 @@ exports.postMembership = async function (req, res, next){ |
47 | 47 | } |
48 | 48 | |
49 | 49 | //GET Customer with cardId and cardOwnerIdList |
50 | - const result = await connection.requestJsonToD01(objectData, sendMemberCardCmd, getMethod); | |
51 | - log.logDetail.addInput(d01, getMethod+"_"+sendMemberCardCmd, constant.RESPONSE, result, result.response); | |
50 | + const result = await connection.requestJsonToD01(req,objectData, sendMemberCardCmd, getMethod); | |
51 | + log.logDetail.addInput(req,d01, getMethod+"_"+sendMemberCardCmd, constant.RESPONSE, result, result.response); | |
52 | 52 | |
53 | 53 | var objDataGetCustomer = { |
54 | 54 | req : req, |
... | ... | @@ -61,13 +61,14 @@ exports.postMembership = async function (req, res, next){ |
61 | 61 | } |
62 | 62 | |
63 | 63 | var objDataMembership = { |
64 | + customerId : customerId, | |
64 | 65 | POST : { |
65 | 66 | req : req, |
66 | 67 | reqMembership : { |
67 | 68 | cardId : req.body.cardId, |
68 | 69 | cardOwnerIdList : [customerId] |
69 | 70 | }, |
70 | - cmd : sendCustomerCmd, | |
71 | + cmd : sendMemberCardCmd, | |
71 | 72 | method : postMethod, |
72 | 73 | resultData : result.response.resultData |
73 | 74 | }, |
... | ... | @@ -79,7 +80,7 @@ exports.postMembership = async function (req, res, next){ |
79 | 80 | cardOwnerIdList : customerId |
80 | 81 | } |
81 | 82 | }, |
82 | - cmd : sendCustomerCmd, | |
83 | + cmd : sendMemberCardCmd, | |
83 | 84 | method : putMethod, |
84 | 85 | resultData : result.response.resultData |
85 | 86 | } |
... | ... | @@ -92,49 +93,49 @@ exports.postMembership = async function (req, res, next){ |
92 | 93 | if(resultObj.resultData && resultObj.resultData.length>0){ |
93 | 94 | |
94 | 95 | stats.receiveRestResponse(d01,getMethod,sendMemberCardCmd,constant.SUCCESS); |
95 | - log.addSuccessSummary(d01,getMethod+"_"+sendMemberCardCmd,resultObj.resultCode,resultObj.resultDescription); | |
96 | + log.addSuccessSummary(req,d01,getMethod+"_"+sendMemberCardCmd,resultObj.resultCode,resultObj.resultDescription); | |
96 | 97 | |
97 | 98 | var todo = await checkOwnerCard(resultObj.resultData,objectData); |
98 | 99 | // console.log(todo); |
99 | 100 | if(todo){ |
100 | - var getCustomer = await getCustomerD01(objDataGetCustomer); | |
101 | + var getCustomer = await getCustomerD01(req, objDataGetCustomer); | |
101 | 102 | var response = await getCustomerHandler(req, getCustomer, resultObj, objDataMembership); |
102 | 103 | } else { |
103 | 104 | stats.receiveRestResponse(d01,getMethod,sendMemberCardCmd,constant.SUCCESS); |
104 | 105 | var response = responseMsg.direct(req,getCmd,constant.RESPONSECONN.MESSAGE.EXCEED); |
105 | - log.addSuccessSummary(d01, getMethod+"_"+sendMemberCardCmd, response.resultCode, response.developerMessage); | |
106 | + log.addSuccessSummary(req,d01, getMethod+"_"+sendMemberCardCmd, response.resultCode, response.developerMessage); | |
106 | 107 | } |
107 | 108 | |
108 | 109 | } else { //data not found |
109 | 110 | |
110 | 111 | stats.receiveRestResponse(d01,getMethod,sendMemberCardCmd,constant.RESPONSERESULT.DATA_NOT_FOUND.developerMessage); |
111 | - log.addSuccessSummary(d01,getMethod+"_"+sendMemberCardCmd,constant.RESPONSERESULT.DATA_NOT_FOUND.resultCode,constant.RESPONSERESULT.DATA_NOT_FOUND.developerMessage); | |
112 | + log.addSuccessSummary(req,d01,getMethod+"_"+sendMemberCardCmd,constant.RESPONSERESULT.DATA_NOT_FOUND.resultCode,constant.RESPONSERESULT.DATA_NOT_FOUND.developerMessage); | |
112 | 113 | |
113 | 114 | //get customer |
114 | 115 | |
115 | - var getCustomer = await getCustomerD01(objDataGetCustomer); | |
116 | + var getCustomer = await getCustomerD01(req, objDataGetCustomer); | |
116 | 117 | var response = await getCustomerHandler(req, getCustomer, resultObj, objDataMembership); |
117 | 118 | } |
118 | 119 | } else if(resultObj.resultCode.startsWith("404")){ //data not found |
119 | 120 | //get customer |
120 | - var getCustomer = await getCustomerD01(objDataGetCustomer); | |
121 | + var getCustomer = await getCustomerD01(req, objDataGetCustomer); | |
121 | 122 | var response = await getCustomerHandler(req, getCustomer, resultObj, objDataMembership); |
122 | 123 | |
123 | 124 | } else if(resultObj.resultCode.startsWith("5")){ |
124 | 125 | stats.receiveRestResponse(d01, getMethod, sendMemberCardCmd, constant.ERROR); |
125 | 126 | var response = responseMsg.direct(req, getCmd, resultObj); |
126 | - log.addErrorSummary(d01, getMethod+"_"+sendMemberCardCmd, resultObj.resultCode, resultObj.developerMessage); | |
127 | + log.addErrorSummary(req,d01, getMethod+"_"+sendMemberCardCmd, resultObj.resultCode, resultObj.developerMessage); | |
127 | 128 | } else { |
128 | 129 | stats.receiveRestResponse(d01, getMethod, sendMemberCardCmd, constant.ERROR); |
129 | 130 | var response = responseMsg.error(req, getCmd, 50000); |
130 | 131 | } |
131 | 132 | } else { |
132 | - stats.receiveRestResponse(d01,method,sendCusCmd,constant.ERROR); | |
133 | + stats.receiveRestResponse(d01,getMethod,sendCusCmd,constant.ERROR); | |
133 | 134 | var response = responseMsg.error(req,getCmd,50000); |
134 | 135 | } |
135 | 136 | } |
136 | 137 | |
137 | - log.logDetail.addOutput(req.body.clientName, postMethod+"_"+getCmd, constant.RESPONSE, response, response); | |
138 | + log.logDetail.addOutput(req,req.body.clientName, postMethod+"_"+getCmd, constant.RESPONSE, response, response); | |
138 | 139 | res.status(200).json(response); |
139 | 140 | next(); |
140 | 141 | }; |
... | ... | @@ -161,7 +162,7 @@ function validator(req, api) |
161 | 162 | return err; |
162 | 163 | } |
163 | 164 | |
164 | -async function getCustomerD01(data){ | |
165 | +async function getCustomerD01(req, data){ | |
165 | 166 | |
166 | 167 | var responseData = { |
167 | 168 | isErr : false, |
... | ... | @@ -169,7 +170,7 @@ async function getCustomerD01(data){ |
169 | 170 | isDirect : false |
170 | 171 | }; |
171 | 172 | |
172 | - const resultCustomer = await connection.requestJsonToD01(data.reqCustomer, data.cmd, data.method); | |
173 | + const resultCustomer = await connection.requestJsonToD01(req, data.reqCustomer, data.cmd, data.method); | |
173 | 174 | var resultObj = resultCustomer.response |
174 | 175 | |
175 | 176 | if(typeof resultCustomer.err === 'undefined'){ |
... | ... | @@ -195,7 +196,7 @@ async function getCustomerD01(data){ |
195 | 196 | return responseData; |
196 | 197 | } |
197 | 198 | |
198 | -async function postMemberCardD01(data){ | |
199 | +async function postMemberCardD01(req, data){ | |
199 | 200 | |
200 | 201 | var responseData = { |
201 | 202 | isErr : false, |
... | ... | @@ -203,7 +204,9 @@ async function postMemberCardD01(data){ |
203 | 204 | isDirect : false |
204 | 205 | }; |
205 | 206 | |
206 | - const resultCustomer = await connection.requestJsonToD01(data.reqMembership, data.cmd, data.method); | |
207 | + // console.log(data) | |
208 | + | |
209 | + const resultCustomer = await connection.requestJsonToD01(req,data.reqMembership, data.cmd, data.method); | |
207 | 210 | var resultObj = resultCustomer.response |
208 | 211 | |
209 | 212 | if(typeof resultCustomer.err === 'undefined'){ |
... | ... | @@ -232,23 +235,58 @@ async function getCustomerHandler(req, getCustomer, getMemberCard, objDataMember |
232 | 235 | if(!getCustomer.isDataNotFound){ |
233 | 236 | //post membercard |
234 | 237 | stats.receiveRestResponse(d01, getMethod, sendCustomerCmd, constant.SUCCESS); |
235 | - log.addSuccessSummary(d01, getMethod+"_"+sendCustomerCmd, getCustomer.response.resultCode, getCustomer.response.resultDescription); | |
236 | - | |
238 | + log.addSuccessSummary(req,d01, getMethod+"_"+sendCustomerCmd, getCustomer.response.resultCode, getCustomer.response.resultDescription); | |
237 | 239 | |
238 | 240 | //check post or put |
239 | - | |
240 | - var postMemberCard = await postMemberCardD01(objDataMembership.POST); | |
241 | - var response = await postMemberCardHandler(req, postMemberCard) | |
242 | 241 | |
242 | + function getResultTodo(req, getMemberCard, objDataMembership){ | |
243 | + | |
244 | + var result = { | |
245 | + doPost : true, | |
246 | + doNothing : false | |
247 | + } | |
248 | + | |
249 | + for(var i = 0 ; i < getMemberCard.resultData.length ; i++){ | |
250 | + if(req.body.cardId === getMemberCard.resultData[i].cardId){ | |
251 | + if(getMemberCard.resultData[i].cardOwnerIdList.includes(objDataMembership.customerId)){ | |
252 | + result.doNothing = true; | |
253 | + break; | |
254 | + } else { | |
255 | + result.doPost = false; | |
256 | + break; | |
257 | + } | |
258 | + } else if(i == getMemberCard.resultData.length-1){ | |
259 | + result.doPost = true; | |
260 | + break; | |
261 | + } | |
262 | + } | |
263 | + | |
264 | + return result; | |
265 | + } | |
266 | + | |
267 | + var getResult = await getResultTodo(req, getMemberCard, objDataMembership); | |
268 | + | |
269 | + if(getResult.doNothing){ | |
270 | + var response = responseMsg.success(req,getCmd) | |
271 | + } else { | |
272 | + if(getResult.doPost){ | |
273 | + var postMemberCard = await postMemberCardD01(req, objDataMembership.POST); | |
274 | + var response = await postMemberCardHandler(req, postMemberCard) | |
275 | + } else { | |
276 | + var putMemberCard = await postMemberCardD01(req, objDataMembership.PUT); | |
277 | + var response = await postMemberCardHandler(req, putMemberCard) | |
278 | + } | |
279 | + } | |
280 | + | |
243 | 281 | } else { |
244 | 282 | stats.receiveRestResponse(d01, getMethod, sendCustomerCmd, constant.RESPONSERESULT.DATA_NOT_FOUND.resultDescription); |
245 | 283 | var response = responseMsg.error(req, getCmd, 40401); |
246 | - log.addErrorSummary(d01, getMethod+"_"+sendCustomerCmd, response.resultCode, response.resultDescription); | |
284 | + log.addErrorSummary(req,d01, getMethod+"_"+sendCustomerCmd, response.resultCode, response.resultDescription); | |
247 | 285 | } |
248 | 286 | } else if(getCustomer.isDirect){ |
249 | 287 | stats.receiveRestResponse(d01, getMethod, sendCustomerCmd, constant.ERROR); |
250 | 288 | var response = responseMsg.direct(req, getCmd, getCustomer.response); |
251 | - log.addErrorSummary(d01, getMethod+"_"+sendCustomerCmd, getCustomer.response.resultCode, getCustomer.response.resultDescription); | |
289 | + log.addErrorSummary(req,d01, getMethod+"_"+sendCustomerCmd, getCustomer.response.resultCode, getCustomer.response.resultDescription); | |
252 | 290 | } else { |
253 | 291 | stats.receiveRestResponse(d01, getMethod, sendCustomerCmd, constant.ERROR); |
254 | 292 | var response = responseMsg.error(req, getCmd, 50000); |
... | ... | @@ -263,11 +301,11 @@ async function postMemberCardHandler(req, memberCard){ |
263 | 301 | if(!memberCard.isErr){ |
264 | 302 | stats.receiveRestResponse(d01, postMethod, sendMemberCardCmd, constant.SUCCESS); |
265 | 303 | var response = responseMsg.direct(req, getCmd, memberCard.response); |
266 | - log.addSuccessSummary(d01, postMethod+"_"+sendMemberCardCmd, response.resultCode, response.developerMessage); | |
267 | - } else if(getCustomer.isDirect){ | |
304 | + log.addSuccessSummary(req,d01, postMethod+"_"+sendMemberCardCmd, response.resultCode, response.developerMessage); | |
305 | + } else if(memberCard.isDirect){ | |
268 | 306 | stats.receiveRestResponse(d01, postMethod, sendMemberCardCmd, constant.ERROR); |
269 | 307 | var response = responseMsg.direct(req, getCmd, memberCard.response); |
270 | - log.addErrorSummary(d01, postMethod+"_"+sendMemberCardCmd, memberCard.response.resultCode, memberCard.response.developerMessage); | |
308 | + log.addErrorSummary(req,d01, postMethod+"_"+sendMemberCardCmd, memberCard.response.resultCode, memberCard.response.developerMessage); | |
271 | 309 | } else { |
272 | 310 | stats.receiveRestResponse(d01, postMethod, sendMemberCardCmd, constant.ERROR); |
273 | 311 | var response = responseMsg.error(req, getCmd, 50000); | ... | ... |
ais-structure/src/modules/vizcard/vizCard.ctrl.js
... | ... | @@ -43,7 +43,7 @@ exports.vizcard = async function (req, res, next) { |
43 | 43 | moblieNo : req.query.moblieNo |
44 | 44 | }; |
45 | 45 | |
46 | - const result = await connection.requestSoapToSACF(objectData,sendCmd,constant.METHOD.POST); | |
46 | + const result = await connection.requestSoapToSACF(req,objectData,sendCmd,constant.METHOD.POST); | |
47 | 47 | // console.log(result.err) |
48 | 48 | |
49 | 49 | if(typeof result.err === 'undefined'){ |
... | ... | @@ -70,14 +70,12 @@ exports.vizcard = async function (req, res, next) { |
70 | 70 | } else { |
71 | 71 | stats.receiveSACFResponse(sacf,sendCmd,"Error"); |
72 | 72 | response = responseMsg.error(req,getCmd,50000); |
73 | - // log.addErrorSummary(sacf,method+"_"+sendCmd,response.resultCode,response.developerMessage); | |
74 | 73 | var resultSet = {rawDataJson : ""} |
75 | 74 | } |
76 | 75 | |
77 | 76 | log.logDetail.addInput(req,sacf,method+"_"+sendCmd,constant.RESPONSE,result,resultSet.rawDataJson); |
78 | 77 | } |
79 | 78 | |
80 | - // console.log(response); | |
81 | 79 | log.logDetail.addOutput(req,sacf,method+"_"+getCmd,constant.RESPONSE,response,response); |
82 | 80 | res.status(200).json(response); |
83 | 81 | next(); | ... | ... |