This commit is contained in:
suseendhiran17 2022-05-04 12:09:22 +05:30
parent 74a23df6bb
commit 87b6fbf987
10 changed files with 271 additions and 93 deletions

View File

@ -0,0 +1,117 @@
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} = require('../models')
const { logMsg } = require('../services/logger.js');
const Credit_PdHelper = require('../services/CreditPdHelper.js');
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 ]
exports.Welcome = (req, res) =>
{
try
{
const Msg = "Welcome....!";
console.log(Msg);
logMsg.info("Api Call Success");
res.send({'status':200 , message:"Success." ,'data': Msg});
} catch(err) {
res.status(500).send({'status':404,
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
}); } //end of try catch
};
exports.CreditPd = async (req, res) =>
{
//
const tempData ={
// case 1
"Borrower & Guarantor Details":{
"borrower_details":[{"mobile_numbers":"","borrower_type":"Main Applicant","borrower_name":"J K COATING INDUSTRIES","entity_type":"Proprietorship Firm","designation":"Not Applicable","relationship_to":"NA","relationship":"NA","numbers_of_years_business_running":"3"},
{"borrower_type":"Co-Applicant","borrower_name":"SIMA","mobile_numbers":"","entity_type":"Individual","designation":"Proprietor","relationship_to":"JITENDRA","relationship":"Wife","numbers_of_years_business_running":"3","borrower_age":36,"borrower_met":"No"}
,{"borrower_type":"Co-Applicant","borrower_name":"JITENDRA","mobile_numbers":"","entity_type":"Individual","designation":"Not Applicable","relationship_to":"SIMA","relationship":"Husband","numbers_of_years_business_running":"4","borrower_age":40,"borrower_met":"Yes"}
,{"borrower_type":"Co-Applicant","borrower_name":"J.K SAND BLASTING AND POWDER COATING","mobile_numbers":"","entity_type":"Proprietorship Firm","designation":"Not Applicable","relationship_to":"NA","relationship":"NA","numbers_of_years_business_running":"4"}
,{"borrower_type":"Co-Applicant","borrower_name":"KAMLA","mobile_numbers":"","entity_type":"Individual","designation":"Not Applicable","relationship_to":"JITENDRA","relationship":"Mother","numbers_of_years_business_running":"0","borrower_age":57,"borrower_met":"No"}],
"common_remarks":"good","person_met":"JITENDRA##2## "},
// case 2
// "Address details":{"initiated_address":"Subhash Colony Plot No 21 A Bhagat K J Kothi Jodhpur, Jodhpur, Rajasthan - 342001","is_pd_done_on_initiated_address":"Yes","address_type":{"address_type_id":"2","address_type":"Clinic","isactive":"1","is_others":"0"},"pd_locality":{"locality_id":"5","locality_name":"Mix Use Area","isactive":"1","is_others":"1"},"pd_location":{"pd_location_approach_id":"2","description":"Easy to locate & Reach","createdon":"2018-10-17 10:15:43","fk_createdby":"1","updatedon":"2019-02-04 07:11:14","fk_updatedby":"1","isactive":"1","is_others":"0"},"comment_locality":{"comments_on_locality_id":"2","rating":"Good","createdon":"2018-10-17 10:35:29","fk_createdby":"1","updatedon":null,"fk_updatedby":null,"isactive":"1","is_others":"0"},"business_estimated_area":"108","uom":"Square Yards","uom_searchControl":null,"common_remarks":"nil","alternative_address":""},
// case 3
// "Future Plans & Business Environments":{"usp_of_business":"NA","future_business_expansion":"TO START BUSINESS IN OWN FACTORY","key_competitors":"NA","sucession_plan":"SON IS STUDYING","other_group_business_applicants":"NA","common_remarks":""},
}
var obj = { };
var arr_ObjKey = [ ]
var creditFilter_obj_key = [ ];
var creditFilter_table_name = [ ];
var name;
var pd_id = [ ];
for (const [key, value] of Object.entries(tempData)) {
creditFilter_obj_key = await CreditFilterTable.findAll({ raw: true , attributes: [ 'obj_key' ], where : { section : key , is_active : 1 }})
creditFilter_table_name = await CreditFilterTable.findAll({ raw: true, attributes: [ 'table_name' ,'section'], where : { section : key , is_active : 1 } , group: ['table_name' , 'section']})
for (let index = 0; index < creditFilter_obj_key.length; index++) {
arr_ObjKey.push(creditFilter_obj_key[index].obj_key)
}
if (key == creditFilter_table_name[0].section) {
for (var [keys, element] of Object.entries(value)) {
if ( Array.isArray(element) == true ) // array of object data
{
element.forEach(async(element , index) => {
// if ( keys == 'borrower_details' && index == 0 )
// {
// Object.keys(element).forEach(async ( datas ) => {
// if ( datas == 'borrower_name')
// {
// name = element[datas] ;
// }
// });
// pd_id = await CreditGeneralInformation.create({ name : name});
// }
obj = element;
delete value.obj
Object.assign( obj, value );
var index = creditFilter_table_name[0].table_name;
var tableName = arr[index]
await tableName.create( obj ).then((data)=>{}).catch((err)=>console.log(err))
// setTimeout(async() => {
// Object.assign( obj, { pd_id : pd_id.pd_id } );
// console.log(obj);
// await tableName.create( obj ).then((data)=>{}).catch((err)=>console.log(err))
// },1000)
});
}
else
{
Object.keys(value).forEach( async (key) => { // nested object data
const keys = Object.keys(value)
if( typeof value[key] === "object" && ( value[key] !== null ) )
{
Credit_PdHelper.CreditPd( key , value[key] , arr_ObjKey , obj )
}
else if( value[key] !== null ) // object data
{
Object.assign( obj, { [key] : value[key] });
}
});
}
}
} //end
// data insert into DB
// var index = creditFilter_table_name[0].table_name;
// var tableName = arr[index]
// setTimeout(async() => {
// // Object.assign( obj, { pd_id : pd_id.pd_id } );
// console.log(obj);
// await tableName.create( obj ).then((data)=>{}).catch((err)=>console.log(err))
// },1000)
}
}

View File

@ -1,14 +1,10 @@
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} = require('../models')
const { logMsg } = require('../services/logger.js');
exports.Welcome = (req, res) =>
{
try
{
{
const Msg = "Welcome....!";
console.log(Msg);
logMsg.info("Api Call Success");
@ -21,88 +17,15 @@ exports.Welcome = (req, res) =>
};
exports.CreditPd = async (req, res) =>
exports.PullCreditPdData = async (req, res) =>
{
// try
// {
const tempData = {"Address details":{"initiated_address":"Subhash Colony Plot No 21 A Bhagat K J Kothi Jodhpur, Jodhpur, Rajasthan - 342001","is_pd_done_on_initiated_address":"Yes","address_type":{"address_type_id":"2","address_type":"Clinic","isactive":"1","is_others":"0"},"pd_locality":{"locality_id":"5","locality_name":"Mix Use Area","isactive":"1","is_others":"1"},"pd_location":{"pd_location_approach_id":"2","description":"Easy to locate & Reach",
"createdon":"2018-10-17 10:15:43","fk_createdby":"1","updatedon":"2019-02-04 07:11:14","fk_updatedby":"1",
"isactive":"1","is_others":"0"},"comment_locality":{"comments_on_locality_id":"2","rating":"Good",
"createdon":"2018-10-17 10:35:29","fk_createdby":"1","updatedon":null,"fk_updatedby":null,
"isactive":"1","is_others":"0"},"business_estimated_area":"108","uom":"Square Yards",
"uom_searchControl":null,"common_remarks":"nil","alternative_address":""} }
// var count = 0;
// var generalInformation = [ ];
// var storeData = [ ];
// const len = Object.keys(tempData).length - 1;
for (const [keys, values] of Object.entries(tempData)) {
Object.values(values).forEach( async (element) => {
// Object.keys(element).forEach( async (elementKey) => {
// if (typeof values.elementKey === "object" && values.elementKey !== null ) {
// console.log("object" , element.elementKey);
// }
// else
// {
// console.log("not a object" , element.elementKey);
// }
// });
if (typeof element === "object" && element !== null ) {
console.log("object" , element);
}
else
{
console.log("not a object" , element);
}
});
// if (keys == 'General Information') { generalInformation = await CreditGeneralInformation.create( values ); storeId = await CreditGeneralInformation.findOne({ where : { pd_id : generalInformation.pd_id , is_active : 1 }}); };
// if (keys == 'Profile') { Object.assign(values, { pd_id: storeId.pd_id }); await CreditProfile.create( values ) };
// if (keys == 'Size and Geographical Reach') { Object.assign(values, { pd_id: storeId.pd_id }); await SizeAndGeographicalResearch.create( values) };
// if (keys == 'Product and Process') { Object.assign(values, { pd_id: storeId.pd_id }); await ProductAndProcess.create( values) };
// if (keys == 'Portfolio Health') { Object.assign(values, { pd_id: storeId.pd_id }); await PortFolioHealth.create( values) };
// if (keys == 'Total Overall Debt/Equity Profile') { Object.assign(values, { pd_id: storeId.pd_id }); await TotalOverallDebit.create( values) };
// if (keys == 'Financial analysis') { Object.assign(values, { pd_id: storeId.pd_id }); await CreditFinancialAnalysis.create( values) };
// if (keys == 'Overall Plan of Action') { Object.assign(values, { pd_id: storeId.pd_id }); await OverallPlanOfAction.create( values) };
// if (keys == 'Validation Points vide Systems and Books at HQ and Branches') { Object.assign(values, { pd_id: storeId.pd_id }); await ValidationPoint.create( values) };
// if (keys == 'Final remarks') { Object.assign(values, { pd_id: storeId.pd_id }); await CreditFinalRemarks.create( values) };
// if (keys == 'Address details') { Object.assign(values, { pd_id: storeId.pd_id }); await CreditAddressDetail.create( values) };
// if (keys == 'Loan details') { Object.assign(values, { pd_id: storeId.pd_id }); await CreditLoanDetail.create( values ) };
// if (keys == 'General Business Information') { Object.assign(values, { pd_id: storeId.pd_id }); await CreditGeneralBusinessInformation.create( values) };
// if (keys == 'Key Products and Business Contribution') { Object.assign(values, { pd_id: storeId.pd_id }); await CreditKeyProductBusinessContribution.create( values) };
// if (keys == 'Employee Strength') { Object.assign(values, { pd_id: storeId.pd_id }); await EmployeeStrength.create( values) };
// if (keys == 'Business and Personal Banking') { Object.assign(values, { pd_id: storeId.pd_id }); await CreditBusinessAndPersonalBankingDetails.create( values) };
// if (keys == 'Financial Information') { Object.assign(values, { pd_id: storeId.pd_id }); await CreditFinancialInformation.create( values) };
// if (keys == 'Supplier details') { Object.assign(values, { pd_id: storeId.pd_id }); await SupplierDetail.create( values) };
// if (keys == 'Clients details') { Object.assign(values, { pd_id: storeId.pd_id }); await ClientDetail.create( values) };
// if (keys == 'Future Plans & Business Environments') { Object.assign(values, { pd_id: storeId.pd_id }); await CreditFuturePlans.create( values) };
// if (keys == 'Existing Loan Obligations') { Object.assign(values, { pd_id: storeId.pd_id }); await CreditExistingLoanObligation.create( values) };
// if (keys == 'Family Members Involved in Business') { Object.assign(values, { pd_id: storeId.pd_id }); await FamilyMemberInvolvedInBusiness.create( values ) };
// if (keys == 'Credit manager specific queries') { Object.assign(values, { pd_id: storeId.pd_id }); await CreditManager.create( values) };
// if (keys == 'Borrower & Guarantor Details') { Object.assign(values, { pd_id: storeId.pd_id }); await CreditBorrowerAndGuarantorDetails.create( values) };
// if (keys == 'Key Stakeholders in Business') { Object.assign(values, { pd_id: storeId.pd_id }); await CreditKeyShareholder.create( values) };
// if (keys == 'Covid 19 Questions') { Object.assign(values, { pd_id: storeId.pd_id }); await Covid19Questions.create( values) };
// if (keys == 'Stock details') { Object.assign(values, { pd_id: storeId.pd_id }); await StockDetail.create( values) };
// if (keys == 'Business Assets') { Object.assign(values, { pd_id: storeId.pd_id }); await BusinessAsset.create( values) };
// });
// }
try
{
res.send({'status':200,'message':"success",'data':req.body});
} catch(err) {
res.send({'status':404,message: err.message || "Some error occurred while retrieving data." ,'data': "No data" });
} //end of try catch
}
}
};

View File

@ -6,7 +6,7 @@ module.exports = (sequelize, DataTypes) => {
}
CreditBorrowerAndGuarantorDetails.init(
{
pd_id: { type: DataTypes.INTEGER },
pd_id: { type: DataTypes.INTEGER },
borrower_type: { type: DataTypes.STRING },
numbers_of_years_business_running: { type: DataTypes.INTEGER },
borrower_name: { type: DataTypes.STRING },

View File

@ -0,0 +1,31 @@
'use strict'
const { Model } = require('sequelize')
module.exports = (sequelize, DataTypes) => {
class CreditFilterTable extends Model {
}
CreditFilterTable.init(
{
pd_id: { type: DataTypes.INTEGER },
section: { type: DataTypes.STRING },
ques_key: { type: DataTypes.STRING },
is_obj: { type: DataTypes.INTEGER },
obj_key: { type: DataTypes.STRING },
is_mul: { type: DataTypes.INTEGER },
mul_key: { type: DataTypes.STRING },
temp_key: { type: DataTypes.STRING },
table_name: { type: DataTypes.STRING },
createdby: { type: DataTypes.INTEGER },
updatedby: { type: DataTypes.INTEGER }
},
{
sequelize,
tableName: 'credit_filter_table',
modelName: 'CreditFilterTable',
}
)
return CreditFilterTable
}

View File

@ -6,7 +6,11 @@ module.exports = (sequelize, DataTypes) => {
}
CreditGeneralInformation.init(
{
pd_id: { type: DataTypes.INTEGER },
pd_id: {
type: DataTypes.INTEGER,
autoIncrement : true,
primaryKey: true
},
name: { type: DataTypes.STRING },
loan_amount: { type: DataTypes.INTEGER },
product: { type: DataTypes.STRING },

View File

@ -22,7 +22,46 @@ module.exports = app => {
router.get("/demo", Mycontroller.Welcome);
router.get('/creditPd',Mycontroller.CreditPd)
/**
* @swagger
* definitions:
* PullCreditPdData:
* type: object
* properties:
* pdid:
* type: integer
* description: pdid
* example: 6646
* product:
* type: string
* description: product
* example: LFMP
* data:
* type: string
* description: json string
* example:
*/
/**
* @swagger
* /api/PullCreditPdData:
* post:
* summary: Pull SalesPd Data
* description: Pull SalesPd Data
* requestBody:
* content:
* application/json:
* schema:
* $ref: '#/definitions/PullCreditPdData'
* responses:
* 200:
* description: success
* 500:
* description: failed
*/
router.post("/PullCreditPdData", Mycontroller.PullCreditPdData);
// router.get('/creditPd',Mycontroller.CreditPd)
// routes started here

View File

@ -0,0 +1,18 @@
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 { logMsg } = require('../services/logger.js');
exports.CreditPd = async ( 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]] });
}
}
}

45
package-lock.json generated
View File

@ -13,6 +13,7 @@
"cors": "^2.8.5",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"global": "^4.4.0",
"lodash": "^4.17.21",
"log4js": "^6.3.0",
"mssql": "^7.2.0",
@ -1625,6 +1626,11 @@
"node": ">=6.0.0"
}
},
"node_modules/dom-walk": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/dom-walk/-/dom-walk-0.1.2.tgz",
"integrity": "sha512-6QvTW9mrGeIegrFXdtQi9pk7O/nSK6lSdXW2eqUspN5LWD7UTji2Fqw5V2YLjBpHEoU9Xl/eUWNpDeZvoyOv2w=="
},
"node_modules/dot-prop": {
"version": "5.3.0",
"resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-5.3.0.tgz",
@ -2151,6 +2157,15 @@
"node": ">= 6"
}
},
"node_modules/global": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/global/-/global-4.4.0.tgz",
"integrity": "sha512-wv/LAoHdRE3BeTGz53FAamhGlPLhlssK45usmGFThIi4XqnBmjKQ16u+RNbP7WvigRZDxUsM0J3gcQ5yicaL0w==",
"dependencies": {
"min-document": "^2.19.0",
"process": "^0.11.10"
}
},
"node_modules/global-dirs": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/global-dirs/-/global-dirs-3.0.0.tgz",
@ -3056,6 +3071,14 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/min-document": {
"version": "2.19.0",
"resolved": "https://registry.npmjs.org/min-document/-/min-document-2.19.0.tgz",
"integrity": "sha1-e9KC4/WELtKVu3SM3Z8f+iyCRoU=",
"dependencies": {
"dom-walk": "^0.1.0"
}
},
"node_modules/minimatch": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
@ -6252,6 +6275,11 @@
"esutils": "^2.0.2"
}
},
"dom-walk": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/dom-walk/-/dom-walk-0.1.2.tgz",
"integrity": "sha512-6QvTW9mrGeIegrFXdtQi9pk7O/nSK6lSdXW2eqUspN5LWD7UTji2Fqw5V2YLjBpHEoU9Xl/eUWNpDeZvoyOv2w=="
},
"dot-prop": {
"version": "5.3.0",
"resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-5.3.0.tgz",
@ -6668,6 +6696,15 @@
"is-glob": "^4.0.1"
}
},
"global": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/global/-/global-4.4.0.tgz",
"integrity": "sha512-wv/LAoHdRE3BeTGz53FAamhGlPLhlssK45usmGFThIi4XqnBmjKQ16u+RNbP7WvigRZDxUsM0J3gcQ5yicaL0w==",
"requires": {
"min-document": "^2.19.0",
"process": "^0.11.10"
}
},
"global-dirs": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/global-dirs/-/global-dirs-3.0.0.tgz",
@ -7367,6 +7404,14 @@
"integrity": "sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==",
"optional": true
},
"min-document": {
"version": "2.19.0",
"resolved": "https://registry.npmjs.org/min-document/-/min-document-2.19.0.tgz",
"integrity": "sha1-e9KC4/WELtKVu3SM3Z8f+iyCRoU=",
"requires": {
"dom-walk": "^0.1.0"
}
},
"minimatch": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",

View File

@ -13,6 +13,7 @@
"cors": "^2.8.5",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"global": "^4.4.0",
"lodash": "^4.17.21",
"log4js": "^6.3.0",
"mssql": "^7.2.0",

View File

@ -19,7 +19,7 @@ const options = {
definition: {
openapi: '3.0.0',
info: {
title: 'Smc_cet_financials',
title: 'Smc_cet_creditPd',
version: '1.0.0',
},
},