diff --git a/ais-structure/src/modules/helper/constants.js b/ais-structure/src/modules/helper/constants.js index 1dc5e61..0b16233 100644 --- a/ais-structure/src/modules/helper/constants.js +++ b/ais-structure/src/modules/helper/constants.js @@ -37,6 +37,10 @@ module.exports = Object.freeze({ SUCCESS:{ resultCode : '20000', resultDescription : 'Success' + }, + EXCEED:{ + resultCode : '40302', + resultDescription : 'Exceed data allowances' } } }, diff --git a/ais-structure/src/modules/helper/log.js b/ais-structure/src/modules/helper/log.js index 9f8f790..42f4774 100644 --- a/ais-structure/src/modules/helper/log.js +++ b/ais-structure/src/modules/helper/log.js @@ -247,43 +247,43 @@ logger.endEC = function(res) messageRes += newLine+"Use times : "+Math.abs(endTime - startTime)+" ms"; - messageRes += ` - ________________________________________________________________________________________________________________________ - __________#####___________________________________#####___________________________________#####_________________________ - _________##____#_________________________________##____#_________________________________##____#________________________ - ________##______#_______________________________##______#_______________________________##______#_______________________ - ________#________#______________________________#________#______________________________#________#______________________ - _________________#######_________________________________#######_________________________________#######________________ - _________________#########_______________________________#########_______________________________#########______________ - __________##_____###########______________________##_____###########______________________##_____###########____________ - ___________#_____#############_____________________#_____#############_____________________#_____#############__________ - _________________##############___###____________________##############___###____________________##############___###___ - _______##________###############_##_##_________##________###############_##_##_________##________###############_##_##__ - ______###_______#################____#________###_______#################____#________###_______#################____#__ - ____#######___##________#########____#______#######___##________#########____#______#######___##________#########____#__ - ___#___####___#______________###_____#_____#___####___#______________###_____#_____#___####___#______________###_____#__ - ___#___##______#__#__________________#_____#___##______#__#__________________#_____#___##______#__#__________________#__ - ___#_________________________________#_____#_________________________________#_____#_________________________________#__ - ___#______________##_________________#_____#______________##_________________#_____#______________##_________________#__ - __#___________#_________________#___#_____#___________#_________________#___#_____#___________#_________________#___#___ - ___#__________#________________###__#______#__________#________________###__#______#__________#________________###__#___ - ____##_______#_________________#_###________##_______#_________________#_###________##_______#_________________#_###____ - _____#________________________##_____________#________________________##_____________#________________________##________ - _____#________________________#______________#________________________#______________#________________________#_________ - _____#_______________________#_______________#_______________________#_______________#_______________________#__________ - _____#______________________##_______________#______________________##_______________#______________________##__________ - _____##_____________________#________________##_____________________#________________##_____________________#___________ - ______#____________________#__________________#____________________#__________________#____________________#____________ - ______#___________________#___________________#___________________#___________________#___________________#_____________ - _______#_________________#_____________________#_________________#_____________________#_________________#______________ - _______##_______________#______________________##_______________#______________________##_______________#_______________ - ________##____________##________________________##____________##________________________##____________##________________ - __________##________###___________________________##________###___________________________##________###_________________ - ____________#########_______________________________#########_______________________________#########___________________ - ________________________________________________________________________________________________________________________ + // messageRes += ` + // ________________________________________________________________________________________________________________________ + // __________#####___________________________________#####___________________________________#####_________________________ + // _________##____#_________________________________##____#_________________________________##____#________________________ + // ________##______#_______________________________##______#_______________________________##______#_______________________ + // ________#________#______________________________#________#______________________________#________#______________________ + // _________________#######_________________________________#######_________________________________#######________________ + // _________________#########_______________________________#########_______________________________#########______________ + // __________##_____###########______________________##_____###########______________________##_____###########____________ + // ___________#_____#############_____________________#_____#############_____________________#_____#############__________ + // _________________##############___###____________________##############___###____________________##############___###___ + // _______##________###############_##_##_________##________###############_##_##_________##________###############_##_##__ + // ______###_______#################____#________###_______#################____#________###_______#################____#__ + // ____#######___##________#########____#______#######___##________#########____#______#######___##________#########____#__ + // ___#___####___#______________###_____#_____#___####___#______________###_____#_____#___####___#______________###_____#__ + // ___#___##______#__#__________________#_____#___##______#__#__________________#_____#___##______#__#__________________#__ + // ___#_________________________________#_____#_________________________________#_____#_________________________________#__ + // ___#______________##_________________#_____#______________##_________________#_____#______________##_________________#__ + // __#___________#_________________#___#_____#___________#_________________#___#_____#___________#_________________#___#___ + // ___#__________#________________###__#______#__________#________________###__#______#__________#________________###__#___ + // ____##_______#_________________#_###________##_______#_________________#_###________##_______#_________________#_###____ + // _____#________________________##_____________#________________________##_____________#________________________##________ + // _____#________________________#______________#________________________#______________#________________________#_________ + // _____#_______________________#_______________#_______________________#_______________#_______________________#__________ + // _____#______________________##_______________#______________________##_______________#______________________##__________ + // _____##_____________________#________________##_____________________#________________##_____________________#___________ + // ______#____________________#__________________#____________________#__________________#____________________#____________ + // ______#___________________#___________________#___________________#___________________#___________________#_____________ + // _______#_________________#_____________________#_________________#_____________________#_________________#______________ + // _______##_______________#______________________##_______________#______________________##_______________#_______________ + // ________##____________##________________________##____________##________________________##____________##________________ + // __________##________###___________________________##________###___________________________##________###_________________ + // ____________#########_______________________________#########_______________________________#########___________________ + // ________________________________________________________________________________________________________________________ - ________________________________________________________________________________________________________________________ - `; + // ________________________________________________________________________________________________________________________ + // `; logger.log(messageRes); messageRes += newLine diff --git a/ais-structure/src/modules/helper/responseMsg.js b/ais-structure/src/modules/helper/responseMsg.js index d3dfba1..9f3a695 100644 --- a/ais-structure/src/modules/helper/responseMsg.js +++ b/ais-structure/src/modules/helper/responseMsg.js @@ -7,7 +7,7 @@ responseMsg.error = function (req,cmd,code){ // var devMsg = "System error"; var response; - switch(code) { + switch(code) { case 40300: response = constants.RESPONSERESULT.MISSING_INVALID break; @@ -49,8 +49,6 @@ responseMsg.direct = function (req,cmd,result,data) developerMessage : result.resultDescription }; - - if(result.resultCode == constants.RESPONSERESULT.SUCCESS.resultCode) { stats.sendResponse(req.method,cmd,constants.SUCCESS); diff --git a/ais-structure/src/modules/membercard/getMembership.ctrl.js b/ais-structure/src/modules/membercard/getMembership.ctrl.js index 43fe844..fbe604a 100644 --- a/ais-structure/src/modules/membercard/getMembership.ctrl.js +++ b/ais-structure/src/modules/membercard/getMembership.ctrl.js @@ -79,40 +79,39 @@ exports.getMembership = async function (req, res, next) { log.addErrorSummary(d01,method+"_"+sendCusCmd,response.resultCode,response.developerMessage); } } else if(resultObj.resultCode.startsWith("404")){ - stats.receiveRestResponse(d01,method,sendCmd,constant.RESPONSERESULT.DATA_NOT_FOUND.developerMessage); + stats.receiveRestResponse(d01,method,sendCusCmd,constant.RESPONSERESULT.DATA_NOT_FOUND.developerMessage); var response = responseMsg.direct(req,getCmd,resultObj); - log.addErrorSummary(d01,method+"_"+sendCmd,resultObj.resultCode,resultObj.developerMessage); + log.addErrorSummary(d01,method+"_"+sendCusCmd,resultObj.resultCode,resultObj.developerMessage); } else if(resultObj.resultCode.startsWith("5")){ - stats.receiveRestResponse(d01,method,sendCmd,constant.ERROR); + stats.receiveRestResponse(d01,method,sendCusCmd,constant.ERROR); var response = responseMsg.direct(req,getCmd,resultObj); - log.addErrorSummary(d01,method+"_"+sendCmd,resultObj.resultCode,resultObj.developerMessage); + log.addErrorSummary(d01,method+"_"+sendCusCmd,resultObj.resultCode,resultObj.developerMessage); } else { - stats.receiveRestResponse(d01,method,sendCmd,constant.ERROR); + stats.receiveRestResponse(d01,method,sendCusCmd,constant.ERROR); var response = responseMsg.error(req,getCmd,50000); } } else { stats.receiveRestResponse(d01,method,sendCusCmd,constant.ERROR); - var response = responseMsg.direct(req,getCmd,resultObj); - log.addErrorSummary(d01,method+"_"+sendCusCmd,resultObj.resultCode,resultObj.developerMessage); + var response = responseMsg.error(req,getCmd,50000); + // log.addErrorSummary(d01,method+"_"+sendCusCmd,resultObj.resultCode,resultObj.developerMessage); }//End get MemberCard - }else - { + } else { stats.receiveRestResponse(d01,method,sendCusCmd,constant.RESPONSERESULT.DATA_NOT_FOUND.developerMessage); var response = responseMsg.error(req,getCmd,40300); log.addErrorSummary(d01,method+"_"+sendCusCmd,response.resultCode,response.developerMessage); } } else if(resultObj.resultCode.startsWith("404")){ - stats.receiveRestResponse(d01,method,sendCmd,constant.ERROR); + stats.receiveRestResponse(d01,method,sendMemCmd,constant.ERROR); var response = responseMsg.direct(req,getCmd,resultObj); - log.addErrorSummary(d01,method+"_"+sendCmd,resultObj.resultCode,resultObj.developerMessage); + log.addErrorSummary(d01,method+"_"+sendMemCmd,resultObj.resultCode,resultObj.developerMessage); } else if(resultObj.resultCode.startsWith("5")){ - stats.receiveRestResponse(d01,method,sendCmd,constant.ERROR); + stats.receiveRestResponse(d01,method,sendMemCmd,constant.ERROR); var response = responseMsg.direct(req,getCmd,resultObj); - log.addErrorSummary(d01,method+"_"+sendCmd,resultObj.resultCode,resultObj.developerMessage); + log.addErrorSummary(d01,method+"_"+sendMemCmd,resultObj.resultCode,resultObj.developerMessage); } else { - stats.receiveRestResponse(d01,method,sendCmd,constant.ERROR); + stats.receiveRestResponse(d01,method,sendMemCmd,constant.ERROR); var response = responseMsg.error(req,getCmd,50000); } } else { diff --git a/ais-structure/src/modules/membercard/postMembership.ctrl.js b/ais-structure/src/modules/membercard/postMembership.ctrl.js index 2e1925e..0012edf 100644 --- a/ais-structure/src/modules/membercard/postMembership.ctrl.js +++ b/ais-structure/src/modules/membercard/postMembership.ctrl.js @@ -4,175 +4,172 @@ var connection = require('../helper/connection.js'); var responseMsg = require('../helper/responseMsg.js'); var log = require('../helper/log.js'); var constant = require('../helper/constants.js') +var env = process.env.NODE_ENV || 'development'; +var cfg = require('../../config/config.js').get(env); -exports.postMembership = async function (req, res, next){ - var getCmd = "CustomerMembership"; - var sendCustomerCmd = "Customer"; - var sendMemberCardCmd = "MemberCard"; - var d01 = "D01"; - var postMethod = constant.METHOD.POST; - var putMethod = constant.METHOD.PUT; - var getMethod = constant.METHOD.GET; +const getCmd = "CustomerMembership"; +const sendCustomerCmd = "Customer"; +const sendMemberCardCmd = "MemberCard"; +const d01 = "D01"; +const postMethod = constant.METHOD.POST; +const putMethod = constant.METHOD.PUT; +const getMethod = constant.METHOD.GET; +exports.postMembership = async function (req, res, next){ + + var customerId; if(req.params.customerId){ - var customerId = req.params.customerId + customerId = req.params.customerId } else if(req.params.userData && req.params.userType){ - var customerId = req.params.userData+"@"+req.params.userType + customerId = req.params.userData+"@"+req.params.userType } else if(req.body.clientName && req.body.commandId){ - var customerId = req.body.clientName+"@"+req.body.commandId; + customerId = req.body.clientName+"@"+req.body.commandId; } - log.startlog(postMethod+"_"+getCmd,req.body.commandId,customerId); - log.logDetail.addInput(req.body.clientName,postMethod+"_"+getCmd,constant.REQUEST,req,req.body); + log.startlog(postMethod+"_"+getCmd, req.body.commandId, customerId); + log.logDetail.addInput(req.body.clientName, postMethod+"_"+getCmd, constant.REQUEST, req, req.body); - var err = validator(req,getCmd); + var err = validator(req, getCmd); if(err.length > 0) { - log.addErrorSummary(req.body.clientName,postMethod+"_"+getCmd,"null","Fail"); - console.log(err); - var response = responseMsg.error(req,getCmd,40300); + log.addErrorSummary(req.body.clientName, postMethod+"_"+getCmd, "null", "Fail"); + // console.log(err); + var response = responseMsg.error(req, getCmd, 40300); }else { - log.addSuccessSummary(req.body.clientName,postMethod+"_"+getCmd,"null","Success"); + log.addSuccessSummary(req.body.clientName, postMethod+"_"+getCmd, "null", "Success"); var objectData = { - cardId : req.body.cardId, + cardId : req.body.cardId, cardOwnerIdList : customerId // _flag : "or" } //GET Customer with cardId and cardOwnerIdList - const result = await connection.requestJsonToD01(objectData,sendMemberCardCmd,getMethod); - log.logDetail.addInput(d01,getMethod+"_"+sendMemberCardCmd,constant.RESPONSE,result,result.response); + const result = await connection.requestJsonToD01(objectData, sendMemberCardCmd, getMethod); + log.logDetail.addInput(d01, getMethod+"_"+sendMemberCardCmd, constant.RESPONSE, result, result.response); var objDataGetCustomer = { - req : req, + req : req, reqCustomer : { customerId : customerId - }, - cmd : sendCustomerCmd, - method : getMethod, + }, + cmd : sendCustomerCmd, + method : getMethod, resultData : result.response.resultData } - var objDataPostCustomer = { - req : req, - reqCustomer : { - cardId : req.body.cardId, - cardOwnerIdList:[customerId] - }, - cmd : sendCustomerCmd, - method : postMethod, - resultData : result.response.resultData + var objDataMembership = { + POST : { + req : req, + reqMembership : { + cardId : req.body.cardId, + cardOwnerIdList : [customerId] + }, + cmd : sendCustomerCmd, + method : postMethod, + resultData : result.response.resultData + }, + PUT : { + req : req, + reqMembership : { + // {"add":{"@cardOwnerIdList":"testAddedCard"}} + add : { + cardOwnerIdList : customerId + } + }, + cmd : sendCustomerCmd, + method : putMethod, + resultData : result.response.resultData + } + } if(typeof result.err === 'undefined'){ var resultObj = result.response; if(resultObj.resultCode.startsWith("2")){ if(resultObj.resultData && resultObj.resultData.length>0){ + stats.receiveRestResponse(d01,getMethod,sendMemberCardCmd,constant.SUCCESS); - var response = responseMsg.success(req,getCmd,resultObj); - log.addSuccessSummary(d01,getMethod+"_"+sendMemberCardCmd,response.resultCode,response.developerMessage); - } else { //data not found - //get customer - var getCustomer = await getCustomerD01(objDataGetCustomer); - //if get data exits post membercard - if(!getCustomer.isErr){ - if(!getCustomer.isDataNotFound){ - //post membercard - stats.receiveRestResponse(d01,getMethod,sendCustomerCmd,constant.SUCCESS); - log.addSuccessSummary(d01,getMethod+"_"+sendCustomerCmd,getCustomer.response.resultCode,getCustomer.response.developerMessage); - - var postCustomer = await postCustomerD01(objDataPostCustomer); - - if(!postCustomer.isErr){ - stats.receiveRestResponse(d01,postMethod,sendCustomerCmd,constant.SUCCESS); - var response = responseMsg.direct(req,getCmd,postCustomer.response); - log.addSuccessSummary(d01,postMethod+"_"+sendCustomerCmd,response.resultCode,response.developerMessage); - } else if(getCustomer.isDirect){ - stats.receiveRestResponse(d01,method,sendCustomerCmd,constant.ERROR); - var response = responseMsg.direct(req,getCmd,getCustomer.response); - log.addErrorSummary(d01,method+"_"+sendCmd,getCustomer.response.resultCode,getCustomer.response.developerMessage); - } else { - stats.receiveRestResponse(d01,method,sendCmd,constant.ERROR); - var response = responseMsg.error(req,getCmd,50000); - } - - } else { - stats.receiveRestResponse(d01,method,sendCmd,constant.RESPONSERESULT.DATA_NOT_FOUND.developerMessage); - var response = responseMsg.error(req,getCmd,40401); - log.addErrorSummary(d01,method+"_"+sendCmd,response.resultCode,response.developerMessage); - } - } else if(getCustomer.isDirect){ - stats.receiveRestResponse(d01,method,sendCmd,constant.ERROR); - var response = responseMsg.direct(req,getCmd,getCustomer.response); - log.addErrorSummary(d01,method+"_"+sendCmd,getCustomer.response.resultCode,getCustomer.response.developerMessage); + log.addSuccessSummary(d01,getMethod+"_"+sendMemberCardCmd,resultObj.resultCode,resultObj.resultDescription); + + var todo = await checkOwnerCard(resultObj.resultData,objectData); + // console.log(todo); + if(todo){ + var getCustomer = await getCustomerD01(objDataGetCustomer); + var response = await getCustomerHandler(req, getCustomer, resultObj, objDataMembership); } else { - stats.receiveRestResponse(d01,method,sendCmd,constant.ERROR); - var response = responseMsg.error(req,getCmd,50000); + stats.receiveRestResponse(d01,getMethod,sendMemberCardCmd,constant.SUCCESS); + var response = responseMsg.direct(req,getCmd,constant.RESPONSECONN.MESSAGE.EXCEED); + log.addSuccessSummary(d01, getMethod+"_"+sendMemberCardCmd, response.resultCode, response.developerMessage); } - //else end flow + + } else { //data not found + + stats.receiveRestResponse(d01,getMethod,sendMemberCardCmd,constant.RESPONSERESULT.DATA_NOT_FOUND.developerMessage); + log.addSuccessSummary(d01,getMethod+"_"+sendMemberCardCmd,constant.RESPONSERESULT.DATA_NOT_FOUND.resultCode,constant.RESPONSERESULT.DATA_NOT_FOUND.developerMessage); + + //get customer + var getCustomer = await getCustomerD01(objDataGetCustomer); + var response = await getCustomerHandler(req, getCustomer, resultObj, objDataMembership); } - } else if(resultObj.resultCode.startsWith("404")){ + } else if(resultObj.resultCode.startsWith("404")){ //data not found //get customer - //if get data exits post member card - //else end flow - stats.receiveRestResponse(d01,method,sendCmd,constant.ERROR); - var response = responseMsg.direct(req,getCmd,resultObj); - log.addErrorSummary(d01,method+"_"+sendCmd,resultObj.resultCode,resultObj.developerMessage); + var getCustomer = await getCustomerD01(objDataGetCustomer); + var response = await getCustomerHandler(req, getCustomer, resultObj, objDataMembership); + } else if(resultObj.resultCode.startsWith("5")){ - stats.receiveRestResponse(d01,method,sendCmd,constant.ERROR); - var response = responseMsg.direct(req,getCmd,resultObj); - log.addErrorSummary(d01,method+"_"+sendCmd,resultObj.resultCode,resultObj.developerMessage); + stats.receiveRestResponse(d01, getMethod, sendMemberCardCmd, constant.ERROR); + var response = responseMsg.direct(req, getCmd, resultObj); + log.addErrorSummary(d01, getMethod+"_"+sendMemberCardCmd, resultObj.resultCode, resultObj.developerMessage); } else { - stats.receiveRestResponse(d01,method,sendCmd,constant.ERROR); - var response = responseMsg.error(req,getCmd,50000); + stats.receiveRestResponse(d01, getMethod, sendMemberCardCmd, constant.ERROR); + var response = responseMsg.error(req, getCmd, 50000); } } else { - stats.receiveRestResponse(d01,constant.METHOD.POST,sendCmd,"Error"); - var response = responseMsg.direct(req,getCmd,result.response); - log.addErrorSummary(d01,method+"_"+sendCmd,response); + stats.receiveRestResponse(d01,method,sendCusCmd,constant.ERROR); + var response = responseMsg.error(req,getCmd,50000); } } - log.logDetail.addOutput(req.body.clientName,postMethod+"_"+getCmd,constant.RESPONSE,response,response); + log.logDetail.addOutput(req.body.clientName, postMethod+"_"+getCmd, constant.RESPONSE, response, response); res.status(200).json(response); next(); }; -function validator(req,api) +function validator(req, api) { // console.log(req.body); var list = []; - list.push([true,"body","commandId","int"]); - list.push([true,"body","clientName","string"]); - list.push([true,"body","cardId","string"]); - // list.push([true,"body","clientName","string"]); - // list.push([true,"body","firstName","string"]); - // list.push([true,"body","lastName","string"]); - // list.push([true,"body","mobile","string"]); - // list.push([true,"body","emailAddress","string"]); - var err = validatorHelper(req,list,api) + list.push([true, "body", "commandId", "int"]); + list.push([true, "body", "clientName", "string"]); + list.push([true, "body", "cardId", "string"]); + // list.push([true, "body", "clientName", "string"]); + // list.push([true, "body", "firstName", "string"]); + // list.push([true, "body", "lastName", "string"]); + // list.push([true, "body", "mobile", "string"]); + // list.push([true, "body", "emailAddress", "string"]); + var err = validatorHelper(req, list, api) if(err.length > 0) - stats.receiveBadRequest(req.method,api); + stats.receiveBadRequest(req.method, api); else - stats.receiveRequest(req.method,api); + stats.receiveRequest(req.method, api); return err; } -var getCustomerD01 = async function(data){ +async function getCustomerD01(data){ var responseData = { - isErr : false, - isDataNotFound : false, + isErr : false, + isDataNotFound : false, isDirect : false }; - const resultCustomer = await connection.requestJsonToD01(data.reqCustomer,data.cmd,data.method); + const resultCustomer = await connection.requestJsonToD01(data.reqCustomer, data.cmd, data.method); var resultObj = resultCustomer.response if(typeof resultCustomer.err === 'undefined'){ @@ -198,15 +195,15 @@ var getCustomerD01 = async function(data){ return responseData; } -var postCustomerD01 = async function(data){ +async function postMemberCardD01(data){ var responseData = { - isErr : false, - isDataNotFound : false, + isErr : false, + isDataNotFound : false, isDirect : false }; - const resultCustomer = await connection.requestJsonToD01(data.reqCustomer,data.cmd,data.method); + const resultCustomer = await connection.requestJsonToD01(data.reqMembership, data.cmd, data.method); var resultObj = resultCustomer.response if(typeof resultCustomer.err === 'undefined'){ @@ -225,4 +222,93 @@ var postCustomerD01 = async function(data){ } return responseData; -} \ No newline at end of file +} + +async function getCustomerHandler(req, getCustomer, getMemberCard, objDataMembership){ + + // console.log(getCustomer.response) + if(!getCustomer.isErr){ + //if get data exits post membercard + if(!getCustomer.isDataNotFound){ + //post membercard + stats.receiveRestResponse(d01, getMethod, sendCustomerCmd, constant.SUCCESS); + log.addSuccessSummary(d01, getMethod+"_"+sendCustomerCmd, getCustomer.response.resultCode, getCustomer.response.resultDescription); + + + //check post or put + + var postMemberCard = await postMemberCardD01(objDataMembership.POST); + var response = await postMemberCardHandler(req, postMemberCard) + + } else { + stats.receiveRestResponse(d01, getMethod, sendCustomerCmd, constant.RESPONSERESULT.DATA_NOT_FOUND.resultDescription); + var response = responseMsg.error(req, getCmd, 40401); + log.addErrorSummary(d01, getMethod+"_"+sendCustomerCmd, response.resultCode, response.resultDescription); + } + } else if(getCustomer.isDirect){ + stats.receiveRestResponse(d01, getMethod, sendCustomerCmd, constant.ERROR); + var response = responseMsg.direct(req, getCmd, getCustomer.response); + log.addErrorSummary(d01, getMethod+"_"+sendCustomerCmd, getCustomer.response.resultCode, getCustomer.response.resultDescription); + } else { + stats.receiveRestResponse(d01, getMethod, sendCustomerCmd, constant.ERROR); + var response = responseMsg.error(req, getCmd, 50000); + } + //else end flow + + return response; +}; + +async function postMemberCardHandler(req, memberCard){ + + if(!memberCard.isErr){ + stats.receiveRestResponse(d01, postMethod, sendMemberCardCmd, constant.SUCCESS); + var response = responseMsg.direct(req, getCmd, memberCard.response); + log.addSuccessSummary(d01, postMethod+"_"+sendMemberCardCmd, response.resultCode, response.developerMessage); + } else if(getCustomer.isDirect){ + stats.receiveRestResponse(d01, postMethod, sendMemberCardCmd, constant.ERROR); + var response = responseMsg.direct(req, getCmd, memberCard.response); + log.addErrorSummary(d01, postMethod+"_"+sendMemberCardCmd, memberCard.response.resultCode, memberCard.response.developerMessage); + } else { + stats.receiveRestResponse(d01, postMethod, sendMemberCardCmd, constant.ERROR); + var response = responseMsg.error(req, getCmd, 50000); + } + + return response; +}; + +async function checkOwnerCard(resultData,objectData){ + + var userOwnerCardLimit = cfg.service.D01.userOwnerCardLimit + var userMembershipCardLimit = cfg.service.D01.userMembershipCardLimit + + var cardId = objectData.cardId; + var customerId = objectData.cardOwnerIdList; + + var countf = async function (resultData){ + var dataCount = { + userOwnCardCount : 0, + cardOwnUserCount : 0 + } + + for(var i = 0 ; i < resultData.length ; i++){ + // console.log(resultData[i]) + if(resultData[i].cardOwnerIdList.includes(customerId)){ + dataCount.userOwnCardCount = dataCount.userOwnCardCount++; + } + if(resultData[i].cardId === cardId){ + dataCount.cardOwnUserCount = resultData[i].cardOwnerIdList.length; + } + } + + return dataCount; + }; + var count = await countf(resultData); + // console.log(count); + + if(count.userOwnCardCount < userMembershipCardLimit + && count.cardOwnUserCount < userOwnerCardLimit){ + return true + } else { + return false; + } +}; \ No newline at end of file -- libgit2 0.21.2