susee
This commit is contained in:
parent
dcd4ba5c71
commit
1d984b83cc
112
app/controllers/abc.js
Normal file
112
app/controllers/abc.js
Normal file
@ -0,0 +1,112 @@
|
||||
// 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) {
|
||||
// arrkeys = key;
|
||||
// for (var [keys, elements] of Object.entries(value)) {
|
||||
// // arrkeys_1 = Object.keys(value);
|
||||
// console.log(keys , elements);
|
||||
// // if ( Array.isArray(elements) == true ) // array of object data
|
||||
// // {
|
||||
elements.forEach(async(element , index) => {
|
||||
Object.assign(obj,element);
|
||||
for (let i = 1; i < arrkeys_1.length; i++) {
|
||||
Object.assign(obj , {[arrkeys_1[i]] : value[arrkeys_1[i]] } );
|
||||
}
|
||||
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((data)=>{}).catch((err)=>console.log(err));
|
||||
});
|
||||
// // }
|
||||
// // else
|
||||
// // {
|
||||
// // Object.keys(value).forEach( async (key) => { // nested object data
|
||||
// // Object.assign( obj, { pd_id : pd_id.pd_id } );
|
||||
// // if( typeof value[key] === "object" && ( value[key] !== null ) && Array.isArray(value[key]) == false )
|
||||
// // {
|
||||
// // Credit_PdHelper.CreditPd( key , value[key] , arr_ObjKey , obj )
|
||||
// // }
|
||||
// // else if( value[key] !== null && Array.isArray(value[key]) == false ) // object data
|
||||
// // {
|
||||
// // Object.assign( obj, { [key] : value[key] });
|
||||
// // }
|
||||
// // else if (Array.isArray(value[key]) == true )
|
||||
// // {
|
||||
// // value[key].forEach( async (element) => {
|
||||
// // Object.assign( obj, { [key] : element });
|
||||
// // });
|
||||
// // }
|
||||
// // });
|
||||
// // }
|
||||
// }
|
||||
// } //end
|
||||
// // data insert into DB
|
||||
// if (arrkeys.includes(creditFilter_table_name[0].table_name) == false) {
|
||||
// // var index = creditFilter_table_name[0].table_name;
|
||||
// // var tableName = arr[index]
|
||||
// // await tableName.create( obj ).then((data)=>{}).catch((err)=>console.log(err));
|
||||
// // console.log(obj);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// case 2
|
||||
|
||||
|
||||
for (const [key, value] of Object.entries(tempData)) {
|
||||
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)
|
||||
}
|
||||
if (key == creditFilter_table_name[0].section) {
|
||||
arrkeys = key;
|
||||
storeKeys = Object.keys(value);
|
||||
for (var [arr_keys, arr_of_element] of Object.entries(value)) {
|
||||
if ( Array.isArray(arr_of_element) == true )
|
||||
{
|
||||
// for (let i = 0 ; i < storeKeys.length ; i++)
|
||||
// {
|
||||
// if ( storeKeys[i] != arr_keys )
|
||||
// {
|
||||
// Object.assign(temp_obj , { [storeKeys[i]] : value[storeKeys[i]] } );
|
||||
// }
|
||||
// }
|
||||
arr_of_element.forEach(async(iter_element , index) => {
|
||||
if (Object.keys(iter_element)[0] == '0') {
|
||||
temp_obj.push({ [arr_keys] : iter_element })
|
||||
} else {
|
||||
temp_obj.push(iter_element) ;
|
||||
}
|
||||
// Object.assign(obj,iter_element ,temp_obj, { pd_id : 1 }); // pd_id.pd_id
|
||||
// var index = creditFilter_table_name[0].table_name;
|
||||
// var tableName = arr[index]
|
||||
// await tableName.create( obj ).then((data)=>{}).catch((err)=>console.log(err));
|
||||
// console.log(obj);
|
||||
});
|
||||
}
|
||||
else if( typeof arr_of_element === "object" && ( arr_of_element !== null ) )
|
||||
{
|
||||
await Object.assign( obj, { pd_id : pd_id.pd_id } );
|
||||
await Credit_PdHelper.CreditPd( arr_keys , arr_of_element , arr_ObjKey , obj )
|
||||
}
|
||||
else if( storeKeys.includes(creditFilter_table_name[0].ques_key) == false )
|
||||
{
|
||||
Object.assign( obj, { pd_id : pd_id.pd_id } );
|
||||
Object.assign( obj, { [arr_keys] : arr_of_element });
|
||||
}
|
||||
}// inner forLoop
|
||||
// DB insert
|
||||
// var index = creditFilter_table_name[0].table_name;
|
||||
// var tableName = arr[index]
|
||||
// await tableName.create( obj ).then((data)=>{}).catch((err)=>console.log(err));
|
||||
// console.log(obj);
|
||||
console.log(temp_obj);
|
||||
}
|
||||
} // 1st forLoop
|
||||
}
|
||||
|
||||
@ -28,90 +28,95 @@ exports.Welcome = (req, res) =>
|
||||
|
||||
exports.CreditPd = async (req, res) =>
|
||||
{
|
||||
//
|
||||
const tempData ={
|
||||
|
||||
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 obj = { }; // store obj
|
||||
let temp_obj = [ ]; // store array of 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)
|
||||
}
|
||||
}
|
||||
// var arrkeys = [ ];
|
||||
// var storeKeys;
|
||||
|
||||
for (const [key, value] of Object.entries(tempData)) {
|
||||
if (key == "Borrower & Guarantor Details") {
|
||||
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 )
|
||||
{
|
||||
name = element['borrower_name'];
|
||||
// pd_id = await CreditGeneralInformation.create({ name : name }); // get main applicant name
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (const [key, value] of Object.entries(tempData)) {
|
||||
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
|
||||
obj = { }; // clear obj
|
||||
// arrkeys = key;
|
||||
// storeKeys = Object.keys(value);
|
||||
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') {
|
||||
temp_obj.push({ [arr_keys] : iter_element })
|
||||
} else {
|
||||
temp_obj.push(iter_element) ;
|
||||
}
|
||||
});
|
||||
}
|
||||
else if( typeof arr_of_element === "object" && ( arr_of_element !== null ) )
|
||||
{
|
||||
await Credit_PdHelper.CreditPd( arr_keys , arr_of_element , arr_ObjKey , obj )
|
||||
}
|
||||
else
|
||||
{
|
||||
Object.assign( obj, { [arr_keys] : arr_of_element });
|
||||
}
|
||||
}// inner forLoop
|
||||
// DB insertion
|
||||
if (temp_obj.length != 0 )
|
||||
{
|
||||
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((data)=>{}).catch((err)=>console.log(err));
|
||||
// console.log(obj);
|
||||
});
|
||||
}
|
||||
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((data)=>{}).catch((err)=>console.log(err));
|
||||
// console.log(obj);
|
||||
}
|
||||
} // if end
|
||||
} // outer forLoop
|
||||
}
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ module.exports = (sequelize, DataTypes) => {
|
||||
business_pd_visited_remark: { type: DataTypes.STRING },
|
||||
business_ownership_type: { type: DataTypes.STRING },
|
||||
business_approximate_market_value: { type: DataTypes.INTEGER },
|
||||
business_name_of_the_owner: { type: DataTypes.STRING },
|
||||
business_name_of_the_owner: { type: DataTypes.STRING }, // DataTypes.ARRAY(DataTypes.STRING),
|
||||
business_vintage: { type: DataTypes.INTEGER },
|
||||
business_purchase_year: { type: DataTypes.INTEGER },
|
||||
business_emi: { type: DataTypes.INTEGER },
|
||||
|
||||
@ -16,7 +16,7 @@ module.exports = (sequelize, DataTypes) => {
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
tableName: 'crredit_credit_manager_specific_queries',
|
||||
tableName: 'credit_credit_manager_specific_queries',
|
||||
modelName: 'CreditManager',
|
||||
}
|
||||
)
|
||||
|
||||
@ -2,6 +2,7 @@ module.exports = app => {
|
||||
const request = require("request");
|
||||
const cors=require('cors');
|
||||
const Mycontroller = require("../controllers/test.controller.js");
|
||||
const CreditPdController = require("../controllers/creditpd.controller.js");
|
||||
const { logMsg } = require('../services/logger.js');
|
||||
var router = require("express").Router();
|
||||
|
||||
@ -61,7 +62,7 @@ module.exports = app => {
|
||||
router.post("/PullCreditPdData", Mycontroller.PullCreditPdData);
|
||||
|
||||
|
||||
// router.get('/creditPd',Mycontroller.CreditPd)
|
||||
router.get('/creditPd',CreditPdController.CreditPd)
|
||||
|
||||
|
||||
// routes started here
|
||||
|
||||
Loading…
Reference in New Issue
Block a user