Surya: test
This commit is contained in:
parent
17a2157483
commit
8381e7830e
@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
const { response } = require('express');
|
||||||
const { sequelize, Entities , Financials , Statementsmaster , Sectionsmaster , Subsectionsmaster , Brokenperiods , Entityfinyears } = require('../models')
|
const { sequelize, Entities , Financials , Statementsmaster , Sectionsmaster , Subsectionsmaster , Brokenperiods , Entityfinyears } = require('../models')
|
||||||
const { logMsg } = require('../services/logger.js');
|
const { logMsg } = require('../services/logger.js');
|
||||||
|
|
||||||
@ -250,89 +251,100 @@ exports.test = (req, res) => {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
exports.test2 = (req, res) => {
|
exports.test2 = async (req, res) => {
|
||||||
const losid = req.query.losid
|
const losid = req.query.losid
|
||||||
const promise = Promise.resolve(res.send({'losid':losid,'status':200,'message':"success"}));
|
|
||||||
const p1 = losid => new Promise((resolve,reject) =>{
|
// const promise = Promise.resolve(res.send({'losid':losid,'status':200,'message':"success"}));
|
||||||
//console.log(losid)
|
var promise = (losid) => new Promise((resolve,reject) =>{
|
||||||
resolve(losid)
|
resolve(losid)
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
p1(1).then((losid) => {
|
// p1(losid).then((losid) => {
|
||||||
|
|
||||||
//pro 42 api call using losid
|
promise(losid).then((losid) => {
|
||||||
const Pro42Data = [
|
console.log(losid)
|
||||||
{"losid":losid,"pan":"AA1234AAAA","cin":"test1_cin","bizname":"test1_bizname","entity_type":"type","activity_group":"grp","biz_act_desc":"des","createdby":4},
|
//pro 42 api call using losid
|
||||||
{"losid":losid,"pan":"BB1234BBBB","cin":"test2_cin","bizname":"test2_bizname","entity_type":"type","activity_group":"grp","biz_act_desc":"des","createdby":4}
|
const Pro42Data = [
|
||||||
];
|
{"losid":losid,"pan":"AA1234AAAA","cin":"test1_cin","bizname":"test1_bizname","entity_type":"type","activity_group":"grp","biz_act_desc":"des","createdby":4},
|
||||||
// insert pro42data into entities table using using foreach
|
{"losid":losid,"pan":"BB1234BBBB","cin":"test2_cin","bizname":"test2_bizname","entity_type":"type","activity_group":"grp","biz_act_desc":"des","createdby":4}
|
||||||
Pro42Data.forEach((Pro42Datavalue, key)=>{
|
];
|
||||||
// check if the Pro42Data (entity) already inserted
|
// insert pro42data into entities table using using foreach
|
||||||
Entities.findOne({ where: { losid : Pro42Datavalue.losid , pan : Pro42Datavalue.pan , cin : Pro42Datavalue.cin } }).then(Entity => {
|
Pro42Data.forEach((Pro42Datavalue, key)=>{
|
||||||
if(Entity)
|
// check if the Pro42Data (entity) already inserted
|
||||||
{
|
Entities.findOne({ where: { losid : Pro42Datavalue.losid , pan : Pro42Datavalue.pan , cin : Pro42Datavalue.cin } }).then(Entity => {
|
||||||
// skip inserting
|
if(Entity)
|
||||||
}
|
{
|
||||||
else
|
// skip inserting
|
||||||
{
|
}
|
||||||
Entities.create({ "losid":Pro42Datavalue.losid,"pan":Pro42Datavalue.pan,"cin":Pro42Datavalue.cin,"bizname":Pro42Datavalue.bizname,"entity_type":Pro42Datavalue.entity_type,"activity_group":Pro42Datavalue.activity_group,"biz_act_desc":Pro42Datavalue.biz_act_desc,"createdby":Pro42Datavalue.createdby})
|
else
|
||||||
.then(Entitydata => {
|
{
|
||||||
|
Entities.create({ "losid":Pro42Datavalue.losid,"pan":Pro42Datavalue.pan,"cin":Pro42Datavalue.cin,"bizname":Pro42Datavalue.bizname,"entity_type":Pro42Datavalue.entity_type,"activity_group":Pro42Datavalue.activity_group,"biz_act_desc":Pro42Datavalue.biz_act_desc,"createdby":Pro42Datavalue.createdby})
|
||||||
|
.then(Entitydata => {
|
||||||
|
|
||||||
//create Entityfinyears data
|
//create Entityfinyears data
|
||||||
const Y1 = new Date().getFullYear();
|
const Y1 = new Date().getFullYear();
|
||||||
const Y2 = Y1-1;
|
const Y2 = Y1-1;
|
||||||
const Y3 = Y2-1;
|
const Y3 = Y2-1;
|
||||||
Entityfinyears.create({ "losid":Entitydata.dataValues.losid,"entityid":Entitydata.dataValues.id,"Y1":Y1,"Y2":Y2,"Y3":Y3,"Y1_st_type":2,"Y2_st_type":2,"Y3_st_type":2})
|
Entityfinyears.create({ "losid":Entitydata.dataValues.losid,"entityid":Entitydata.dataValues.id,"Y1":Y1,"Y2":Y2,"Y3":Y3,"Y1_st_type":2,"Y2_st_type":2,"Y3_st_type":2})
|
||||||
.then(Entityfinyearsdata => {
|
.then(Entityfinyearsdata => {
|
||||||
|
|
||||||
//create financials data based on Entityfinyears
|
//create financials data based on Entityfinyears
|
||||||
let fin_years_array = [];
|
let fin_years_array = [];
|
||||||
fin_years_array = [
|
fin_years_array = [
|
||||||
{"entity_id":Entityfinyearsdata.dataValues.entityid,"fy":Entityfinyearsdata.dataValues.Y1,"st_type":Entityfinyearsdata.dataValues.Y1_st_type},
|
{"entity_id":Entityfinyearsdata.dataValues.entityid,"fy":Entityfinyearsdata.dataValues.Y1,"st_type":Entityfinyearsdata.dataValues.Y1_st_type},
|
||||||
{"entity_id":Entityfinyearsdata.dataValues.entityid,"fy":Entityfinyearsdata.dataValues.Y2,"st_type":Entityfinyearsdata.dataValues.Y2_st_type},
|
{"entity_id":Entityfinyearsdata.dataValues.entityid,"fy":Entityfinyearsdata.dataValues.Y2,"st_type":Entityfinyearsdata.dataValues.Y2_st_type},
|
||||||
{"entity_id":Entityfinyearsdata.dataValues.entityid,"fy":Entityfinyearsdata.dataValues.Y3,"st_type":Entityfinyearsdata.dataValues.Y3_st_type}
|
{"entity_id":Entityfinyearsdata.dataValues.entityid,"fy":Entityfinyearsdata.dataValues.Y3,"st_type":Entityfinyearsdata.dataValues.Y3_st_type}
|
||||||
];
|
];
|
||||||
|
|
||||||
// create skeletion
|
// create skeletion
|
||||||
fin_years_array.forEach((value, key)=>{
|
fin_years_array.forEach((value, key)=>{
|
||||||
const entity_id = value.entity_id;
|
const entity_id = value.entity_id;
|
||||||
const fy = value.fy;
|
const fy = value.fy;
|
||||||
const st_type = value.st_type;
|
const st_type = value.st_type;
|
||||||
|
|
||||||
// generate financials data array
|
// generate financials data array
|
||||||
let fin_data_array = [];
|
let fin_data_array = [];
|
||||||
for (let i = 1; i < 120; i++)
|
for (let i = 1; i < 120; i++)
|
||||||
{
|
{
|
||||||
fin_data_obj = { "entity_id":entity_id,"st_type":st_type,"itemid":i,"fy":fy,"value":0,"is_active":1,"createdby":4}
|
fin_data_obj = { "entity_id":entity_id,"st_type":st_type,"itemid":i,"fy":fy,"value":0,"is_active":1,"createdby":4}
|
||||||
fin_data_array.push(fin_data_obj);
|
fin_data_array.push(fin_data_obj);
|
||||||
}
|
}
|
||||||
//bulk financials data create
|
//bulk financials data create
|
||||||
Financials.bulkCreate(fin_data_array);
|
Financials.bulkCreate(fin_data_array);
|
||||||
//console.log(fin_data_array)
|
//console.log(fin_data_array)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
res.status(404).send({'status':404,
|
res.status(404).send({'status':404,
|
||||||
message: err.message || "Some error occurred while insertinging statements." ,'data': "No data" });
|
message: err.message || "Some error occurred while insertinging statements." ,'data': "No data" });
|
||||||
}); // end of entity fin year table data insert
|
}); // end of entity fin year table data insert
|
||||||
|
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
res.status(404).send({'status':404,
|
res.status(404).send({'status':404,
|
||||||
message: err.message || "Some error occurred while insertinging statements." ,'data': "No data" });
|
message: err.message || "Some error occurred while insertinging statements." ,'data': "No data" });
|
||||||
}); // end of entity insert
|
}); // end of entity insert
|
||||||
|
|
||||||
} //end of else condition
|
} //end of else condition
|
||||||
|
|
||||||
}); // end of (losid,pan,cin) combination checking entity data exist or not
|
}) // end of (losid,pan,cin) combination checking entity data exist or not
|
||||||
|
|
||||||
}); // end of pro42 data foreach
|
}) // end of pro42 data foreach
|
||||||
|
|
||||||
return ({'losid':losid,'status':200,'message':"success",'data':"No data"}); // success message
|
return ({'losid':losid,'status':200,'message':"success",'data':"No data"}); // success message
|
||||||
//end of try catch
|
//end of try catch
|
||||||
|
|
||||||
})
|
|
||||||
.then((value) => {
|
|
||||||
|
|
||||||
|
})
|
||||||
|
// await sleep(2000)
|
||||||
|
//promise.then(function(value){
|
||||||
|
//.then((value) => {
|
||||||
|
.then(function(value){
|
||||||
|
// writeToBody(topic);
|
||||||
|
console.log(value)
|
||||||
|
setTimeout(function(){
|
||||||
|
console.log(value)
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if(value.status == 200)
|
if(value.status == 200)
|
||||||
@ -354,20 +366,23 @@ exports.test = (req, res) => {
|
|||||||
}],
|
}],
|
||||||
required :false
|
required :false
|
||||||
})
|
})
|
||||||
.then(MasterData => {
|
.then(MasterData =>
|
||||||
|
{
|
||||||
|
//setTimeout(
|
||||||
Entities.findAll({where : { losid } , attributes: ['id', 'losid' , 'pan' , 'cin' , 'bizname' , 'entity_type' , 'activity_group' , 'biz_act_desc' ] })
|
Entities.findAll({where : { losid } , attributes: ['id', 'losid' , 'pan' , 'cin' , 'bizname' , 'entity_type' , 'activity_group' , 'biz_act_desc' ] })
|
||||||
|
// ,2000)
|
||||||
.then(EntitiesData => {
|
.then(EntitiesData => {
|
||||||
|
console.log(EntitiesData)
|
||||||
let data = [];
|
let data = [];
|
||||||
EntitiesData.forEach((value, key)=>{
|
EntitiesData.forEach((value, key)=>{
|
||||||
obj_data = { ...value.dataValues , statementsmasterrData:MasterData }
|
obj_data = { ...value.dataValues , statementsmasterrData:MasterData }
|
||||||
|
|
||||||
data.push(obj_data);
|
data.push(obj_data);
|
||||||
}) // end of EntitiesData foreach
|
}); // end of EntitiesData foreach
|
||||||
console.log(data)
|
console.log(data)
|
||||||
console.log('4')
|
logMsg.info("MenuList api working")
|
||||||
logMsg.info("MenuList api working");
|
Promise.resolve(res.send({'losid':losid,'status':200,'message':"success",'data':data}))
|
||||||
|
return (data);
|
||||||
return ({'status':200,'message':"success",'data':data});
|
|
||||||
}); // end of findall EntitiesData
|
}); // end of findall EntitiesData
|
||||||
}); // end of findall masters datas
|
}); // end of findall masters datas
|
||||||
} // end of starter function if condition
|
} // end of starter function if condition
|
||||||
@ -375,13 +390,24 @@ exports.test = (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.log(err)
|
console.log
|
||||||
return res.status(500).json({'status':404,'message':"failed",'data':"No data"})
|
|
||||||
}
|
}
|
||||||
|
},1000);
|
||||||
|
})
|
||||||
|
// .then((value) =>{
|
||||||
|
// console.log(value)
|
||||||
|
// console.log('last')
|
||||||
|
|
||||||
}).catch(console.log)
|
// resolve(res.send({'losid':losid,'status':200,'message':"success",'data':value}))
|
||||||
|
|
||||||
|
// })
|
||||||
|
// Promise.all([promise]).then(value => {
|
||||||
|
// console.log(value)
|
||||||
|
// console.log('last')
|
||||||
|
// resolve(res.send({'losid':losid,'status':200,'message':"success",'data':value}))
|
||||||
|
// })
|
||||||
|
|
||||||
|
.catch(console.log)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -233,6 +233,10 @@ module.exports = app => {
|
|||||||
* type: integer
|
* type: integer
|
||||||
* description: Third Year statement type
|
* description: Third Year statement type
|
||||||
* example: 1
|
* example: 1
|
||||||
|
* Y4_st_type:
|
||||||
|
* type: integer
|
||||||
|
* description: fourth Year statement type
|
||||||
|
* example: 1 or null
|
||||||
* updatedby:
|
* updatedby:
|
||||||
* type: integer
|
* type: integer
|
||||||
* description: The person who modified
|
* description: The person who modified
|
||||||
@ -815,9 +819,6 @@ module.exports = app => {
|
|||||||
*/
|
*/
|
||||||
router.get("/Historyapi", master.Historyapi);
|
router.get("/Historyapi", master.Historyapi);
|
||||||
|
|
||||||
// router.get("/printAll", test.printAll);
|
|
||||||
router.get("/test", test.test);
|
|
||||||
router.get("/test1", test.test1);
|
|
||||||
router.get("/test2", test.test2);
|
router.get("/test2", test.test2);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user