diff --git a/app/controllers/entity.applicant.controller.js b/app/controllers/entity.applicant.controller.js index 4fd9fcf..df129b3 100644 --- a/app/controllers/entity.applicant.controller.js +++ b/app/controllers/entity.applicant.controller.js @@ -103,7 +103,7 @@ exports.createApplicantDetails = async (req, res) => } else { - PropertyOwnershipIncomeConsideredData = Object.assign(PropertyOwnershipIncomeConsideredData, {loan_no_id: req.body.loan_no_id}); + PropertyOwnershipIncomeConsideredData = Object.assign(PropertyOwnershipIncomeConsideredData, {loan_no_id: req.body.loan_no_id}); PropertyOwnershipIncomeConsideredData = Object.assign(PropertyOwnershipIncomeConsideredData, {applicant_id: data.dataValues.id}); await PropertyOwnershipIncomeConsidered.create(PropertyOwnershipIncomeConsideredData) .then(data=>{logMsg.info("PropertyOwnershipIncomeConsidered inserted");}).catch(err=>{logMsg.info("PropertyOwnershipIncomeConsidered Failed , Msg :" +err);}); @@ -132,9 +132,58 @@ exports.updateApplicantDetails = async (req, res) => { id = req.body.id; delete req.body.id; - ApplicantsDetails.update(req.body,{ where: { id: id }}).then(data => - { - res.send({'status':200,'message':"success",'data':data}); + ApplicantsDetails.findOne({raw: true , where: { id: id }}).then(async (ApplicantsDetailsData) => + { + if(ApplicantsDetailsData.name != req.body.name) + { + ApplicantsDetails.update(req.body,{ where: { id: id }}).then(async(data) => + { + await ApplicantsRelationship.update({name_of_the_individual:req.body.name},{ where: { applicant_id: id , is_active : 1}}) + .then(data=>{logMsg.info("ApplicantsRelationship name updated");}).catch(err=>{logMsg.info("ApplicantsRelationship name update Failed , Msg :" +err);}); + + await ResidenceAddressDetails.update({name_of_the_individual:req.body.name},{ where: { applicant_id: id , is_active : 1}}) + .then(data=>{logMsg.info("ApplicantsRelationship name updated");}).catch(err=>{logMsg.info("ApplicantsRelationship name update Failed , Msg :" +err);}); + + await PropertyOwnershipIncomeConsidered.update({name_of_the_loan_applicants:req.body.name,applicant_type:req.body.applicant_type},{ where: { applicant_id: id , is_active : 1}}) + .then(data=>{logMsg.info("ApplicantsRelationship name updated");}).catch(err=>{logMsg.info("ApplicantsRelationship name update Failed , Msg :" +err);}); + + + res.send({'status':200,'message':"success",'data':data}); + + }) + .catch(err => { + res.send({'status':404, + message: err.message || "Some error occurred while retrieving statements." ,'data': "No data" }); + }); + + + } + else if (ApplicantsDetailsData.applicant_type != req.body.applicant_type) + { + ApplicantsDetails.update(req.body,{ where: { id: id }}).then(async(data) => + { + await PropertyOwnershipIncomeConsidered.update({applicant_type:req.body.applicant_type},{ where: { applicant_id: id , is_active : 1}}) + .then(data=>{logMsg.info("ApplicantsRelationship name updated");}).catch(err=>{logMsg.info("ApplicantsRelationship name update Failed , Msg :" +err);}); + + res.send({'status':200,'message':"success",'data':data}); + + }).catch(err => { + res.send({'status':404, + message: err.message || "Some error occurred while retrieving statements." ,'data': "No data" }); + }); + } + else + { + ApplicantsDetails.update(req.body,{ where: { id: id }}).then(async(data) => + { + res.send({'status':200,'message':"success",'data':data}); + + }).catch(err => { + res.send({'status':404, + message: err.message || "Some error occurred while retrieving statements." ,'data': "No data" }); + }); + } + }) .catch(err => { @@ -142,9 +191,12 @@ exports.updateApplicantDetails = async (req, res) => message: err.message || "Some error occurred while retrieving statements." ,'data': "No data" }); }); + + + } catch(err) { res.send({'status':404,message: err.message || "Some error occurred while inserting statements." ,'data': "No data" }); - } //end of try catch + } //end of try catch };