This commit is contained in:
sriramv 2023-04-03 15:39:02 +05:30
parent 567030b99e
commit c414b9bf69
3 changed files with 36 additions and 27 deletions

View File

@ -18,22 +18,28 @@ exports.PullCreditPdData = async (req, res) => {
CreditGeneralInformationDataExist = await CreditGeneralInformation.findOne({ where : { ref_no : req.body.pdid ,product:req.body.product,case_no :req.body.caseno, is_active : 1 }});
if(CreditGeneralInformationDataExist)
{
await CreditGeneralInformation.destroy({ where : { pd_id : CreditGeneralInformationDataExist.dataValues.pd_id},
include : [
{model: CreditAddressDetail }, {model: CreditFuturePlans },
{model : CreditBorrowerAndGuarantorDetails },
{model: CreditBusinessAndPersonalBankingDetails }, {model: BusinessAsset },
{model: CreditFinancialInformation }, {model: CreditKeyShareholder },
{model: CreditKeyProductBusinessContribution }, {model: EmployeeStrength },
{model: ClientDetail }, {model: StockDetail },
{model: CreditExistingLoanObligation },
{model: FamilyMemberInvolvedInBusiness },
{model : CreditManager },
{model: CreditFinalRemarks }, {model: CreditLoanDetail },
{model: CreditGeneralBusinessInformation },
{model: SupplierDetail }
]
});
CreditGeneralInformation.destroy({ where : { pd_id : CreditGeneralInformationDataExist.dataValues.pd_id}
}).then(data=>{
CreditAddressDetail.destroy({ where : { pd_id : CreditGeneralInformationDataExist.dataValues.pd_id}});
CreditFuturePlans.destroy({ where : { pd_id : CreditGeneralInformationDataExist.dataValues.pd_id}});
CreditBorrowerAndGuarantorDetails.destroy({ where : { pd_id : CreditGeneralInformationDataExist.dataValues.pd_id}});
CreditBusinessAndPersonalBankingDetails.destroy({ where : { pd_id : CreditGeneralInformationDataExist.dataValues.pd_id}});
BusinessAsset.destroy({ where : { pd_id : CreditGeneralInformationDataExist.dataValues.pd_id}});
CreditFinancialInformation.destroy({ where : { pd_id : CreditGeneralInformationDataExist.dataValues.pd_id}});
CreditKeyShareholder.destroy({ where : { pd_id : CreditGeneralInformationDataExist.dataValues.pd_id}});
CreditKeyProductBusinessContribution.destroy({ where : { pd_id : CreditGeneralInformationDataExist.dataValues.pd_id}});
EmployeeStrength.destroy({ where : { pd_id : CreditGeneralInformationDataExist.dataValues.pd_id}});
ClientDetail.destroy({ where : { pd_id : CreditGeneralInformationDataExist.dataValues.pd_id}});
StockDetail.destroy({ where : { pd_id : CreditGeneralInformationDataExist.dataValues.pd_id}});
CreditExistingLoanObligation.destroy({ where : { pd_id : CreditGeneralInformationDataExist.dataValues.pd_id}});
FamilyMemberInvolvedInBusiness.destroy({ where : { pd_id : CreditGeneralInformationDataExist.dataValues.pd_id}});
CreditManager.destroy({ where : { pd_id : CreditGeneralInformationDataExist.dataValues.pd_id}});
CreditFinalRemarks.destroy({ where : { pd_id : CreditGeneralInformationDataExist.dataValues.pd_id}});
CreditLoanDetail.destroy({ where : { pd_id : CreditGeneralInformationDataExist.dataValues.pd_id}});
CreditGeneralBusinessInformation.destroy({ where : { pd_id : CreditGeneralInformationDataExist.dataValues.pd_id}});
SupplierDetail.destroy({ where : { pd_id : CreditGeneralInformationDataExist.dataValues.pd_id}});
}).catch(err=>{logMsg.info("GeneralInformation Deletion failed ,PdId(ref_no)= "+req.body.pdid+ " ERR =" + err); });
// res.send({'status':200, 'message': "data already exist." ,'data': "No data" });
// logMsg.info("CreditGeneralInformation data already exist.,PdId(ref_no)= "+req.body.pdid);
// }
@ -61,13 +67,14 @@ exports.PullCreditPdData = async (req, res) => {
await CreditGeneralInformation.create(obj)
.then((successData)=>{logMsg.info("GeneralInformation insert success ,PdId= "+successData.dataValues.pd_id);})
.catch((err)=>{ logMsg.info("GeneralInformation insert failed ,PdId(ref_no)= "+req.body.pdid+ " ERR =" + err); });
Object.assign(tempData.data , {last_index : {}});
PDID = await CreditGeneralInformation.findOne({ where : { ref_no : req.body.pdid ,case_no :req.body.caseno, is_active : 1 }});
length = [];
for (var [OverallKey, OverallValue] of Object.entries(tempData.data)) {
if(OverallKey != "Officer Details")
table_name = await CreditFilterTable.findAll({ raw: true, attributes: [ 'table_name'], where : { section : OverallKey , is_active : 1 } , group: ['table_name']})
length.push(OverallKey);
if(OverallKey != "Officer Details" || OverallKey != "last_index"){
table_name = await CreditFilterTable.findAll({ raw: true, attributes: [ 'table_name'], where : { section : OverallKey , is_active : 1 } , group: ['table_name']});
}
obj = { };
temp_array.length = 0 ;
for (var [ObjectKey, ObjectValue] of Object.entries(OverallValue)) {
@ -96,7 +103,8 @@ exports.PullCreditPdData = async (req, res) => {
}
}
// DB Insertion
if (OverallKey == "last_index") { await CreditGeneralInformation.update(GenInfoObj , { where : { pd_id : PDID.dataValues.pd_id , is_active : 1}}); logMsg.info("CreditGeneralInformation update success ,PdId= "+PDID.dataValues.pd_id); }
if (Object.entries(tempData.data).length == length.length) { await CreditGeneralInformation.update(GenInfoObj , { where : { pd_id : PDID.dataValues.pd_id , is_active : 1}}); logMsg.info("CreditGeneralInformation update success ,PdId= "+PDID.dataValues.pd_id); }
if (temp_array.length > 0)
{
temp_array.forEach(async(element) => {
@ -111,7 +119,8 @@ exports.PullCreditPdData = async (req, res) => {
});
}
else
{
{
if(OverallKey != "Officer Details") {
Object.assign(obj , {pd_id : PDID.dataValues.pd_id} );
var index = table_name[0].table_name;
var tableName = arr[index];
@ -119,9 +128,11 @@ exports.PullCreditPdData = async (req, res) => {
await tableName.create(obj)
.then((successData)=>{logMsg.info(tableName+" insert success ,PdId= "+successData.dataValues.pd_id);})
.catch((err)=>{ logMsg.info(tableName+" insert failed ,PdId= "+PDID.dataValues.pd_id+ " ERR =" + err); });
}
}
}
}
res.send({'status':200,'message':"success"});
}//end of else condition
}

View File

@ -19,7 +19,7 @@ module.exports = app => {
* description: success
*/
router.get("/demo", Mycontroller.Welcome);
router.get("/test", Mycontroller.test);
router.post("/ReInsertImageData", CreditPdController.ReInsertImageData);

View File

@ -102,7 +102,6 @@ async function ARRAY(Array , GenInfoObj , OverallKey) {
//RoundOfValue = Math.round(element.numbers_of_years_business_running,2).toString();
RoundOfValue = Number((element.numbers_of_years_business_running).toFixed(2).toString());
console.log(RoundOfValue);
Object.assign(ArrayObj,{ numbers_of_years_business_running : RoundOfValue });
}
}
@ -114,7 +113,6 @@ async function ARRAY(Array , GenInfoObj , OverallKey) {
{
//RoundOfValue = Math.round(element.numbers_of_years_business_running,2).toString();
RoundOfAge = Number((element.borrower_age).toFixed(2).toString());
console.log(RoundOfAge);
Object.assign(ArrayObj,{ borrower_age : RoundOfAge });
} else if(typeof element.borrower_age === 'string'){ Object.assign(ArrayObj,{ borrower_age : null }); }
}