mainLandingPage Api added : suseendhiran
This commit is contained in:
parent
cc933c4d05
commit
6204db2da7
@ -7,15 +7,16 @@ const moment = require('moment');
|
||||
|
||||
|
||||
//LoanDeatilList List Api
|
||||
exports.LoanDeatilListTEST = async (req, res) =>
|
||||
exports.mainLandingPage = async (req, res) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
data = await ApiCallHelper.loanDetailsDataApiCall('MW00004618','AXZPP6264B');
|
||||
Applicant_id = { };
|
||||
if (data.lstLoanApplication.length != 0)
|
||||
ResData = await ApiCallHelper.loanDetailsDataApiCall(req.query.losid);
|
||||
if (ResData.status != 'Not Found')
|
||||
{
|
||||
if (ResData.lstLoanApplication.length != 0)
|
||||
{
|
||||
loanDetailData = data.lstLoanApplication[0];
|
||||
loanDetailData = ResData.lstLoanApplication[0];
|
||||
loanDetailObject =
|
||||
{
|
||||
applicationNo : loanDetailData.applicationNo,
|
||||
@ -23,16 +24,17 @@ exports.LoanDeatilListTEST = async (req, res) =>
|
||||
date_of_login : moment(new Date(loanDetailData.loginDate)).format("YYYY-MM-DD"),
|
||||
sourcing_channel_name : loanDetailData.source,
|
||||
emi_of_loan_applied_for : Number(loanDetailData.loanAmount),
|
||||
product : loanDetailData.loanProductName
|
||||
// product : loanDetailData.loanProductName
|
||||
}
|
||||
// Loan Detail Create
|
||||
LoanDetail.create(loanDetailObject).then(LoanDetailData =>
|
||||
{
|
||||
// entity detail promise
|
||||
// Entity detail promise
|
||||
var EntityKYCDetailDataInsert = new Promise(async(resolve, reject) =>
|
||||
{
|
||||
lstEntityKYCDetailDataArray = [];
|
||||
data.lstApplicantKYCDetail.forEach(async(value,index,array) => {
|
||||
if (value.kycType == "Non-Individual ")
|
||||
ResData.lstApplicantKYCDetail.forEach(async(value,index,array) => {
|
||||
if (value.kycType.trim() == "Non-Individual")
|
||||
{
|
||||
lstEntityKYCDetailObj =
|
||||
{
|
||||
@ -42,7 +44,7 @@ exports.LoanDeatilListTEST = async (req, res) =>
|
||||
entity_formation_date : moment(new Date(value.doi)).format("YYYY-MM-DD"),
|
||||
// entity_type : value.kycType
|
||||
}
|
||||
data.lstApplicantAddress.forEach(async(address_value,index) =>
|
||||
ResData.lstApplicantAddress.forEach(async(address_value,index) =>
|
||||
{
|
||||
if (value.iD_ApplicantKYCDetail == address_value.iD_ApplicantKYCDetail && address_value.iD_OwnershipTypes == "Permanent" )
|
||||
{
|
||||
@ -78,31 +80,38 @@ exports.LoanDeatilListTEST = async (req, res) =>
|
||||
}
|
||||
});
|
||||
}); // end of entity detail promise
|
||||
// Create entity detail
|
||||
// Create Entity detail
|
||||
EntityKYCDetailDataInsert.then(async(lstEntityKYCDetailDataArray)=>
|
||||
{
|
||||
lstEntityKYCDetailDataArray.forEach(async(element) =>
|
||||
{
|
||||
await EntityDetails.create(element)
|
||||
.then(data=>{ logMsg.info("EntityDetails inserted"); })
|
||||
.then(async(data)=>
|
||||
{
|
||||
logMsg.info("EntityDetails inserted");
|
||||
await ApiCallHelper.EntityChildTable(data.dataValues.id)
|
||||
.then(childData=>{
|
||||
logMsg.info("EntityChildTable inserted"); })
|
||||
})
|
||||
.catch(err=>{ logMsg.info("EntityDetails Failed , Msg :" +err); });
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// application detail promise
|
||||
// Application detail promise
|
||||
var ApplicantKYCDetailDataInsert = new Promise(async(resolve, reject) =>
|
||||
{
|
||||
lstApplicantKYCDetailDataArray = [];
|
||||
data.lstApplicantKYCDetail.forEach(async(value,index,array) => {
|
||||
if (value.kycType == "Individual ")
|
||||
ResData.lstApplicantKYCDetail.forEach(async(value,index,array) => {
|
||||
if (value.kycType.trim() == "Individual")
|
||||
{
|
||||
Applicant_id = value.iD_ApplicantKYCDetail;
|
||||
lstApplicantKYCDetailObj =
|
||||
{
|
||||
{
|
||||
Applicant_id : value.iD_ApplicantKYCDetail,
|
||||
Applicant_entity_type : value.kycType.trim(),
|
||||
losid : LoanDetailData.dataValues.losid ,
|
||||
loan_no_id : LoanDetailData.dataValues.id ,
|
||||
name : [value.firstName, value.middleName, value.lastName ].filter(Boolean).join(" "),
|
||||
name : [value.firstName, value.middleName, value.lastName ].filter(Boolean).join(" "), // concat and ignore null
|
||||
}
|
||||
lstApplicantKYCDetailDataArray.push(lstApplicantKYCDetailObj);
|
||||
}
|
||||
@ -116,44 +125,28 @@ exports.LoanDeatilListTEST = async (req, res) =>
|
||||
ApplicantKYCDetailDataInsert.then(async(lstApplicantKYCDetailDataArray)=>
|
||||
{
|
||||
await ApplicantsDetails.bulkCreate(lstApplicantKYCDetailDataArray)
|
||||
.then(ApplicantsDetailsData=>{
|
||||
if(data.lstLoanApplication.entity_type == "Individual " && data.lstApplicantAddress.length != 0 )
|
||||
{
|
||||
// ResidenceAddressDetails data
|
||||
data.lstApplicantAddress.forEach(async(ApplicantAddress) =>
|
||||
{
|
||||
// Applicant Address Create
|
||||
if (ApplicantAddress.iD_ApplicantKYCDetail == Applicant_id && ApplicantAddress.iD_OwnershipTypes == "Permanent")
|
||||
{
|
||||
Object.assign(ApplicantAddress,
|
||||
{
|
||||
loan_no_id : LoanDetailData.dataValues.losid ,
|
||||
losid : ApplicantsDetailsData.dataValues.losid ,
|
||||
applicant_id: ApplicantsDetailsData.dataValues.id ,
|
||||
residence_address : [ApplicantAddress.address1, ApplicantAddress.address2, ApplicantAddress.address3 , ApplicantAddress.iD_States , ApplicantAddress.city , ApplicantAddress.pin ].filter(Boolean).join(" "),
|
||||
ownership_status : ApplicantAddress.iD_OwnershipTypes ,
|
||||
// residence_location_area
|
||||
})
|
||||
await ResidenceAddressDetails.create(ApplicantAddress)
|
||||
.then(data=>{logMsg.info("ResidenceAddressDetails inserted");})
|
||||
.catch(err=>{logMsg.info("ResidenceAddressDetails Failed , Msg :" +err);});
|
||||
}
|
||||
});
|
||||
}
|
||||
.then(async(ApplicantsDetailsData)=>
|
||||
{
|
||||
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 )
|
||||
});
|
||||
}).catch(err=>{ logMsg.info("ApplicantsDetails Failed , Msg :" +err); }); // ApplicantsDetails Create catch block
|
||||
});
|
||||
}).catch(err=>{ logMsg.info("LoanDetails Failed , Msg :" +err); }) // Loan deatil Create catch block
|
||||
} // end of if lstLoanApplication
|
||||
else
|
||||
{
|
||||
logMsg.info("Los api call failed Failed , Msg :" +err);
|
||||
} // Los api call failed
|
||||
}
|
||||
else
|
||||
{
|
||||
logMsg.info("Los api call failed Failed" +ResData.losid);
|
||||
} // Los api call failed
|
||||
|
||||
|
||||
|
||||
|
||||
// Final Response
|
||||
LoanDetail.findAll({raw: true , where : { losid : "MW00004618" , is_active : 1}}).then(data =>
|
||||
LoanDetail.findAll({raw: true , where : { is_active : 1}}).then(data =>
|
||||
{
|
||||
if(data.length > 0)
|
||||
{
|
||||
@ -174,4 +167,9 @@ exports.LoanDeatilListTEST = async (req, res) =>
|
||||
res.send({'status':404,message: err.message || "Some error occurred while inserting statements." ,'data': "No data" });
|
||||
} //end of try catch
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -8,7 +8,6 @@ module.exports = app => {
|
||||
const { logMsg } = require('../services/logger.js');
|
||||
var router = require("express").Router();
|
||||
|
||||
router.get("/LoanDeatilListTEST", Loancontroller.LoanDeatilListTEST);
|
||||
// demo welcome Api
|
||||
/**
|
||||
* @swagger
|
||||
@ -2488,6 +2487,30 @@ router.get("/MainAppMasterDataList", Entitycontroller.MainAppMasterDataList);
|
||||
router.delete("/DeleteTradeReference", Entitycontroller.DeleteTradeReference);
|
||||
|
||||
|
||||
|
||||
|
||||
// mainLandingPage Api
|
||||
/**
|
||||
* @swagger
|
||||
* /api/mainLandingPage:
|
||||
* get:
|
||||
* summary: LoanDeatil List TEST Api
|
||||
* description: LoanDeatil List TEST Api
|
||||
* parameters:
|
||||
* - in: query
|
||||
* name: losid
|
||||
* schema:
|
||||
* type: string
|
||||
* required: true
|
||||
* description: Loan ID
|
||||
* example: MW112233
|
||||
* responses:
|
||||
* 200:
|
||||
* description: success
|
||||
*/
|
||||
router.get("/mainLandingPage", Loancontroller.mainLandingPage);
|
||||
|
||||
|
||||
// routes started here
|
||||
app.use('/api', router);
|
||||
};
|
||||
|
||||
@ -1,16 +1,15 @@
|
||||
//const { sequelize} = require('../models');
|
||||
const { sequelize , LoanDetail , EntityDetails , ApplicantsDetails , ApplicantsRelationship , ResidenceAddressDetails , DueDiligenceCheck , TradeReferences , CheckTypeMaster , EnquiriesAndDisbursements , PropertyAndLtv , ATNWrelatedInputs , SalesPD , ATNWrelatedInputMaster ,ATNWrelationship , OtherParameterMaster ,OtherParameterMasterValue , OtherParameterRelationship , OtherParameters , ATNErelatedInputSubVal , DataFromLos , FormulaMaster , LoanAndLtvMaster , EntityApplicantMaster , PropertyOwnershipIncomeConsidered } = require('../models')
|
||||
const { logMsg } = require('../services/logger.js');
|
||||
const request = require('request');
|
||||
|
||||
|
||||
|
||||
async function loanDetailsDataApiCall(losid,pan_no) {
|
||||
async function loanDetailsDataApiCall(losid) {
|
||||
try {
|
||||
LOAN_URL = process.env.LOS_DATA_URL;
|
||||
token = await getLoginToken();
|
||||
request_object = {
|
||||
"losid": losid,
|
||||
"panNo": pan_no
|
||||
"losid": losid
|
||||
};
|
||||
return new Promise((resolve, reject) => {
|
||||
request({
|
||||
@ -67,9 +66,227 @@ function getLoginToken() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
async function EntityChildTable(EntityId)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var DueDiligenceCheckPromise = new Promise(async(resolve, reject) =>
|
||||
{
|
||||
// DueDiligenceCheck
|
||||
CheckTypeMaster.findAll({raw: true , where : {is_active : 1}}).then(async(CheckTypeMasterData) =>
|
||||
{
|
||||
entityid = EntityId;
|
||||
DueDiligenceCheckData = [];
|
||||
for (const value of CheckTypeMasterData)
|
||||
{
|
||||
check_type_obj = {entity_id:entityid , check_type_id:value.id , check_type:value.value};
|
||||
DueDiligenceCheckData.push(check_type_obj);
|
||||
}
|
||||
setTimeout(() => {
|
||||
DueDiligenceCheck.bulkCreate(DueDiligenceCheckData)
|
||||
.then(DueDiligenceCheckData =>
|
||||
{
|
||||
logMsg.info("DueDiligenceCheck Data Creation Success for EntityId= "+entityid);
|
||||
resolve()
|
||||
})
|
||||
.catch(err =>{ logMsg.info("DueDiligenceCheck Data Creation Failed for EntityId= "+entityid+" Error= "+err); });
|
||||
}, 500);
|
||||
})
|
||||
.catch(err => { logMsg.info("DueDiligenceCheckType Data Fetching Failed for EntityId= "+entityid+" Error= "+err); });
|
||||
}); //promise
|
||||
|
||||
|
||||
|
||||
// ATNWrelatedInput
|
||||
var ATNWrelatedInputsPromise = new Promise(async(resolve, reject) =>
|
||||
{
|
||||
ATNWrelatedInputMaster.findAll({raw: true , where : {is_active : 1}}).then(async(ATNWrelatedInputMasterData) =>
|
||||
{
|
||||
entityid = EntityId;
|
||||
ATNWrelatedInputMasterData_arr = [];
|
||||
ATNWrelatedInputMasterData_arr_val = [];
|
||||
for (const value of ATNWrelatedInputMasterData)
|
||||
{
|
||||
if ( value.id == 9 || value.id == 10 ) { atnw_master_value_data = { atnw_related_input :value.master_name }; ATNWrelatedInputMasterData_arr_val.push(atnw_master_value_data); } else { atnw_master_data = {entity_id:entityid , atnw_related_input_id:value.id , atnw_related_input:value.master_name}; ATNWrelatedInputMasterData_arr.push(atnw_master_data); }
|
||||
}
|
||||
setTimeout(() => {
|
||||
ATNWrelatedInputs.bulkCreate(ATNWrelatedInputMasterData_arr)
|
||||
.then(ATNWrelatedInputMasterData_arr =>
|
||||
{
|
||||
ATNWrelatedInputMasterData_arr.forEach( async (atnw_element) => {
|
||||
if (atnw_element.atnw_related_input_id == 8) {
|
||||
ATNWrelatedInputMasterData_arr_val.forEach( async (atnw_related_input_id_element) => {
|
||||
Object.assign( atnw_related_input_id_element, { master_id : atnw_element.id });
|
||||
ATNErelatedInputSubVal.create(atnw_related_input_id_element).then(data => {
|
||||
logMsg.info("ATNWrelatedInputs_subValue Data Creation Success for EntityId= "+entityid);
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
logMsg.info("ATNWrelatedInputs Data Creation Success for EntityId= "+entityid);
|
||||
resolve();
|
||||
})
|
||||
.catch(err =>{ logMsg.info("ATNWrelatedInputs Data Creation Failed for EntityId= "+entityid+" Error= "+err); });
|
||||
}, 500);
|
||||
})
|
||||
.catch(err => { logMsg.info("ATNWrelatedInputs Data Fetching Failed for EntityId= "+entityid+" Error= "+err); });
|
||||
}); // Promise
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// otherParameter data create
|
||||
var OtherParametersPromise = new Promise(async(resolve, reject) =>
|
||||
{
|
||||
OtherParameterMaster.findAll({raw: true , where : {is_active : 1}}).then(async(OtherParameterMasterData) =>
|
||||
{
|
||||
entityid = EntityId;
|
||||
OtherParameterMasterData_arr = [];
|
||||
for (const value of OtherParameterMasterData)
|
||||
{
|
||||
op_master_data = {entity_id:entityid , op_master_id:value.id , master_name:value.master_name};
|
||||
OtherParameterMasterData_arr.push(op_master_data);
|
||||
}
|
||||
setTimeout(() => {
|
||||
OtherParameters.bulkCreate(OtherParameterMasterData_arr)
|
||||
.then(OtherParameterMasterData_arr =>
|
||||
{
|
||||
logMsg.info("otherParameter Data Creation Success for EntityId= "+entityid);
|
||||
resolve()
|
||||
})
|
||||
.catch(err =>{ logMsg.info("otherParameter Data Creation Failed for EntityId= "+entityid+" Error= "+err); });
|
||||
}, 500);
|
||||
})
|
||||
.catch(err => { logMsg.info("otherParameter Data Fetching Failed for EntityId= "+entityid+" Error= "+err); });
|
||||
})// Promise
|
||||
|
||||
|
||||
|
||||
|
||||
// TradeReferencesDetails
|
||||
var TradeReferencesPromise = new Promise(async(resolve, reject) =>
|
||||
{
|
||||
TradeReferencesData = { "entity_id" : EntityId }
|
||||
await TradeReferences.create(TradeReferencesData)
|
||||
.then(data => { logMsg.info("TradeReferences Data Creation Success for EntityId= "+EntityId); resolve(); })
|
||||
.catch(err => { logMsg.info("TradeReferences Data Creation Failed for EntityId= "+EntityId+" Error= "+err); });
|
||||
})// Promise
|
||||
|
||||
|
||||
|
||||
|
||||
// EnquiriesAndDisbursements
|
||||
var EnquiriesAndDisbursementsPromise = new Promise(async(resolve, reject) =>
|
||||
{
|
||||
EnquiriesAndDisbursementsData = { "entity_id" : EntityId }
|
||||
EnquiriesAndDisbursements.create(EnquiriesAndDisbursementsData)
|
||||
.then(data => { logMsg.info("EnquiriesAndDisbursements Data Creation Success for EntityId= "+EntityId); resolve(); })
|
||||
.catch(err => { logMsg.info("EnquiriesAndDisbursements Data Creation Failed for EntityId= "+EntityId+" Error= "+err); });
|
||||
}) // Promise
|
||||
|
||||
|
||||
Promise.all([DueDiligenceCheckPromise, ATNWrelatedInputsPromise, OtherParametersPromise , TradeReferencesPromise , EnquiriesAndDisbursementsPromise ])
|
||||
.then((values) => {
|
||||
logMsg.info("Data Creation Success for EntityId= "+EntityId); // [3, 1337, "foo"]
|
||||
})
|
||||
|
||||
}
|
||||
catch (error)
|
||||
{
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function ApplicantChildTable(ApplicantName , LoanId , ApplicantId , Losid , EntityType , ApiArray , Product , Applicant_id) {
|
||||
try
|
||||
{
|
||||
// ApplicantsRelationship Table
|
||||
var ApplicantsRelationshipPromise = new Promise(async(resolve, reject) =>
|
||||
{
|
||||
// if(EntityType == "Individual")
|
||||
// {
|
||||
ApplicantsRelationshipData = { }
|
||||
Object.assign(ApplicantsRelationshipData, {name_of_the_individual : ApplicantName ,applicant_id: ApplicantId, loan_no_id: LoanId ,losid: Losid });
|
||||
// if (ApiArray.lstApplicantsRelationship.length != 0)
|
||||
// {
|
||||
await ApplicantsRelationship.create(ApplicantsRelationshipData)
|
||||
.then(data=>{logMsg.info("ApplicantsRelationship inserted"); resolve()}).catch(err=>{logMsg.info("ApplicantsRelationship Failed , Msg :" +err);});
|
||||
// }
|
||||
// }
|
||||
});
|
||||
// ResidenceAddressDetails Table
|
||||
var ResidenceAddressDetailsPromise = new Promise(async(resolve, reject) =>
|
||||
{
|
||||
if(ApiArray.lstApplicantAddress.length != 0 )
|
||||
{
|
||||
// ResidenceAddressDetails data
|
||||
ApiArray.lstApplicantAddress.forEach(async(ApplicantAddress,index) =>
|
||||
{
|
||||
// Applicant Address Create
|
||||
if (ApplicantAddress.iD_ApplicantKYCDetail == String(Applicant_id) && ApplicantAddress.iD_OwnershipTypes == "Permanent")
|
||||
{
|
||||
ApplicantAddress =
|
||||
{
|
||||
name_of_the_individual : ApplicantName,
|
||||
loan_no_id : LoanId , losid : Losid , applicant_id: ApplicantId ,
|
||||
residence_address : [ApplicantAddress.address1, ApplicantAddress.address2, ApplicantAddress.address3 , ApplicantAddress.iD_States , ApplicantAddress.city , ApplicantAddress.pin ].filter(Boolean).join(" "), // concat and ignore null
|
||||
ownership_status : ApplicantAddress.iD_OwnershipTypes ,
|
||||
// residence_location_area
|
||||
}
|
||||
await ResidenceAddressDetails.create(ApplicantAddress)
|
||||
.then(data=>
|
||||
{
|
||||
logMsg.info("ResidenceAddressDetails inserted");
|
||||
if ([ApiArray.lstApplicantAddress].length - 1 == index)
|
||||
{
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
.catch(err=>{logMsg.info("ResidenceAddressDetails Failed , Msg :" +err);});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
})
|
||||
// ResidenceAddressDetails Table
|
||||
var PropertyOwnershipIncomeConsideredPromise = new Promise(async(resolve, reject) =>
|
||||
{
|
||||
// if (EntityType == "Individual")
|
||||
// {
|
||||
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);});
|
||||
// }
|
||||
});
|
||||
|
||||
|
||||
Promise.all([ApplicantsRelationshipPromise, ResidenceAddressDetailsPromise, PropertyOwnershipIncomeConsideredPromise ])
|
||||
.then((values) => {
|
||||
logMsg.info("ApplicantsRelationshipPromise ,ResidenceAddressDetailsPromise, PropertyOwnershipIncomeConsidered inserted");; // [3, 1337, "foo"]
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
catch (error)
|
||||
{
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
|
||||
loanDetailsDataApiCall : loanDetailsDataApiCall,
|
||||
getLoginToken : getLoginToken
|
||||
|
||||
getLoginToken : getLoginToken,
|
||||
EntityChildTable : EntityChildTable,
|
||||
ApplicantChildTable : ApplicantChildTable
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user