diff --git a/app/controllers/loan.details.controller.js b/app/controllers/loan.details.controller.js index 77db583..283a0fd 100644 --- a/app/controllers/loan.details.controller.js +++ b/app/controllers/loan.details.controller.js @@ -14,8 +14,8 @@ exports.mainLandingPage = async (req, res) => ResData = await ApiCallHelper.loanDetailsDataApiCall(req.query.losid); if (ResData.status != 'Not Found') { - Loan_Detail = LoanDetail.findAll({ where : { losid : req.query.losid , is_active : 1}}) - if (ResData.lstLoanApplication.length != 0 && Loan_Detail.length == undefined ) + Loan_Detail = await LoanDetail.findOne({ where : { losid : req.query.losid , is_active : 1}}) + if (ResData.lstLoanApplication.length != 0 && Loan_Detail == null ) { loanDetailData = ResData.lstLoanApplication[0]; loanDetailObject = @@ -30,6 +30,21 @@ 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" }); + }); // Entity detail promise var EntityKYCDetailDataInsert = new Promise(async(resolve, reject) => { @@ -91,8 +106,6 @@ exports.mainLandingPage = async (req, res) => { logMsg.info("EntityDetails inserted"); await ApiCallHelper.EntityChildTable(data.dataValues.id) - .then(childData=>{ - logMsg.info("EntityChildTable inserted"); }) }) .catch(err=>{ logMsg.info("EntityDetails Failed , Msg :" +err); }); }); @@ -137,30 +150,62 @@ exports.mainLandingPage = async (req, res) => }); }).catch(err=>{ logMsg.info("LoanDetails Failed , Msg :" +err); }) // Loan deatil Create catch block } // end of if lstLoanApplication + else + { + 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" }); + }); + } } else { - logMsg.info("Los api call failed Failed" + ResData.losid); + logMsg.info("Los api call failed Failed " +ResData.losid); + // 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" }); + }); } // 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" }); - }); + // // 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 92b94cb..d213a56 100644 --- a/app/services/ApiCallHelper.js +++ b/app/services/ApiCallHelper.js @@ -89,8 +89,8 @@ async function EntityChildTable(EntityId) DueDiligenceCheck.bulkCreate(DueDiligenceCheckData) .then(DueDiligenceCheckData => { - logMsg.info("DueDiligenceCheck Data Creation Success for EntityId= "+entityid); - resolve() + // logMsg.info("DueDiligenceCheck Data Creation Success for EntityId= "+entityid); + resolve("DueDiligenceCheck") }) .catch(err =>{ logMsg.info("DueDiligenceCheck Data Creation Failed for EntityId= "+entityid+" Error= "+err); }); }, 500); @@ -126,8 +126,8 @@ async function EntityChildTable(EntityId) }); } }); - logMsg.info("ATNWrelatedInputs Data Creation Success for EntityId= "+entityid); - resolve(); + // logMsg.info("ATNWrelatedInputs Data Creation Success for EntityId= "+entityid); + resolve("ATNWrelatedInputs"); }) .catch(err =>{ logMsg.info("ATNWrelatedInputs Data Creation Failed for EntityId= "+entityid+" Error= "+err); }); }, 500); @@ -155,8 +155,8 @@ async function EntityChildTable(EntityId) OtherParameters.bulkCreate(OtherParameterMasterData_arr) .then(OtherParameterMasterData_arr => { - logMsg.info("otherParameter Data Creation Success for EntityId= "+entityid); - resolve() + // logMsg.info("otherParameter Data Creation Success for EntityId= "+entityid); + resolve("otherParameter") }) .catch(err =>{ logMsg.info("otherParameter Data Creation Failed for EntityId= "+entityid+" Error= "+err); }); }, 500); @@ -172,7 +172,7 @@ async function EntityChildTable(EntityId) { TradeReferencesData = { "entity_id" : EntityId } await TradeReferences.create(TradeReferencesData) - .then(data => { logMsg.info("TradeReferences Data Creation Success for EntityId= "+EntityId); resolve(); }) + .then(data => {resolve("TradeReferences"); }) .catch(err => { logMsg.info("TradeReferences Data Creation Failed for EntityId= "+EntityId+" Error= "+err); }); })// Promise @@ -184,15 +184,15 @@ async function EntityChildTable(EntityId) { EnquiriesAndDisbursementsData = { "entity_id" : EntityId } EnquiriesAndDisbursements.create(EnquiriesAndDisbursementsData) - .then(data => { logMsg.info("EnquiriesAndDisbursements Data Creation Success for EntityId= "+EntityId); resolve(); }) + .then(data => {resolve("EnquiriesAndDisbursements"); }) .catch(err => { logMsg.info("EnquiriesAndDisbursements Data Creation Failed for EntityId= "+EntityId+" Error= "+err); }); }) // Promise Promise.all([DueDiligenceCheckPromise, ATNWrelatedInputsPromise, OtherParametersPromise , TradeReferencesPromise , EnquiriesAndDisbursementsPromise ]) - .then((values) => { + .then(values => { values.forEach(element => { - logMsg.info(element+ "Data Creation Success for EntityId= "+EntityId); // [3, 1337, "foo"] + logMsg.info(element+ " Data Creation Success for EntityId= "+EntityId); // [3, 1337, "foo"] }); }) @@ -220,7 +220,7 @@ function ApplicantChildTable(ApplicantName , LoanId , ApplicantId , Losid , Enti // if (ApiArray.lstApplicantsRelationship.length != 0) // { await ApplicantsRelationship.create(ApplicantsRelationshipData) - .then(data=>{logMsg.info("ApplicantsRelationship inserted"); resolve()}).catch(err=>{logMsg.info("ApplicantsRelationship Failed , Msg :" +err);}); + .then(data=>{ resolve("ApplicantsRelationship")}).catch(err=>{logMsg.info("ApplicantsRelationship Failed , Msg :" +err);}); // } // } }); @@ -246,10 +246,10 @@ function ApplicantChildTable(ApplicantName , LoanId , ApplicantId , Losid , Enti await ResidenceAddressDetails.create(ApplicantAddress) .then(data=> { - logMsg.info("ResidenceAddressDetails inserted"); + // logMsg.info("ResidenceAddressDetails inserted"); if ([ApiArray.lstApplicantAddress].length - 1 == index) { - resolve() + resolve("ResidenceAddressDetails") } }) .catch(err=>{logMsg.info("ResidenceAddressDetails Failed , Msg :" +err);}); @@ -266,7 +266,7 @@ function ApplicantChildTable(ApplicantName , LoanId , ApplicantId , Losid , Enti PropertyOwnershipIncomeConsideredData = { } Object.assign(PropertyOwnershipIncomeConsideredData, {name_of_the_loan_applicants : ApplicantName ,applicant_id: ApplicantId, loan_no_id: LoanId ,losid: Losid }); await PropertyOwnershipIncomeConsidered.create(PropertyOwnershipIncomeConsideredData) - .then(data=>{logMsg.info("PropertyOwnershipIncomeConsidered inserted"); resolve() }).catch(err=>{logMsg.info("PropertyOwnershipIncomeConsidered Failed , Msg :" +err);}); + .then(data=>{ resolve("PropertyOwnershipIncomeConsidered") }).catch(err=>{logMsg.info("PropertyOwnershipIncomeConsidered Failed , Msg :" +err);}); // } }); @@ -274,7 +274,7 @@ function ApplicantChildTable(ApplicantName , LoanId , ApplicantId , Losid , Enti Promise.all([ApplicantsRelationshipPromise, ResidenceAddressDetailsPromise, PropertyOwnershipIncomeConsideredPromise ]) .then((values) => { values.forEach(element => { - logMsg.info(element+ "Data Creation Success for EntityId= "+EntityId); // [3, 1337, "foo"] + logMsg.info(element+ " Data Creation Success for EntityId= "+EntityId); // [3, 1337, "foo"] }); })