diff --git a/app/controllers/credit.js b/app/controllers/credit.js deleted file mode 100644 index 03f1f0f..0000000 --- a/app/controllers/credit.js +++ /dev/null @@ -1,110 +0,0 @@ -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" - }); - } - -}; - - - - - - - - - diff --git a/app/controllers/creditpd.controller.js b/app/controllers/creditpd.controller.js index bf72eb8..3912460 100644 --- a/app/controllers/creditpd.controller.js +++ b/app/controllers/creditpd.controller.js @@ -3,8 +3,10 @@ const { logMsg } = require('../services/logger.js'); const Credit_PdHelper = require('../services/CreditPdHelper.js'); const request = require('request'); const moment = require('moment'); -var global = require('global'); -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 ] +// var global = require('global'); +// 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 ] + + exports.Welcome = (req, res) => { @@ -23,198 +25,74 @@ exports.Welcome = (req, res) => +// PullCreditPdData +exports.PullCreditPdData = async (req, res) => { - - - - - - - -exports.PullCreditPdData = async (req, res) => -{ - - // try - // { - console.log(req.body); - const tempData = JSON.parse(JSON.stringify(req.body.data)); - // var obj = { }; - // var temp_obj = [ ]; - // var arr_ObjKey = [ ] - // var creditFilter_obj_key = [ ]; - // var creditFilter_table_name = [ ]; - // var key_for_arrays = [ ]; - // var name; - // var loan_amount; - // var pd_id = [ ]; - // var resPonse = [ ]; - - - // // create creditGeneralInormationData - // resPonse.length = 0 ; // clear array datas - // for (const [key, value] of Object.entries(tempData)) - // { - // if (key == "Loan details" || key =="Borrower & Guarantor Details" || key == "Officer Details") - // { - // for (var [keys, element] of Object.entries(value)) - // { - // if ( Array.isArray(element) == true ) - // { - // element.forEach(async(element , index) => { - // if ( keys == 'borrower_details' && index == 0 ) - // { - // Object.assign( obj , {name : element['borrower_name']}) - // Object.assign(obj, { ref_no: req.body.pdid , product :req.body.product , case_no :req.body.caseno}); - // } - // }); - // } - // else - // { - // if ( key == "Borrower & Guarantor Details" && keys == 'common_remarks') { Object.assign( obj , {remarks : element}) } - // if ( keys == 'loan_amount') { { Object.assign( obj , { loan_amount : element })} }; - // if ( key == "Officer Details") - // { - // 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 my_date = moment(mydate).format("YYYY-MM-DD HH:mm:ss A") - // Object.assign( obj, { [keys] : my_date }); - // } - // else{ - // Object.assign(obj, { [ keys ] : element }); - // } - // } - // } - // } - // } - // } - // // Object.assign( obj , { ref_no : req.body.pdid }); - // console.log(obj); - // pd_id = 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); }); - // // 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 - // for (const [key, value] of Object.entries(tempData)) { - // console.log(key); - // 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']}) - - // for (let index = 0; index < creditFilter_obj_key.length; index++) - // { - // arr_ObjKey.push(creditFilter_obj_key[index].mul_key) // store nested obj keys - // } - - - // if (key == creditFilter_table_name[0].section) { - // temp_obj.length = 0 ; // clear array datas - // obj = { }; // clear obj datas - - // // Check if the data is array or not - // for (var [arr_keys, arr_of_element] of Object.entries(value)) { - // if ( Array.isArray(arr_of_element) == true ) - // { - // arr_of_element.forEach(async(iter_element , index) => - // { - // if (Object.keys(iter_element)[0] == '0') - // { - // Object.assign( obj, { [arr_keys] : iter_element }); - // } - // // assign array of objects - // else - // { - // key_for_arrays = Object.keys(iter_element); - // Object.values(iter_element).forEach( async (element_ele , index ) => { - // if ( typeof element_ele === "object" && ( element_ele !== null )) - // { - // delete element_ele.display_data; - // delete value.display_data; - // await Credit_PdHelper.CreditPd( key_for_arrays[index] , element_ele , arr_ObjKey , obj ) - // } - // else - // { - // // temp_obj.push(iter_element) ; - // Object.assign( obj, { [key_for_arrays[index]] : element_ele }); - // } - // }); - // } - // temp_obj.push(obj) - // obj = { }; // clear obj datas - // }); - // } - // // end of array - // // assign nestedObject datas - // else if( typeof arr_of_element === "object" && ( arr_of_element !== null ) ) - // { - // delete arr_of_element.display_data; - // delete value.display_data; - // await Credit_PdHelper.CreditPd( arr_keys , arr_of_element , arr_ObjKey , obj ) - // } - // // assign object data - // else - // { - // 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 my_date = moment(mydate).format("YYYY-MM-DD") - // Object.assign( obj, { [arr_keys] : my_date }); - // } - // else - // { - // Object.assign( obj, { [arr_keys] : arr_of_element }); - // } - // } - // }// end of inner forLoop - - - // // DB insertion - - - // if (temp_obj.length != 0 ) // insert array of object datas - // { - // temp_obj.forEach( async (temp_obj_element) => - // { - // Object.assign( obj,{ pd_id : pd_id.pd_id} ); - // Object.assign( obj,temp_obj_element ); - // var index = creditFilter_table_name[0].table_name; - // var tableName = arr[index] - // await tableName.create( obj ) - // .then((successData)=>{logMsg.info(` ${tableName} insert success ,PdId= `+pd_id.pd_id);}) - // .catch((err)=>{ logMsg.info(` ${tableName} insert failed ,PdId= `+pd_id.pd_id); }); - // }); - // } - // // insert nestedObject and object datas - // else - // { - // Object.assign( obj,{ pd_id : pd_id.pd_id} ); - // var index = creditFilter_table_name[0].table_name; - // var tableName = arr[index] - // await tableName.create( obj ) - // .then((successData)=>{logMsg.info(` ${tableName} insert success ,PdId= `+pd_id.pd_id);}) - // .catch((err)=>{ logMsg.info(` ${tableName} insert failed ,PdId= `+pd_id.pd_id); }); - // } - // } // if end - // } // end of outer forLoop - // 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 - + 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.PullCreditPdPhotographsData = async (req, res) => { try