mainLandingPage Api : suseendhiran

This commit is contained in:
suseendhiran17 2022-08-02 18:43:01 +05:30
parent b593a8149b
commit f470ebaba3
2 changed files with 80 additions and 35 deletions

View File

@ -14,8 +14,8 @@ exports.mainLandingPage = async (req, res) =>
ResData = await ApiCallHelper.loanDetailsDataApiCall(req.query.losid); ResData = await ApiCallHelper.loanDetailsDataApiCall(req.query.losid);
if (ResData.status != 'Not Found') if (ResData.status != 'Not Found')
{ {
Loan_Detail = LoanDetail.findAll({ where : { losid : req.query.losid , is_active : 1}}) Loan_Detail = await LoanDetail.findOne({ where : { losid : req.query.losid , is_active : 1}})
if (ResData.lstLoanApplication.length != 0 && Loan_Detail.length == undefined ) if (ResData.lstLoanApplication.length != 0 && Loan_Detail == null )
{ {
loanDetailData = ResData.lstLoanApplication[0]; loanDetailData = ResData.lstLoanApplication[0];
loanDetailObject = loanDetailObject =
@ -30,6 +30,21 @@ exports.mainLandingPage = async (req, res) =>
// Loan Detail Create // Loan Detail Create
LoanDetail.create(loanDetailObject).then(LoanDetailData => 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 // Entity detail promise
var EntityKYCDetailDataInsert = new Promise(async(resolve, reject) => var EntityKYCDetailDataInsert = new Promise(async(resolve, reject) =>
{ {
@ -91,8 +106,6 @@ exports.mainLandingPage = async (req, res) =>
{ {
logMsg.info("EntityDetails inserted"); logMsg.info("EntityDetails inserted");
await ApiCallHelper.EntityChildTable(data.dataValues.id) await ApiCallHelper.EntityChildTable(data.dataValues.id)
.then(childData=>{
logMsg.info("EntityChildTable inserted"); })
}) })
.catch(err=>{ logMsg.info("EntityDetails Failed , Msg :" +err); }); .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 }).catch(err=>{ logMsg.info("LoanDetails Failed , Msg :" +err); }) // Loan deatil Create catch block
} // end of if lstLoanApplication } // 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 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 } // Los api call failed
// Final Response // // Final Response
LoanDetail.findAll({raw: true , where : { is_active : 1}}).then(data => // LoanDetail.findAll({raw: true , where : { is_active : 1}}).then(data =>
{ // {
if(data.length > 0) // if(data.length > 0)
{ // {
res.send({'status':200,'message':"success",'data':data}); // res.send({'status':200,'message':"success",'data':data});
} // }
else { // else {
res.send({'status':404,'message':"failed",'data':"No data"}); // res.send({'status':404,'message':"failed",'data':"No data"});
} // }
}) // })
.catch(err => { // .catch(err => {
res.send({'status':404, // res.send({'status':404,
message: err.message || "Some error occurred while retrieving statements." ,'data': "No data" }); // message: err.message || "Some error occurred while retrieving statements." ,'data': "No data" });
}); // });
} // end of try block } // end of try block
catch(err) catch(err)

View File

@ -89,8 +89,8 @@ async function EntityChildTable(EntityId)
DueDiligenceCheck.bulkCreate(DueDiligenceCheckData) DueDiligenceCheck.bulkCreate(DueDiligenceCheckData)
.then(DueDiligenceCheckData => .then(DueDiligenceCheckData =>
{ {
logMsg.info("DueDiligenceCheck Data Creation Success for EntityId= "+entityid); // logMsg.info("DueDiligenceCheck Data Creation Success for EntityId= "+entityid);
resolve() resolve("DueDiligenceCheck")
}) })
.catch(err =>{ logMsg.info("DueDiligenceCheck Data Creation Failed for EntityId= "+entityid+" Error= "+err); }); .catch(err =>{ logMsg.info("DueDiligenceCheck Data Creation Failed for EntityId= "+entityid+" Error= "+err); });
}, 500); }, 500);
@ -126,8 +126,8 @@ async function EntityChildTable(EntityId)
}); });
} }
}); });
logMsg.info("ATNWrelatedInputs Data Creation Success for EntityId= "+entityid); // logMsg.info("ATNWrelatedInputs Data Creation Success for EntityId= "+entityid);
resolve(); resolve("ATNWrelatedInputs");
}) })
.catch(err =>{ logMsg.info("ATNWrelatedInputs Data Creation Failed for EntityId= "+entityid+" Error= "+err); }); .catch(err =>{ logMsg.info("ATNWrelatedInputs Data Creation Failed for EntityId= "+entityid+" Error= "+err); });
}, 500); }, 500);
@ -155,8 +155,8 @@ async function EntityChildTable(EntityId)
OtherParameters.bulkCreate(OtherParameterMasterData_arr) OtherParameters.bulkCreate(OtherParameterMasterData_arr)
.then(OtherParameterMasterData_arr => .then(OtherParameterMasterData_arr =>
{ {
logMsg.info("otherParameter Data Creation Success for EntityId= "+entityid); // logMsg.info("otherParameter Data Creation Success for EntityId= "+entityid);
resolve() resolve("otherParameter")
}) })
.catch(err =>{ logMsg.info("otherParameter Data Creation Failed for EntityId= "+entityid+" Error= "+err); }); .catch(err =>{ logMsg.info("otherParameter Data Creation Failed for EntityId= "+entityid+" Error= "+err); });
}, 500); }, 500);
@ -172,7 +172,7 @@ async function EntityChildTable(EntityId)
{ {
TradeReferencesData = { "entity_id" : EntityId } TradeReferencesData = { "entity_id" : EntityId }
await TradeReferences.create(TradeReferencesData) 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); }); .catch(err => { logMsg.info("TradeReferences Data Creation Failed for EntityId= "+EntityId+" Error= "+err); });
})// Promise })// Promise
@ -184,15 +184,15 @@ async function EntityChildTable(EntityId)
{ {
EnquiriesAndDisbursementsData = { "entity_id" : EntityId } EnquiriesAndDisbursementsData = { "entity_id" : EntityId }
EnquiriesAndDisbursements.create(EnquiriesAndDisbursementsData) 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); }); .catch(err => { logMsg.info("EnquiriesAndDisbursements Data Creation Failed for EntityId= "+EntityId+" Error= "+err); });
}) // Promise }) // Promise
Promise.all([DueDiligenceCheckPromise, ATNWrelatedInputsPromise, OtherParametersPromise , TradeReferencesPromise , EnquiriesAndDisbursementsPromise ]) Promise.all([DueDiligenceCheckPromise, ATNWrelatedInputsPromise, OtherParametersPromise , TradeReferencesPromise , EnquiriesAndDisbursementsPromise ])
.then((values) => { .then(values => {
values.forEach(element => { 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) // if (ApiArray.lstApplicantsRelationship.length != 0)
// { // {
await ApplicantsRelationship.create(ApplicantsRelationshipData) 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) await ResidenceAddressDetails.create(ApplicantAddress)
.then(data=> .then(data=>
{ {
logMsg.info("ResidenceAddressDetails inserted"); // logMsg.info("ResidenceAddressDetails inserted");
if ([ApiArray.lstApplicantAddress].length - 1 == index) if ([ApiArray.lstApplicantAddress].length - 1 == index)
{ {
resolve() resolve("ResidenceAddressDetails")
} }
}) })
.catch(err=>{logMsg.info("ResidenceAddressDetails Failed , Msg :" +err);}); .catch(err=>{logMsg.info("ResidenceAddressDetails Failed , Msg :" +err);});
@ -266,7 +266,7 @@ function ApplicantChildTable(ApplicantName , LoanId , ApplicantId , Losid , Enti
PropertyOwnershipIncomeConsideredData = { } PropertyOwnershipIncomeConsideredData = { }
Object.assign(PropertyOwnershipIncomeConsideredData, {name_of_the_loan_applicants : ApplicantName ,applicant_id: ApplicantId, loan_no_id: LoanId ,losid: Losid }); Object.assign(PropertyOwnershipIncomeConsideredData, {name_of_the_loan_applicants : ApplicantName ,applicant_id: ApplicantId, loan_no_id: LoanId ,losid: Losid });
await PropertyOwnershipIncomeConsidered.create(PropertyOwnershipIncomeConsideredData) 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 ]) Promise.all([ApplicantsRelationshipPromise, ResidenceAddressDetailsPromise, PropertyOwnershipIncomeConsideredPromise ])
.then((values) => { .then((values) => {
values.forEach(element => { 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"]
}); });
}) })