From 01fae2f4605817b2fb46861a7f1af90d1bc0100c Mon Sep 17 00:00:00 2001 From: suseendhiran17 <58357088+suseendhiran17@users.noreply.github.com> Date: Fri, 30 Sep 2022 10:08:21 +0530 Subject: [PATCH] changes in select api : suseendhiran --- app/config/db.config.js | 6 +- app/controllers/credit.js | 110 ++++++++ app/controllers/creditpd.controller.js | 377 ++++++++++++------------- app/models/index.js | 9 +- app/routes/routes.js | 21 +- app/services/CreditPdHelper.js | 97 ++++++- server.js | 1 - 7 files changed, 405 insertions(+), 216 deletions(-) create mode 100644 app/controllers/credit.js diff --git a/app/config/db.config.js b/app/config/db.config.js index ceea409..af25892 100644 --- a/app/config/db.config.js +++ b/app/config/db.config.js @@ -1,5 +1,4 @@ require('dotenv').config(); - const { logMsg } = require('../services/logger'); module.exports = { @@ -12,5 +11,6 @@ module.exports = { "dialect": "mssql", "logging": (message) =>(logMsg.info(message)) - } - }; \ No newline at end of file + }, + +}; \ No newline at end of file diff --git a/app/controllers/credit.js b/app/controllers/credit.js new file mode 100644 index 0000000..03f1f0f --- /dev/null +++ b/app/controllers/credit.js @@ -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" + }); + } + +}; + + + + + + + + + diff --git a/app/controllers/creditpd.controller.js b/app/controllers/creditpd.controller.js index 96eb33d..bf43b5f 100644 --- a/app/controllers/creditpd.controller.js +++ b/app/controllers/creditpd.controller.js @@ -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 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 ] +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) => { @@ -45,171 +34,172 @@ exports.Welcome = (req, res) => exports.PullCreditPdData = async (req, res) => { - try - { + // 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 = [ ]; + // 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 }}); + // // 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']}) + // // 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 - } + // 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 + // 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 + // // 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 + // // 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 + // 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 } @@ -337,7 +327,7 @@ exports.GetCreditPdData = async (req, res) => MainApplicantDetails = JSON.parse(applicantDetails); 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 : [ {model: CreditAddressDetail }, {model: CreditFuturePlans }, {model : CreditBorrowerAndGuarantorDetails }, @@ -345,14 +335,28 @@ exports.GetCreditPdData = async (req, res) => {model: CreditFinancialInformation }, {model: CreditKeyShareholder }, {model: CreditKeyProductBusinessContribution }, {model: EmployeeStrength }, {model: ClientDetail }, {model: StockDetail }, - {model: CreditExistingLoanObligation }, {model: FamilyMemberInvolvedInBusiness }, - {model : CreditManager }, {model: Photograph }, + {model: CreditExistingLoanObligation }, + {model: FamilyMemberInvolvedInBusiness }, + {model : CreditManager }, + {model: Photograph }, {model: CreditFinalRemarks }, {model: CreditLoanDetail }, - {model: CreditGeneralBusinessInformation }, {model: SupplierDetail } + {model: CreditGeneralBusinessInformation }, + {model: SupplierDetail } ] }) - res.send({'status':200,'message':"success",'data':resData}); - }else + .then((data)=>{ + 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"}); } @@ -375,33 +379,10 @@ exports.GetCreditPdData = async (req, res) => // // 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" -// }); -// } - -// }; + + + + diff --git a/app/models/index.js b/app/models/index.js index abe34a1..fd6a336 100644 --- a/app/models/index.js +++ b/app/models/index.js @@ -6,8 +6,8 @@ const Sequelize = require('sequelize'); const basename = path.basename(__filename); const env = process.env.NODE_ENV || 'development'; const config = require(__dirname + '/../config/db.config.js')[env]; -//console.log(env); -//console.log(config); +// console.log(env); +// console.log(config); const db = {}; let sequelize; @@ -21,11 +21,11 @@ fs .readdirSync(__dirname) .filter(file => { return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js'); - }) + }) .forEach(file => { const model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes); db[model.name] = model; - }); + }); Object.keys(db).forEach(modelName => { if (db[modelName].associate) { @@ -37,3 +37,4 @@ db.sequelize = sequelize; db.Sequelize = Sequelize; module.exports = db; + diff --git a/app/routes/routes.js b/app/routes/routes.js index c664cdb..f4a58b5 100644 --- a/app/routes/routes.js +++ b/app/routes/routes.js @@ -3,10 +3,30 @@ module.exports = app => { const cors=require('cors'); const Mycontroller = require("../controllers/test.controller.js"); const CreditPdController = require("../controllers/creditpd.controller.js"); + const CreditController = require("../controllers/credit.js"); const { logMsg } = require('../services/logger.js'); 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 app.use('/api', router); }; diff --git a/app/services/CreditPdHelper.js b/app/services/CreditPdHelper.js index 26e5ce7..392eea0 100644 --- a/app/services/CreditPdHelper.js +++ b/app/services/CreditPdHelper.js @@ -1,13 +1,10 @@ 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} = 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 request = require('request'); +const moment = require('moment'); - -exports.CreditPd = async ( credit_key , credit_value ,credit_temp_array ,credit_obj) => { +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]] }); @@ -16,9 +13,7 @@ exports.CreditPd = async ( credit_key , credit_value ,credit_temp_array ,credit } - -exports.MainApplicantDetails = async(losid) => { - +async function MainApplicantDetails(losid) { try { 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 + } \ No newline at end of file diff --git a/server.js b/server.js index e4500ec..604cef3 100644 --- a/server.js +++ b/server.js @@ -60,4 +60,3 @@ app.listen({ port: PORT_NUMBER }, async () => { //await sequelize.authenticate() }) -