111 lines
6.4 KiB
JavaScript
111 lines
6.4 KiB
JavaScript
const { sequelize, Test, CreditGeneralInformation, SizeAndGeographicalResearch, CreditProfile, ProductAndProcess, PortFolioHealth, TotalOverallDebit, OverallPlanOfAction, ValidationPoint, CreditLoanDetail, CreditFinalRemarks, CreditGeneralBusinessInformation, CreditKeyProductBusinessContribution, EmployeeStrength, CreditBusinessAndPersonalBankingDetails, CreditFinancialInformation, SupplierDetail, ClientDetail, CreditFuturePlans, CreditExistingLoanObligation, FamilyMemberInvolvedInBusiness, CreditManager, CreditBorrowerAndGuarantorDetails, CreditFinancialAnalysis, CreditAddressDetail, CreditKeyShareholder, Covid19Questions, StockDetail, BusinessAsset, CreditFilterTable, Photograph } = require('../models')
|
|
const request = require('request');
|
|
const moment = require('moment');
|
|
const { logMsg } = require('../services/logger.js');
|
|
const Credit_PdHelper = require('../services/CreditPdHelper.js');
|
|
|
|
|
|
exports.PullCredit = async (req, res) => {
|
|
|
|
try {
|
|
const arr = [ CreditAddressDetail , CreditBorrowerAndGuarantorDetails , CreditBusinessAndPersonalBankingDetails, BusinessAsset , ClientDetail , Covid19Questions , EmployeeStrength , CreditExistingLoanObligation , FamilyMemberInvolvedInBusiness , CreditFinalRemarks , CreditFinancialAnalysis , CreditFinancialInformation , CreditFuturePlans , CreditGeneralBusinessInformation , CreditGeneralInformation , CreditKeyProductBusinessContribution , CreditKeyShareholder , CreditLoanDetail , OverallPlanOfAction , PortFolioHealth , ProductAndProcess , CreditProfile , SizeAndGeographicalResearch , StockDetail , SupplierDetail , TotalOverallDebit , ValidationPoint , CreditManager , Photograph ] ;
|
|
const tempData = JSON.parse(JSON.stringify(req.body.data));
|
|
obj = {};
|
|
GenInfoObj = {};
|
|
temp_array = [];
|
|
// create creditGeneralInormationData
|
|
Object.assign(obj, { ref_no: req.body.pdid , product :req.body.product , case_no :req.body.caseno});
|
|
PDID = await CreditGeneralInformation.create(obj)
|
|
logMsg.info("GeneralInformation insert success ,PdId= "+PDID.dataValues.pd_id);
|
|
for (var [OverallKey, OverallValue] of Object.entries(tempData)) {
|
|
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)) {
|
|
if (Array.isArray(OverallValue[ObjectKey]) == true)
|
|
{
|
|
temp_array = await Credit_PdHelper.ARRAY( OverallValue[ObjectKey] , GenInfoObj , OverallKey )
|
|
}
|
|
else if (typeof OverallValue[ObjectKey] === "object" && ( OverallValue[ObjectKey] !== null ))
|
|
{
|
|
delete OverallValue[ObjectKey].display_data; delete OverallValue.display_data;
|
|
obj = await Credit_PdHelper.OBJECT( OverallValue, ObjectKey , OverallValue[ObjectKey] )
|
|
}
|
|
else if (moment(OverallValue[ObjectKey], "DD-MM-YYYY", true).isValid() == true || moment(OverallValue[ObjectKey], "DD/MM/YYYY hh:mm:ss A", true).isValid() == true )
|
|
{
|
|
date = await Credit_PdHelper.DATE( OverallValue[ObjectKey] );
|
|
Object.assign(obj, { [ObjectKey]: date });
|
|
if (OverallKey == "Officer Details") { Object.assign(GenInfoObj,{[ObjectKey] : date}) };
|
|
}
|
|
else
|
|
{
|
|
Object.assign(obj, { [ObjectKey]: ObjectValue });
|
|
if (OverallKey == "Borrower & Guarantor Details" && ObjectKey == "common_remarks") { Object.assign(GenInfoObj,{remarks : ObjectValue}) };
|
|
if (OverallKey == "Loan details" && ObjectKey == "loan_amount") { Object.assign(GenInfoObj,{loan_amount : ObjectValue}) };
|
|
if (OverallKey == "Officer Details") { Object.assign(GenInfoObj,{[ObjectKey] : ObjectValue}) };
|
|
}
|
|
}
|
|
// DB Insertion
|
|
if (OverallKey == "Officer Details") { 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) => {
|
|
Object.assign(element , {pd_id : PDID.dataValues.pd_id} ); Object.assign(element ,obj );
|
|
var index = table_name[0].table_name; var tableName = arr[index]
|
|
await tableName.create(element); logMsg.info(OverallKey+" insert success ,PdId= "+PDID.dataValues.pd_id);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
Object.assign(obj , {pd_id : PDID.dataValues.pd_id} );
|
|
var index = table_name[0].table_name; var tableName = arr[index]
|
|
tableName.create(obj);logMsg.info(OverallKey+" insert success ,PdId= "+PDID.dataValues.pd_id);
|
|
}
|
|
}
|
|
res.send({'status':200,'message':"success"});
|
|
}
|
|
catch (err) {
|
|
res.send({ 'status': 404, message: err.message || "Some error occurred while retrieving data.", 'data': "No data" });
|
|
} //end of try catch
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.getTable = async (req, res) =>
|
|
{
|
|
try
|
|
{
|
|
var resData = await CreditGeneralInformation.findOne({ where : { pd_id : req.query.pd_id ,is_active : 1},
|
|
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: Photograph },
|
|
{model: CreditFinalRemarks }, {model: CreditLoanDetail },
|
|
{model: CreditGeneralBusinessInformation }, {model: SupplierDetail }
|
|
]
|
|
})
|
|
res.send({'status':200,'message':"success",'data':resData});
|
|
}
|
|
catch(err) {
|
|
res.status(500).send({'status':404,
|
|
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
|
|
});
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|