diff --git a/app/controllers/loan.details.controller.js b/app/controllers/loan.details.controller.js index 283a0fd..380177d 100644 --- a/app/controllers/loan.details.controller.js +++ b/app/controllers/loan.details.controller.js @@ -11,11 +11,11 @@ exports.mainLandingPage = async (req, res) => { try { - ResData = await ApiCallHelper.loanDetailsDataApiCall(req.query.losid); - if (ResData.status != 'Not Found') + Loan_Detail_Losid = await LoanDetail.findOne({ where : { losid : req.query.losid , is_active : 1}}) + if (Loan_Detail_Losid == undefined) { - Loan_Detail = await LoanDetail.findOne({ where : { losid : req.query.losid , is_active : 1}}) - if (ResData.lstLoanApplication.length != 0 && Loan_Detail == null ) + ResData = await ApiCallHelper.loanDetailsDataApiCall(req.query.losid); + if (ResData.status == "Successful" && ResData.lstLoanApplication.length != 0) { loanDetailData = ResData.lstLoanApplication[0]; loanDetailObject = @@ -30,21 +30,9 @@ exports.mainLandingPage = async (req, res) => // Loan Detail Create LoanDetail.create(loanDetailObject).then(LoanDetailData => { - // Final Response - LoanDetail.findAll({raw: true , where : { is_active : 1}}).then(data => - { - if(data.length > 0) - { - res.send({'status':200,'message':"success",'data':data}); - } - else { - res.send({'status':404,'message':"failed",'data':"No data"}); - } - }) - .catch(err => { - res.send({'status':404, - message: err.message || "Some error occurred while retrieving statements." ,'data': "No data" }); - }); + // Final Response + LoanDetail.findAll({raw: true , where : { is_active : 1}}).then(data => { if(data.length > 0) { res.send({'status':200,'message':"success",'data':data}); } else { res.send({'status':404,'message':"failed",'data':"No data"}); } }) + // Entity detail promise var EntityKYCDetailDataInsert = new Promise(async(resolve, reject) => { @@ -144,7 +132,7 @@ exports.mainLandingPage = async (req, res) => logMsg.info("Applicants inserted"); ApplicantsDetailsData.forEach(async(ApplicantsDetailsDataElement , index ) => { - await ApiCallHelper.ApplicantChildTable(ApplicantsDetailsDataElement.name , LoanDetailData.dataValues.id ,ApplicantsDetailsDataElement.id ,ApplicantsDetailsDataElement.losid ,lstApplicantKYCDetailDataArray[index].Applicant_entity_type , ResData , "Product" , lstApplicantKYCDetailDataArray[index].Applicant_id ) + await ApiCallHelper.ApplicantChildTable(ApplicantsDetailsDataElement.name , LoanDetailData.dataValues.id ,ApplicantsDetailsDataElement.id ,ApplicantsDetailsDataElement.losid ,lstApplicantKYCDetailDataArray[index].Applicant_entity_type , ResData , "LFMP" , lstApplicantKYCDetailDataArray[index].Applicant_id ) }); }).catch(err=>{ logMsg.info("ApplicantsDetails Failed , Msg :" +err); }); // ApplicantsDetails Create catch block }); @@ -152,6 +140,7 @@ exports.mainLandingPage = async (req, res) => } // end of if lstLoanApplication else { + logMsg.info("Los api call failed Failed " +req.query.losid); LoanDetail.findAll({raw: true , where : { is_active : 1}}).then(data => { if(data.length > 0) @@ -170,7 +159,7 @@ exports.mainLandingPage = async (req, res) => } else { - logMsg.info("Los api call failed Failed " +ResData.losid); + logMsg.info("Data already inserted " +req.query.losid); // Final Response LoanDetail.findAll({raw: true , where : { is_active : 1}}).then(data => { @@ -187,26 +176,6 @@ exports.mainLandingPage = async (req, res) => message: err.message || "Some error occurred while retrieving statements." ,'data': "No data" }); }); } // Los api call failed - - - - - // // Final Response - // LoanDetail.findAll({raw: true , where : { is_active : 1}}).then(data => - // { - // if(data.length > 0) - // { - // res.send({'status':200,'message':"success",'data':data}); - // } - // else { - // res.send({'status':404,'message':"failed",'data':"No data"}); - // } - // }) - // .catch(err => { - // res.send({'status':404, - // message: err.message || "Some error occurred while retrieving statements." ,'data': "No data" }); - // }); - } // end of try block catch(err) { diff --git a/app/services/ApiCallHelper.js b/app/services/ApiCallHelper.js index d213a56..df1bb81 100644 --- a/app/services/ApiCallHelper.js +++ b/app/services/ApiCallHelper.js @@ -227,7 +227,7 @@ function ApplicantChildTable(ApplicantName , LoanId , ApplicantId , Losid , Enti // ResidenceAddressDetails Table var ResidenceAddressDetailsPromise = new Promise(async(resolve, reject) => { - if(ApiArray.lstApplicantAddress.length != 0 ) + if(ApiArray.lstApplicantAddress.length != 0 /* && EntityType == "Individual" */) { // ResidenceAddressDetails data ApiArray.lstApplicantAddress.forEach(async(ApplicantAddress,index) => @@ -261,7 +261,7 @@ function ApplicantChildTable(ApplicantName , LoanId , ApplicantId , Losid , Enti // ResidenceAddressDetails Table var PropertyOwnershipIncomeConsideredPromise = new Promise(async(resolve, reject) => { - // if (EntityType == "Individual") + // if (product == "LFMP") // { PropertyOwnershipIncomeConsideredData = { } Object.assign(PropertyOwnershipIncomeConsideredData, {name_of_the_loan_applicants : ApplicantName ,applicant_id: ApplicantId, loan_no_id: LoanId ,losid: Losid }); @@ -287,6 +287,9 @@ function ApplicantChildTable(ApplicantName , LoanId , ApplicantId , Losid , Enti } + + + module.exports = { loanDetailsDataApiCall : loanDetailsDataApiCall,