143 lines
4.8 KiB
JavaScript
143 lines
4.8 KiB
JavaScript
const { keys, values } = require('lodash');
|
|
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 { logMsg } = require('../services/logger.js');
|
|
const request = require('request');
|
|
const moment = require('moment');
|
|
|
|
async function CreditPd(credit_key , credit_value ,credit_temp_array ,credit_obj) {
|
|
for (let i = 0; i < credit_temp_array.length; i++) {
|
|
if ( Object.keys(credit_value).includes(credit_temp_array[i]) ) {
|
|
await Object.assign( credit_obj, { [credit_key] : credit_value[credit_temp_array[i]] });
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
async function MainApplicantDetails(losid) {
|
|
try {
|
|
const url = `${ process.env.MAIN_APPLICANT_DETAIL }/MainApplicantDetailsList?losid=`+losid;
|
|
|
|
return new Promise((resolve, reject) => {
|
|
request({
|
|
url: url,
|
|
method: "GET"
|
|
|
|
}, function (error, response, body) {
|
|
resolve(body);
|
|
});
|
|
|
|
});
|
|
}
|
|
catch (error) {
|
|
console.log(error);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// OBJECT
|
|
async function OBJECT(OverAllobject , objectKey , ParticularObj) {
|
|
try
|
|
{
|
|
|
|
const DumpObject = {"address_type" : "address_type" , "pd_locality" : "locality_name", "pd_location" : "description" , "comment_locality" : "rating" , "relationship" : "name" , "company_relation" : "name"} ;
|
|
return new Promise((resolve, reject) =>
|
|
{
|
|
// if(OverAllobject[objectKey] == ""){delete OverAllobject[objectKey];}
|
|
Objkey = DumpObject[objectKey];
|
|
Object.assign(OverAllobject , { [objectKey] : ParticularObj[Objkey]})
|
|
resolve(OverAllobject)
|
|
})
|
|
}
|
|
catch (error)
|
|
{
|
|
console.log(error);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//DATE
|
|
async function DATE(date) {
|
|
try
|
|
{
|
|
return new Promise((resolve, reject) =>
|
|
{
|
|
var mydate = moment(date, "DD-MM-YYYY hh:mm:ss A"); // convert dd/mm/yyyy to yyyy/mm/dd
|
|
var my_date = moment(mydate).format("YYYY-MM-DD hh:mm:ss A")
|
|
resolve(my_date)
|
|
})
|
|
}
|
|
catch (error)
|
|
{
|
|
console.log(error);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//ARRAY
|
|
async function ARRAY(Array , GenInfoObj , OverallKey) {
|
|
try
|
|
{
|
|
ArrayObj = { };
|
|
tempArr = [ ];
|
|
return new Promise((resolve, reject) =>
|
|
{
|
|
Array.forEach(async(element,index,array) => {
|
|
for (var [Key, Value] of Object.entries(element)) {
|
|
// if(Value == ""){delete element[Key];}
|
|
if (typeof Value === "object" && ( Value !== null )) {
|
|
Obj = await OBJECT( element, Key , Value );
|
|
Object.assign(ArrayObj, Obj )
|
|
} else {
|
|
Object.assign(ArrayObj,{ [Key] : Value })
|
|
}
|
|
if (OverallKey == "Borrower & Guarantor Details" && Key == "numbers_of_years_business_running" )
|
|
{
|
|
|
|
if(typeof element.numbers_of_years_business_running === 'number')
|
|
{
|
|
|
|
//RoundOfValue = Math.round(element.numbers_of_years_business_running,2).toString();
|
|
RoundOfValue = Number((element.numbers_of_years_business_running).toFixed(2).toString());
|
|
Object.assign(ArrayObj,{ numbers_of_years_business_running : RoundOfValue });
|
|
}
|
|
}
|
|
|
|
if (OverallKey == "Borrower & Guarantor Details" && Key == "borrower_age" )
|
|
{
|
|
|
|
if(typeof element.borrower_age === 'number')
|
|
{
|
|
//RoundOfValue = Math.round(element.numbers_of_years_business_running,2).toString();
|
|
RoundOfAge = Number((element.borrower_age).toFixed(2).toString());
|
|
Object.assign(ArrayObj,{ borrower_age : RoundOfAge });
|
|
} else if(typeof element.borrower_age === 'string'){ Object.assign(ArrayObj,{ borrower_age : null }); }
|
|
}
|
|
}
|
|
tempArr.push(ArrayObj)
|
|
ArrayObj = { };
|
|
if (array.length - 1 == index) {
|
|
resolve(tempArr)
|
|
}
|
|
});
|
|
})
|
|
}
|
|
catch (error)
|
|
{
|
|
console.log(error);
|
|
}
|
|
}
|
|
|
|
|
|
module.exports = {
|
|
|
|
OBJECT : OBJECT,
|
|
CreditPd : CreditPd ,
|
|
MainApplicantDetails : MainApplicantDetails,
|
|
DATE : DATE,
|
|
ARRAY : ARRAY
|
|
} |