changes in select api : suseendhiran
This commit is contained in:
parent
6ff3c97757
commit
01fae2f460
@ -1,5 +1,4 @@
|
|||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
|
|
||||||
const { logMsg } = require('../services/logger');
|
const { logMsg } = require('../services/logger');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
||||||
@ -12,5 +11,6 @@ module.exports = {
|
|||||||
"dialect": "mssql",
|
"dialect": "mssql",
|
||||||
"logging": (message) =>(logMsg.info(message))
|
"logging": (message) =>(logMsg.info(message))
|
||||||
|
|
||||||
}
|
},
|
||||||
};
|
|
||||||
|
};
|
||||||
110
app/controllers/credit.js
Normal file
110
app/controllers/credit.js
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
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"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,21 +1,10 @@
|
|||||||
const { keys, values, forEach } = 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 { 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 { logMsg } = require('../services/logger.js');
|
||||||
const Credit_PdHelper = require('../services/CreditPdHelper.js');
|
const Credit_PdHelper = require('../services/CreditPdHelper.js');
|
||||||
const request = require('request');
|
const request = require('request');
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
var global = require('global');
|
var global = require('global');
|
||||||
global.arr = [ CreditAddressDetail , CreditBorrowerAndGuarantorDetails , CreditBusinessAndPersonalBankingDetails,
|
global.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 ]
|
||||||
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 ]
|
|
||||||
|
|
||||||
exports.Welcome = (req, res) =>
|
exports.Welcome = (req, res) =>
|
||||||
{
|
{
|
||||||
@ -45,171 +34,172 @@ exports.Welcome = (req, res) =>
|
|||||||
exports.PullCreditPdData = async (req, res) =>
|
exports.PullCreditPdData = async (req, res) =>
|
||||||
{
|
{
|
||||||
|
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
|
console.log(req.body);
|
||||||
const tempData = JSON.parse(JSON.stringify(req.body.data));
|
const tempData = JSON.parse(JSON.stringify(req.body.data));
|
||||||
var obj = { };
|
// var obj = { };
|
||||||
var temp_obj = [ ];
|
// var temp_obj = [ ];
|
||||||
var arr_ObjKey = [ ]
|
// var arr_ObjKey = [ ]
|
||||||
var creditFilter_obj_key = [ ];
|
// var creditFilter_obj_key = [ ];
|
||||||
var creditFilter_table_name = [ ];
|
// var creditFilter_table_name = [ ];
|
||||||
var key_for_arrays = [ ];
|
// var key_for_arrays = [ ];
|
||||||
var name;
|
// var name;
|
||||||
var loan_amount;
|
// var loan_amount;
|
||||||
var pd_id = [ ];
|
// var pd_id = [ ];
|
||||||
var resPonse = [ ];
|
// var resPonse = [ ];
|
||||||
|
|
||||||
|
|
||||||
// create creditGeneralInormationData
|
// // create creditGeneralInormationData
|
||||||
resPonse.length = 0 ; // clear array datas
|
// resPonse.length = 0 ; // clear array datas
|
||||||
for (const [key, value] of Object.entries(tempData))
|
// for (const [key, value] of Object.entries(tempData))
|
||||||
{
|
// {
|
||||||
if (key == "Loan details" || key =="Borrower & Guarantor Details" || key == "Officer Details")
|
// if (key == "Loan details" || key =="Borrower & Guarantor Details" || key == "Officer Details")
|
||||||
{
|
// {
|
||||||
for (var [keys, element] of Object.entries(value))
|
// for (var [keys, element] of Object.entries(value))
|
||||||
{
|
// {
|
||||||
if ( Array.isArray(element) == true )
|
// if ( Array.isArray(element) == true )
|
||||||
{
|
// {
|
||||||
element.forEach(async(element , index) => {
|
// element.forEach(async(element , index) => {
|
||||||
if ( keys == 'borrower_details' && index == 0 )
|
// if ( keys == 'borrower_details' && index == 0 )
|
||||||
{
|
// {
|
||||||
Object.assign( obj , {name : element['borrower_name']})
|
// Object.assign( obj , {name : element['borrower_name']})
|
||||||
Object.assign(obj, { ref_no: req.body.pdid , product :req.body.product , case_no :req.body.caseno});
|
// Object.assign(obj, { ref_no: req.body.pdid , product :req.body.product , case_no :req.body.caseno});
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
if ( key == "Borrower & Guarantor Details" && keys == 'common_remarks') { Object.assign( obj , {remarks : element}) }
|
// if ( key == "Borrower & Guarantor Details" && keys == 'common_remarks') { Object.assign( obj , {remarks : element}) }
|
||||||
if ( keys == 'loan_amount') { { Object.assign( obj , { loan_amount : element })} };
|
// if ( keys == 'loan_amount') { { Object.assign( obj , { loan_amount : element })} };
|
||||||
if ( key == "Officer Details")
|
// if ( key == "Officer Details")
|
||||||
{
|
// {
|
||||||
if (moment(element, "DD/MM/YYYY hh:mm:ss A", true).isValid() == true) {
|
// if (moment(element, "DD/MM/YYYY hh:mm:ss A", true).isValid() == true) {
|
||||||
var mydate = moment(element, "DD/MM/YYYY hh:MM:ss A"); // convert dd/mm/yyyy to yyyy/mm/dd
|
// var mydate = moment(element, "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")
|
// var my_date = moment(mydate).format("YYYY-MM-DD HH:mm:ss A")
|
||||||
Object.assign( obj, { [keys] : my_date });
|
// Object.assign( obj, { [keys] : my_date });
|
||||||
}
|
// }
|
||||||
else{
|
// else{
|
||||||
Object.assign(obj, { [ keys ] : element });
|
// Object.assign(obj, { [ keys ] : element });
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
// Object.assign( obj , { ref_no : req.body.pdid });
|
// // Object.assign( obj , { ref_no : req.body.pdid });
|
||||||
console.log(obj);
|
// console.log(obj);
|
||||||
pd_id = await CreditGeneralInformation.create(obj)
|
// pd_id = await CreditGeneralInformation.create(obj)
|
||||||
// .then((successData)=>{logMsg.info("GeneralInformation insert success ,PdId= "+successData.dataValues.pd_id);})
|
// // .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); });
|
// // .catch((err)=>{ logMsg.info("GeneralInformation insert failed ,PdId(ref_no)= "+req.body.pdid); });
|
||||||
// pd_id = await CreditGeneralInformation.findOne({ where : { ref_no : req.body.pdid , is_active : 1 }});
|
// // pd_id = await CreditGeneralInformation.findOne({ where : { ref_no : req.body.pdid , is_active : 1 }});
|
||||||
|
|
||||||
|
|
||||||
// loop to check if the data is array or nestedObject or objects
|
// // loop to check if the data is array or nestedObject or objects
|
||||||
for (const [key, value] of Object.entries(tempData)) {
|
// for (const [key, value] of Object.entries(tempData)) {
|
||||||
console.log(key);
|
// console.log(key);
|
||||||
creditFilter_obj_key = await CreditFilterTable.findAll({ raw: true , attributes: [ 'mul_key' ], where : { section : key , is_active : 1 , is_mul : 1}})
|
// creditFilter_obj_key = await CreditFilterTable.findAll({ raw: true , attributes: [ 'mul_key' ], where : { section : key , is_active : 1 , is_mul : 1}})
|
||||||
creditFilter_table_name = await CreditFilterTable.findAll({ raw: true, attributes: [ 'table_name' ,'section' ,'ques_key'], where : { section : key , is_active : 1 } , group: ['table_name' , 'section' ,'ques_key']})
|
// creditFilter_table_name = await CreditFilterTable.findAll({ raw: true, attributes: [ 'table_name' ,'section' ,'ques_key'], where : { section : key , is_active : 1 } , group: ['table_name' , 'section' ,'ques_key']})
|
||||||
|
|
||||||
for (let index = 0; index < creditFilter_obj_key.length; index++)
|
// for (let index = 0; index < creditFilter_obj_key.length; index++)
|
||||||
{
|
// {
|
||||||
arr_ObjKey.push(creditFilter_obj_key[index].mul_key) // store nested obj keys
|
// arr_ObjKey.push(creditFilter_obj_key[index].mul_key) // store nested obj keys
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
if (key == creditFilter_table_name[0].section) {
|
// if (key == creditFilter_table_name[0].section) {
|
||||||
temp_obj.length = 0 ; // clear array datas
|
// temp_obj.length = 0 ; // clear array datas
|
||||||
obj = { }; // clear obj datas
|
// obj = { }; // clear obj datas
|
||||||
|
|
||||||
// Check if the data is array or not
|
// // Check if the data is array or not
|
||||||
for (var [arr_keys, arr_of_element] of Object.entries(value)) {
|
// for (var [arr_keys, arr_of_element] of Object.entries(value)) {
|
||||||
if ( Array.isArray(arr_of_element) == true )
|
// if ( Array.isArray(arr_of_element) == true )
|
||||||
{
|
// {
|
||||||
arr_of_element.forEach(async(iter_element , index) =>
|
// arr_of_element.forEach(async(iter_element , index) =>
|
||||||
{
|
// {
|
||||||
if (Object.keys(iter_element)[0] == '0')
|
// if (Object.keys(iter_element)[0] == '0')
|
||||||
{
|
// {
|
||||||
Object.assign( obj, { [arr_keys] : iter_element });
|
// Object.assign( obj, { [arr_keys] : iter_element });
|
||||||
}
|
// }
|
||||||
// assign array of objects
|
// // assign array of objects
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
key_for_arrays = Object.keys(iter_element);
|
// key_for_arrays = Object.keys(iter_element);
|
||||||
Object.values(iter_element).forEach( async (element_ele , index ) => {
|
// Object.values(iter_element).forEach( async (element_ele , index ) => {
|
||||||
if ( typeof element_ele === "object" && ( element_ele !== null ))
|
// if ( typeof element_ele === "object" && ( element_ele !== null ))
|
||||||
{
|
// {
|
||||||
delete element_ele.display_data;
|
// delete element_ele.display_data;
|
||||||
delete value.display_data;
|
// delete value.display_data;
|
||||||
await Credit_PdHelper.CreditPd( key_for_arrays[index] , element_ele , arr_ObjKey , obj )
|
// await Credit_PdHelper.CreditPd( key_for_arrays[index] , element_ele , arr_ObjKey , obj )
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
// temp_obj.push(iter_element) ;
|
// // temp_obj.push(iter_element) ;
|
||||||
Object.assign( obj, { [key_for_arrays[index]] : element_ele });
|
// Object.assign( obj, { [key_for_arrays[index]] : element_ele });
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
temp_obj.push(obj)
|
// temp_obj.push(obj)
|
||||||
obj = { }; // clear obj datas
|
// obj = { }; // clear obj datas
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
// end of array
|
// // end of array
|
||||||
// assign nestedObject datas
|
// // assign nestedObject datas
|
||||||
else if( typeof arr_of_element === "object" && ( arr_of_element !== null ) )
|
// else if( typeof arr_of_element === "object" && ( arr_of_element !== null ) )
|
||||||
{
|
// {
|
||||||
delete arr_of_element.display_data;
|
// delete arr_of_element.display_data;
|
||||||
delete value.display_data;
|
// delete value.display_data;
|
||||||
await Credit_PdHelper.CreditPd( arr_keys , arr_of_element , arr_ObjKey , obj )
|
// await Credit_PdHelper.CreditPd( arr_keys , arr_of_element , arr_ObjKey , obj )
|
||||||
}
|
// }
|
||||||
// assign object data
|
// // assign object data
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
if (moment(arr_of_element, "DD-MM-YYYY", true).isValid() == true)
|
// if (moment(arr_of_element, "DD-MM-YYYY", true).isValid() == true)
|
||||||
{
|
// {
|
||||||
var mydate = moment(arr_of_element, "DD-MM-YYYY"); // convert dd/mm/yyyy to yyyy/mm/dd
|
// var mydate = moment(arr_of_element, "DD-MM-YYYY"); // convert dd/mm/yyyy to yyyy/mm/dd
|
||||||
var my_date = moment(mydate).format("YYYY-MM-DD")
|
// var my_date = moment(mydate).format("YYYY-MM-DD")
|
||||||
Object.assign( obj, { [arr_keys] : my_date });
|
// Object.assign( obj, { [arr_keys] : my_date });
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
Object.assign( obj, { [arr_keys] : arr_of_element });
|
// Object.assign( obj, { [arr_keys] : arr_of_element });
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}// end of inner forLoop
|
// }// end of inner forLoop
|
||||||
|
|
||||||
|
|
||||||
// DB insertion
|
// // DB insertion
|
||||||
|
|
||||||
|
|
||||||
if (temp_obj.length != 0 ) // insert array of object datas
|
// if (temp_obj.length != 0 ) // insert array of object datas
|
||||||
{
|
// {
|
||||||
temp_obj.forEach( async (temp_obj_element) =>
|
// temp_obj.forEach( async (temp_obj_element) =>
|
||||||
{
|
// {
|
||||||
Object.assign( obj,{ pd_id : pd_id.pd_id} );
|
// Object.assign( obj,{ pd_id : pd_id.pd_id} );
|
||||||
Object.assign( obj,temp_obj_element );
|
// Object.assign( obj,temp_obj_element );
|
||||||
var index = creditFilter_table_name[0].table_name;
|
// var index = creditFilter_table_name[0].table_name;
|
||||||
var tableName = arr[index]
|
// var tableName = arr[index]
|
||||||
await tableName.create( obj )
|
// await tableName.create( obj )
|
||||||
.then((successData)=>{logMsg.info(` ${tableName} insert success ,PdId= `+pd_id.pd_id);})
|
// .then((successData)=>{logMsg.info(` ${tableName} insert success ,PdId= `+pd_id.pd_id);})
|
||||||
.catch((err)=>{ logMsg.info(` ${tableName} insert failed ,PdId= `+pd_id.pd_id); });
|
// .catch((err)=>{ logMsg.info(` ${tableName} insert failed ,PdId= `+pd_id.pd_id); });
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
// insert nestedObject and object datas
|
// // insert nestedObject and object datas
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
Object.assign( obj,{ pd_id : pd_id.pd_id} );
|
// Object.assign( obj,{ pd_id : pd_id.pd_id} );
|
||||||
var index = creditFilter_table_name[0].table_name;
|
// var index = creditFilter_table_name[0].table_name;
|
||||||
var tableName = arr[index]
|
// var tableName = arr[index]
|
||||||
await tableName.create( obj )
|
// await tableName.create( obj )
|
||||||
.then((successData)=>{logMsg.info(` ${tableName} insert success ,PdId= `+pd_id.pd_id);})
|
// .then((successData)=>{logMsg.info(` ${tableName} insert success ,PdId= `+pd_id.pd_id);})
|
||||||
.catch((err)=>{ logMsg.info(` ${tableName} insert failed ,PdId= `+pd_id.pd_id); });
|
// .catch((err)=>{ logMsg.info(` ${tableName} insert failed ,PdId= `+pd_id.pd_id); });
|
||||||
}
|
// }
|
||||||
} // if end
|
// } // if end
|
||||||
} // end of outer forLoop
|
// } // end of outer forLoop
|
||||||
res.send({'status':200,'message':"success"});
|
// res.send({'status':200,'message':"success"});
|
||||||
} catch(err) {
|
// } catch(err) {
|
||||||
res.send({'status':404,message: err.message || "Some error occurred while retrieving data." ,'data': "No data" });
|
// res.send({'status':404,message: err.message || "Some error occurred while retrieving data." ,'data': "No data" });
|
||||||
} //end of try catch
|
// } //end of try catch
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,7 +327,7 @@ exports.GetCreditPdData = async (req, res) =>
|
|||||||
MainApplicantDetails = JSON.parse(applicantDetails);
|
MainApplicantDetails = JSON.parse(applicantDetails);
|
||||||
if(MainApplicantDetails.status == 200)
|
if(MainApplicantDetails.status == 200)
|
||||||
{
|
{
|
||||||
var resData = await CreditGeneralInformation.findAll({ where : { name : MainApplicantDetails.data.name,is_active : 1},
|
CreditGeneralInformation.findAll({ where : { name : MainApplicantDetails.data.name,is_active : 1},
|
||||||
include : [
|
include : [
|
||||||
{model: CreditAddressDetail }, {model: CreditFuturePlans },
|
{model: CreditAddressDetail }, {model: CreditFuturePlans },
|
||||||
{model : CreditBorrowerAndGuarantorDetails },
|
{model : CreditBorrowerAndGuarantorDetails },
|
||||||
@ -345,14 +335,28 @@ exports.GetCreditPdData = async (req, res) =>
|
|||||||
{model: CreditFinancialInformation }, {model: CreditKeyShareholder },
|
{model: CreditFinancialInformation }, {model: CreditKeyShareholder },
|
||||||
{model: CreditKeyProductBusinessContribution }, {model: EmployeeStrength },
|
{model: CreditKeyProductBusinessContribution }, {model: EmployeeStrength },
|
||||||
{model: ClientDetail }, {model: StockDetail },
|
{model: ClientDetail }, {model: StockDetail },
|
||||||
{model: CreditExistingLoanObligation }, {model: FamilyMemberInvolvedInBusiness },
|
{model: CreditExistingLoanObligation },
|
||||||
{model : CreditManager }, {model: Photograph },
|
{model: FamilyMemberInvolvedInBusiness },
|
||||||
|
{model : CreditManager },
|
||||||
|
{model: Photograph },
|
||||||
{model: CreditFinalRemarks }, {model: CreditLoanDetail },
|
{model: CreditFinalRemarks }, {model: CreditLoanDetail },
|
||||||
{model: CreditGeneralBusinessInformation }, {model: SupplierDetail }
|
{model: CreditGeneralBusinessInformation },
|
||||||
|
{model: SupplierDetail }
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
res.send({'status':200,'message':"success",'data':resData});
|
.then((data)=>{
|
||||||
}else
|
if (condition)
|
||||||
|
{
|
||||||
|
res.send({'status':200,'message':"success",'data':data});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
res.send({'status':404,'message':"failed",'data':"No data"});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
res.send({'status':404,'message':"failed",'data':"No data"});
|
res.send({'status':404,'message':"failed",'data':"No data"});
|
||||||
}
|
}
|
||||||
@ -375,33 +379,10 @@ exports.GetCreditPdData = async (req, res) =>
|
|||||||
|
|
||||||
// // test
|
// // test
|
||||||
|
|
||||||
// exports.testGetCreditPdData = async (req, res) =>
|
|
||||||
// {
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// var resData = await CreditGeneralInformation.findAll({ where : { pd_id : req.query.pdid ,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"
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
// };
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -6,8 +6,8 @@ const Sequelize = require('sequelize');
|
|||||||
const basename = path.basename(__filename);
|
const basename = path.basename(__filename);
|
||||||
const env = process.env.NODE_ENV || 'development';
|
const env = process.env.NODE_ENV || 'development';
|
||||||
const config = require(__dirname + '/../config/db.config.js')[env];
|
const config = require(__dirname + '/../config/db.config.js')[env];
|
||||||
//console.log(env);
|
// console.log(env);
|
||||||
//console.log(config);
|
// console.log(config);
|
||||||
const db = {};
|
const db = {};
|
||||||
|
|
||||||
let sequelize;
|
let sequelize;
|
||||||
@ -21,11 +21,11 @@ fs
|
|||||||
.readdirSync(__dirname)
|
.readdirSync(__dirname)
|
||||||
.filter(file => {
|
.filter(file => {
|
||||||
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
|
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
|
||||||
})
|
})
|
||||||
.forEach(file => {
|
.forEach(file => {
|
||||||
const model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes);
|
const model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes);
|
||||||
db[model.name] = model;
|
db[model.name] = model;
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.keys(db).forEach(modelName => {
|
Object.keys(db).forEach(modelName => {
|
||||||
if (db[modelName].associate) {
|
if (db[modelName].associate) {
|
||||||
@ -37,3 +37,4 @@ db.sequelize = sequelize;
|
|||||||
db.Sequelize = Sequelize;
|
db.Sequelize = Sequelize;
|
||||||
|
|
||||||
module.exports = db;
|
module.exports = db;
|
||||||
|
|
||||||
|
|||||||
@ -3,10 +3,30 @@ module.exports = app => {
|
|||||||
const cors=require('cors');
|
const cors=require('cors');
|
||||||
const Mycontroller = require("../controllers/test.controller.js");
|
const Mycontroller = require("../controllers/test.controller.js");
|
||||||
const CreditPdController = require("../controllers/creditpd.controller.js");
|
const CreditPdController = require("../controllers/creditpd.controller.js");
|
||||||
|
const CreditController = require("../controllers/credit.js");
|
||||||
const { logMsg } = require('../services/logger.js');
|
const { logMsg } = require('../services/logger.js');
|
||||||
var router = require("express").Router();
|
var router = require("express").Router();
|
||||||
|
|
||||||
|
router.get("/PullCredit", CreditController.PullCredit);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /api/getTable:
|
||||||
|
* get:
|
||||||
|
* summary: List
|
||||||
|
* description:
|
||||||
|
* parameters:
|
||||||
|
* - in: query
|
||||||
|
* name: pd_id
|
||||||
|
* schema:
|
||||||
|
* type: string
|
||||||
|
* required: true
|
||||||
|
* example: 123
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: success
|
||||||
|
*/
|
||||||
|
router.get('/getTable',CreditController.getTable);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -240,7 +260,6 @@ router.get("/DownloadPdReport", CreditPdController.DownloadPdReport);
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// routes started here
|
// routes started here
|
||||||
app.use('/api', router);
|
app.use('/api', router);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,13 +1,10 @@
|
|||||||
const { keys, values } = require('lodash');
|
const { keys, values } = require('lodash');
|
||||||
const { sequelize,Test,CreditGeneralInformation,SizeAndGeographicalResearch,CreditProfile,ProductAndProcess,PortFolioHealth,TotalOverallDebit,OverallPlanOfAction,ValidationPoint,
|
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')
|
||||||
CreditLoanDetail,CreditFinalRemarks,CreditGeneralBusinessInformation,CreditKeyProductBusinessContribution,EmployeeStrength,CreditBusinessAndPersonalBankingDetails,CreditFinancialInformation,
|
|
||||||
SupplierDetail ,ClientDetail,CreditFuturePlans,CreditExistingLoanObligation,FamilyMemberInvolvedInBusiness,CreditManager,CreditBorrowerAndGuarantorDetails,CreditFinancialAnalysis,CreditAddressDetail,
|
|
||||||
CreditKeyShareholder,Covid19Questions,StockDetail,BusinessAsset} = require('../models')
|
|
||||||
const { logMsg } = require('../services/logger.js');
|
const { logMsg } = require('../services/logger.js');
|
||||||
const request = require('request');
|
const request = require('request');
|
||||||
|
const moment = require('moment');
|
||||||
|
|
||||||
|
async function CreditPd(credit_key , credit_value ,credit_temp_array ,credit_obj) {
|
||||||
exports.CreditPd = async ( credit_key , credit_value ,credit_temp_array ,credit_obj) => {
|
|
||||||
for (let i = 0; i < credit_temp_array.length; i++) {
|
for (let i = 0; i < credit_temp_array.length; i++) {
|
||||||
if ( Object.keys(credit_value).includes(credit_temp_array[i]) ) {
|
if ( Object.keys(credit_value).includes(credit_temp_array[i]) ) {
|
||||||
await Object.assign( credit_obj, { [credit_key] : credit_value[credit_temp_array[i]] });
|
await Object.assign( credit_obj, { [credit_key] : credit_value[credit_temp_array[i]] });
|
||||||
@ -16,9 +13,7 @@ exports.CreditPd = async ( credit_key , credit_value ,credit_temp_array ,credit
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async function MainApplicantDetails(losid) {
|
||||||
exports.MainApplicantDetails = async(losid) => {
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const url = "https://demo.devopsmcfinance.com/cet_mainapp/api/MainApplicantDetailsList?losid="+losid;
|
const url = "https://demo.devopsmcfinance.com/cet_mainapp/api/MainApplicantDetailsList?losid="+losid;
|
||||||
|
|
||||||
@ -39,3 +34,87 @@ catch (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) =>
|
||||||
|
{
|
||||||
|
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"); // convert dd/mm/yyyy to yyyy/mm/dd
|
||||||
|
var my_date = moment(mydate).format("YYYY-MM-DD")
|
||||||
|
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 (typeof Value === "object" && ( Value !== null )) {
|
||||||
|
Obj = await OBJECT( element, Key , Value );
|
||||||
|
Object.assign(ArrayObj, Obj )
|
||||||
|
if (OverallKey == "Borrower & Guarantor Details" && Key == "borrower_name" && element.borrower_type == "Main Applicant") { Object.assign(GenInfoObj,{borrower_name : element.borrower_name}) }
|
||||||
|
} else {
|
||||||
|
Object.assign(ArrayObj,{ [Key] : Value })
|
||||||
|
if (OverallKey == "Borrower & Guarantor Details" && Key == "borrower_name" && element.borrower_type == "Main Applicant") { Object.assign(GenInfoObj,{borrower_name : element.borrower_name}) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user