Swagger array of object update : suseendhiran

This commit is contained in:
suseendhiran17 2022-07-29 10:40:05 +05:30
parent 604a9122d0
commit cc933c4d05
3 changed files with 242 additions and 125 deletions

View File

@ -423,7 +423,6 @@ exports.updateDueDiligenceCheck = async (req, res) =>
{
id = element.id;
delete element.id;
console.log(element);
// update value
DueDiligenceCheck.update(element,{ where: { id: id }}).then(data =>
{
@ -965,7 +964,6 @@ exports.updateLoanDetail = async (req, res) =>
updatedby = req.body.updatedby;
delete req.body.id;
delete req.body.updatedby;
// update old value is_active = 0 where requested id
await LoanDetail.update(req.body,{ where: { id: id }}).then(data=>{
res.send({'status':200,'message':"success",'data':data})
})

View File

@ -9,75 +9,169 @@ const moment = require('moment');
//LoanDeatilList List Api
exports.LoanDeatilListTEST = async (req, res) =>
{
try
{
data = await ApiCallHelper.loanDetailsDataApiCall('MW00004618','AXZPP6264B');
res.send({'status':200,'message':"success",'data':data});
// if (data.status == 'Successful')
// {
// if (data.lstLoanApplication.length != 0)
// {
// loanDetailData = data.lstLoanApplication[0];
// loanDetailObject = {
// applicationNo : loanDetailData.applicationNo,
// losid : loanDetailData.loginNo ,
// date_of_login : moment(new Date(loanDetailData.loginDate)).format("YYYY-MM-DD"),
// sourcing_channel_name : loanDetailData.source,
// emi_of_loan_applied_for : LoanDeatilList.loanAmount,
// //product : LoanDeatilList.iD_LoanProduct
// }
// LoanDetail.create(loanDetailObject).then(LoanDetailData =>
// {
// if (data.lstApplicantKYCDetail.length != 0)
// {
// var ApplicantKYCDetailDataInsert = new Promise(async(resolve, reject) => {
// lstApplicantKYCDetailDataArray = [];
// data.lstApplicantKYCDetail.forEach(async(value,index,array) => {
// lstApplicantKYCDetailObj = {
// }
// lstApplicantKYCDetailDataArray.push(lstApplicantKYCDetailObj);
// if (index === array.length -1) { resolve(lstApplicantKYCDetailDataArray); }
// });
// });
// ApplicantKYCDetailDataInsert.then(async(lstApplicantKYCDetailDataArray)=>{
// console.log(lstApplicantKYCDetailDataArray);
// await ApplicantsDetails.bulkCreate(lstApplicantKYCDetailDataArray).catch(err=>{ });
// });
try
{
data = await ApiCallHelper.loanDetailsDataApiCall('MW00004618','AXZPP6264B');
Applicant_id = { };
if (data.lstLoanApplication.length != 0)
{
loanDetailData = data.lstLoanApplication[0];
loanDetailObject =
{
applicationNo : loanDetailData.applicationNo,
losid : loanDetailData.loginNo ,
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
}
LoanDetail.create(loanDetailObject).then(LoanDetailData =>
{
// entity detail promise
var EntityKYCDetailDataInsert = new Promise(async(resolve, reject) =>
{
lstEntityKYCDetailDataArray = [];
data.lstApplicantKYCDetail.forEach(async(value,index,array) => {
if (value.kycType == "Non-Individual ")
{
lstEntityKYCDetailObj =
{
losid : LoanDetailData.dataValues.losid ,
loan_no_id : LoanDetailData.dataValues.id ,
entity_name : [value.firstName, value.middleName, value.lastName ].filter(Boolean).join(" "),
entity_formation_date : moment(new Date(value.doi)).format("YYYY-MM-DD"),
// entity_type : value.kycType
}
data.lstApplicantAddress.forEach(async(address_value,index) =>
{
if (value.iD_ApplicantKYCDetail == address_value.iD_ApplicantKYCDetail && address_value.iD_OwnershipTypes == "Permanent" )
{
lstEntityAddressDetailObj =
{
registered_address_of_business: [address_value.address1, address_value.address2, address_value.address3 ].filter(Boolean).join(" "),
registered_address_state: address_value.iD_States,
registered_address_city: address_value.city,
registered_address_pin: address_value.pin,
registered_address_ownership_status:address_value.iD_OwnershipTypes
}
Object.assign(lstEntityKYCDetailObj,lstEntityAddressDetailObj)
}
else if(value.iD_ApplicantKYCDetail == address_value.iD_ApplicantKYCDetail && address_value.iD_OwnershipTypes == "Current" )
{
lstEntityAddress1DetailObj =
{
operating_address_of_business: [address_value.address1, address_value.address2, address_value.address3 ].filter(Boolean).join(" "),
operating_address_state: address_value.iD_States,
operating_address_city: address_value.city,
operating_address_pin: address_value.pin,
operating_address_ownership_status:address_value.iD_OwnershipTypes,
// operating_address_city_category : address_value.addressCategory
}
Object.assign(lstEntityKYCDetailObj,lstEntityAddress1DetailObj)
}
});
lstEntityKYCDetailDataArray.push(lstEntityKYCDetailObj);
}
if (index === array.length -1)
{
resolve(lstEntityKYCDetailDataArray);
}
});
}); // end of entity detail promise
// Create entity detail
EntityKYCDetailDataInsert.then(async(lstEntityKYCDetailDataArray)=>
{
lstEntityKYCDetailDataArray.forEach(async(element) =>
{
await EntityDetails.create(element)
.then(data=>{ logMsg.info("EntityDetails inserted"); })
.catch(err=>{ logMsg.info("EntityDetails Failed , Msg :" +err); });
});
});
// } else { } // lstApplicantKYCDetail array is empty from Los api
// }).catch(err => {res.send({'status':404,message: err.message || "Some error occurred while retrieving statements." ,'data': "No data" });});
// } else { } // lstLoanApplication array is empty from Los api
// } else { } // Los api call failed
// application detail promise
var ApplicantKYCDetailDataInsert = new Promise(async(resolve, reject) =>
{
lstApplicantKYCDetailDataArray = [];
data.lstApplicantKYCDetail.forEach(async(value,index,array) => {
if (value.kycType == "Individual ")
{
Applicant_id = value.iD_ApplicantKYCDetail;
lstApplicantKYCDetailObj =
{
losid : LoanDetailData.dataValues.losid ,
loan_no_id : LoanDetailData.dataValues.id ,
name : [value.firstName, value.middleName, value.lastName ].filter(Boolean).join(" "),
}
lstApplicantKYCDetailDataArray.push(lstApplicantKYCDetailObj);
}
if (index === array.length -1)
{
resolve(lstApplicantKYCDetailDataArray);
}
});
}); // end of application detail promise
// Create Application detail, Address detail , Relationship detail
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);});
}
});
}
}).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
// LoanDetail.findAll({raw: true , where : { losid : req.query.losid , 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 : { losid : "MW00004618" , 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" });
});
} 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 block
catch(err)
{
res.send({'status':404,message: err.message || "Some error occurred while inserting statements." ,'data': "No data" });
} //end of try catch
};

View File

@ -1433,36 +1433,38 @@ router.post("/updateEnquiriesAndDisbursementsDetails", Entitycontroller.updateEn
* @swagger
* definitions:
* updateDueDiligenceCheck:
* type: object
* properties:
* id:
* type: integer
* description:
* example: 1
* entity_id:
* type: integer
* description:
* example: 1
* check_type_id:
* type: integer
* description:
* example: 1
* check_type:
* type: string
* description:
* example: ROC Check
* check_result:
* type: string
* description:
* example: Negative
* remarks:
* type: string
* description:
* example: No Feedback
* updatedby:
* type: integer
* description:
* example: 1
* type: array
* items:
* type: object
* properties:
* id:
* type: integer
* description:
* example: 1
* entity_id:
* type: integer
* description:
* example: 1
* check_type_id:
* type: integer
* description:
* example: 1
* check_type:
* type: string
* description:
* example: ROC Check
* check_result:
* type: string
* description:
* example: Negative
* remarks:
* type: string
* description:
* example: No Feedback
* updatedby:
* type: integer
* description:
* example: 1
*/
/**
* @swagger
@ -2084,36 +2086,59 @@ router.get("/atnwRelationMaster", Mastercontroller.atnwRelationMaster);
* @swagger
* definitions:
* updateATNWrelatedInputs:
* type: object
* properties:
* id:
* type: integer
* description:
* example: 1
* entity_id:
* type: integer
* description:
* example: 1
* atnw_related_input_id:
* type: integer
* description:
* example: 1
* atnw_related_input:
* type: string
* description:
* example: property_own_doc_avail
* atnw_related_input_value:
* type: string
* description:
* example: Yes
* updatedby:
* type: integer
* description:
* example: 1
* subValue:
* type: string
* description: json string
* example:
* type: array
* items:
* type: object
* properties:
* id:
* type: integer
* description:
* example: 1
* entity_id:
* type: integer
* description:
* example: 1
* atnw_related_input_id:
* type: integer
* description:
* example: 1
* atnw_related_input:
* type: string
* description:
* example: property_own_doc_avail
* atnw_related_input_value:
* type: string
* description:
* example: Yes
* updatedby:
* type: integer
* description:
* example: 1
* subValue:
* type: array
* items:
* type: object
* properties:
* id:
* type: integer
* description:
* example: 1
* master_id:
* type: integer
* description:
* example: 1
* atnw_related_input:
* type: integer
* description:
* example: 1
* atnw_related_input_value:
* type: integer
* description:
* example: 1
* updatedby:
* type: integer
* description:
* example: 1
*/
/**
* @swagger