667 lines
27 KiB
JavaScript
667 lines
27 KiB
JavaScript
|
|
const { response } = require('express');
|
|
const { sequelize, Entities , Financials , Statementsmaster , Sectionsmaster , Subsectionsmaster , Brokenperiods , Entityfinyears } = require('../models')
|
|
const { logMsg } = require('../services/logger.js');
|
|
const financialControllerHelper = require('../services/financial.controller.helper.js');
|
|
const camundaHelper = require('../services/camunda.helper.js');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
|
|
|
|
exports.intiator = (req, res) => {
|
|
const losid = req.query.losid
|
|
console.log(losid)
|
|
console.log('1')
|
|
try
|
|
{
|
|
starter(losid,MenuList)
|
|
}
|
|
catch(err) {
|
|
res.status(500).send({'status':404,
|
|
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
|
|
}); }
|
|
}
|
|
|
|
|
|
function giveresponse(value) {
|
|
|
|
try
|
|
{
|
|
res.status({value});
|
|
}
|
|
catch(err) {
|
|
res.status(500).send({'status':404,
|
|
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
|
|
}); }
|
|
}
|
|
// menu list api
|
|
function MenuList (value,giveresponse) {
|
|
|
|
try {
|
|
const losid = req.query.losid
|
|
// call starter function here
|
|
|
|
req_obj ={"losid":losid}
|
|
|
|
starter_response = starter(req_obj);
|
|
|
|
setTimeout(()=>{
|
|
if(starter_response.status == 200)
|
|
{
|
|
Statementsmaster.findAll({
|
|
where :{is_active : 1} ,
|
|
attributes: ['id', 'statement', 'is_active'],
|
|
include :[{
|
|
association: 'sectionsmasterData' ,
|
|
where :{is_active : 1} ,
|
|
attributes: ['id', 'section', 'is_active'],
|
|
include :[{
|
|
association: 'subsectionsmasterData' ,
|
|
where :{is_active : 1} ,
|
|
attributes: ['id', 'subsection','itemtext', 'is_active'],
|
|
required :false
|
|
}],
|
|
required :false
|
|
}],
|
|
required :false
|
|
})
|
|
.then(MasterData => {
|
|
Entities.findAll({where : { losid } , attributes: [ 'id', 'losid' , 'pan' , 'cin' , 'bizname' , 'entity_type' , 'activity_group' , 'biz_act_desc' , 'process_instance_id' ] })
|
|
.then(EntitiesData => {
|
|
let data = [];
|
|
EntitiesData.forEach((value, key)=>{
|
|
|
|
instancesid = value.dataValues.process_instance_id;
|
|
taskid = camundaHelper.financialsListOfProcessInstances(instancesid);
|
|
taskid.then(function(result){
|
|
formVariable = camundaHelper.financialsFormVariables(result);
|
|
formVariable.then(function(form_result){
|
|
formVariableResult = JSON.parse(form_result);
|
|
if(formVariableResult.type){ camunda_status = {"process_status":"NULL"}; } else { camunda_status =JSON.parse(form_result); }
|
|
obj_data = { ...value.dataValues ,status:camunda_status , statementsmasterrData:MasterData }
|
|
data.push(obj_data);
|
|
});
|
|
});
|
|
// obj_data = { ...value.dataValues , statementsmasterrData:MasterData }
|
|
// data.push(obj_data);
|
|
|
|
}); // end of EntitiesData foreach
|
|
|
|
setTimeout(()=>{
|
|
// below code for overall sum object push process
|
|
sum_data = { ...{'losid':losid,'bizname':"Consolidated Financials Summary",'is_consolidated_api_call':1} , statementsmasterrData:MasterData };
|
|
data.push(sum_data);
|
|
// send respose to FE
|
|
res.send({'status':200,'message':"success",'data':data});
|
|
},5000)
|
|
}); // end of findall EntitiesData
|
|
}); // end of findall masters datas
|
|
} // end of starter function if condition
|
|
},5000)
|
|
} catch (err) {
|
|
console.log(err)
|
|
return res.status(500).json({'status':404,'message':"failed",'data':"No data"})
|
|
}
|
|
|
|
};
|
|
|
|
|
|
//testing
|
|
function starter(value, MenuList)
|
|
{
|
|
|
|
const losid = req.losid;
|
|
try
|
|
{
|
|
|
|
//pro 42 api call using losid
|
|
const Pro42Data = [
|
|
{"losid":losid,"pan":"AA1234AAAA","cin":"test1_cin","bizname":"test1_bizname","entity_type":"type","activity_group":"grp","biz_act_desc":"des","createdby":4},
|
|
{"losid":losid,"pan":"BB1234BBBB","cin":"test2_cin","bizname":"test2_bizname","entity_type":"type","activity_group":"grp","biz_act_desc":"des","createdby":4}
|
|
];
|
|
// insert pro42data into entities table using using foreach
|
|
Pro42Data.forEach((Pro42Datavalue, key)=>{
|
|
// check if the Pro42Data (entity) already inserted
|
|
Entities.findOne({ where: { losid : Pro42Datavalue.losid , pan : Pro42Datavalue.pan , cin : Pro42Datavalue.cin } }).then(Entity => {
|
|
if(Entity)
|
|
{
|
|
// skip inserting
|
|
}
|
|
else
|
|
{
|
|
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 => {
|
|
|
|
//process instance Id update
|
|
const primeryId = Entitydata.dataValues.id;
|
|
const user = "SMC";
|
|
processInstanceId = camundaHelper.startFinancialsProcessInstance(Entitydata.dataValues.losid,Entitydata.dataValues.pan,user);
|
|
processInstanceId.then(function(InstanceId){
|
|
Entities.update({ "process_instance_id":InstanceId },{ where: { id: primeryId }});
|
|
});
|
|
|
|
//create Entityfinyears data
|
|
const Y1 = new Date().getFullYear();
|
|
const Y2 = Y1-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})
|
|
.then(Entityfinyearsdata => {
|
|
|
|
//create financials data based on Entityfinyears
|
|
let 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.Y2,"st_type":Entityfinyearsdata.dataValues.Y2_st_type},
|
|
{"entity_id":Entityfinyearsdata.dataValues.entityid,"fy":Entityfinyearsdata.dataValues.Y3,"st_type":Entityfinyearsdata.dataValues.Y3_st_type}
|
|
];
|
|
|
|
// create skeletion
|
|
fin_years_array.forEach((value, key)=>{
|
|
const entity_id = value.entity_id;
|
|
const fy = value.fy;
|
|
const st_type = value.st_type;
|
|
|
|
// generate financials data array
|
|
let fin_data_array = [];
|
|
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_array.push(fin_data_obj);
|
|
} //console.log("------"+entity_id +"---"+ fy)
|
|
//bulk financials data create
|
|
Financials.bulkCreate(fin_data_array);
|
|
//console.log(fin_data_array)
|
|
});
|
|
|
|
|
|
}).catch(err => {
|
|
res.status(404).send({'status':404,
|
|
message: err.message || "Some error occurred while insertinging statements." ,'data': "No data" });
|
|
}); // end of entity fin year table data insert
|
|
|
|
}).catch(err => {
|
|
res.status(404).send({'status':404,
|
|
message: err.message || "Some error occurred while insertinging statements." ,'data': "No data" });
|
|
}); // end of entity insert
|
|
|
|
} //end of else condition
|
|
|
|
}); // end of (losid,pan,cin) combination checking entity data exist or not
|
|
|
|
}); // end of pro42 data foreach
|
|
|
|
MenuList({'losid':losid,'status':200,'message':"success",'data':"No data"}); // success message
|
|
|
|
|
|
} catch(err) {
|
|
res.status(500).send({'status':404,
|
|
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
|
|
}); } //end of try catch
|
|
|
|
|
|
|
|
|
|
//end of try catch
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// exports.printAll = () => {
|
|
|
|
// .then(() => {
|
|
// return console.log("B")
|
|
// })
|
|
// .then(() => {
|
|
// return console.log("C")
|
|
// })
|
|
// }
|
|
//printAll()
|
|
|
|
// function doSomething(){
|
|
// return doAnotherThing(parameter).then(function(other){
|
|
// // Do more stuff
|
|
// return "xxxxx"
|
|
// });
|
|
// }
|
|
|
|
// // Usage
|
|
// doSomething().then(function(other){
|
|
// console.log (other)
|
|
// });
|
|
|
|
exports.test = (req, res) => {
|
|
const losid = req.query.losid;
|
|
|
|
const promise = Promise.resolve(res.send({'losid':losid,'status':200,'message':"success","data":data}));
|
|
const promise1 = new Promise((resolve, reject) => {
|
|
console.log(losid)
|
|
const data = losid
|
|
console.log('1')
|
|
return data
|
|
|
|
|
|
//to call starter here
|
|
promise.then(val => console.log(val));
|
|
|
|
})
|
|
.then(losid => {
|
|
//call menulist
|
|
console.log(losid);
|
|
console.log('2')
|
|
});
|
|
// const promise = Promise.resolve(res.send({'losid':losid,'status':200,'message':"success","data":data}));
|
|
};
|
|
exports.test1 = (req, res) => {
|
|
const v = doSomething(function(x) {
|
|
console.log(x);
|
|
doSomethingMore(x, function(y) {
|
|
console.log(y);
|
|
doRestOfTheThings(y, function(z) {
|
|
console.log(z);
|
|
});
|
|
});
|
|
});
|
|
doSomething();
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
exports.test2 = async (req, res) => {
|
|
const losid = req.query.losid
|
|
|
|
// const promise = Promise.resolve(res.send({'losid':losid,'status':200,'message':"success"}));
|
|
var promise = (losid) => new Promise((resolve,reject) =>{
|
|
resolve(losid)
|
|
|
|
|
|
})
|
|
// p1(losid).then((losid) => {
|
|
|
|
promise(losid).then((losid) => {
|
|
|
|
console.log(losid)
|
|
//pro 42 api call using losid
|
|
const Pro42Data = [
|
|
{"losid":losid,"pan":"AA1234AAAA","cin":"test1_cin","bizname":"test1_bizname","entity_type":"type","activity_group":"grp","biz_act_desc":"des","createdby":4},
|
|
{"losid":losid,"pan":"BB1234BBBB","cin":"test2_cin","bizname":"test2_bizname","entity_type":"type","activity_group":"grp","biz_act_desc":"des","createdby":4}
|
|
];
|
|
// insert pro42data into entities table using using foreach
|
|
Pro42Data.forEach((Pro42Datavalue, key)=>{
|
|
// check if the Pro42Data (entity) already inserted
|
|
Entities.findOne({ where: { losid : Pro42Datavalue.losid , pan : Pro42Datavalue.pan , cin : Pro42Datavalue.cin } }).then(Entity => {
|
|
if(Entity)
|
|
{
|
|
// skip inserting
|
|
}
|
|
else
|
|
{
|
|
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
|
|
const Y1 = new Date().getFullYear();
|
|
const Y2 = Y1-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})
|
|
.then(Entityfinyearsdata => {
|
|
|
|
//create financials data based on Entityfinyears
|
|
let 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.Y2,"st_type":Entityfinyearsdata.dataValues.Y2_st_type},
|
|
{"entity_id":Entityfinyearsdata.dataValues.entityid,"fy":Entityfinyearsdata.dataValues.Y3,"st_type":Entityfinyearsdata.dataValues.Y3_st_type}
|
|
];
|
|
|
|
// create skeletion
|
|
fin_years_array.forEach((value, key)=>{
|
|
const entity_id = value.entity_id;
|
|
const fy = value.fy;
|
|
const st_type = value.st_type;
|
|
|
|
// generate financials data array
|
|
let fin_data_array = [];
|
|
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_array.push(fin_data_obj);
|
|
}
|
|
//bulk financials data create
|
|
Financials.bulkCreate(fin_data_array);
|
|
//console.log(fin_data_array)
|
|
});
|
|
|
|
|
|
}).catch(err => {
|
|
res.status(404).send({'status':404,
|
|
message: err.message || "Some error occurred while insertinging statements." ,'data': "No data" });
|
|
}); // end of entity fin year table data insert
|
|
|
|
}).catch(err => {
|
|
res.status(404).send({'status':404,
|
|
message: err.message || "Some error occurred while insertinging statements." ,'data': "No data" });
|
|
}); // end of entity insert
|
|
|
|
} //end of else condition
|
|
|
|
}) // end of (losid,pan,cin) combination checking entity data exist or not
|
|
|
|
}) // end of pro42 data foreach
|
|
|
|
return ({'losid':losid,'status':201,'message':"success",'data':"No data"}); // success message
|
|
//end of try catch
|
|
|
|
|
|
})
|
|
// await sleep(2000)
|
|
//promise.then(function(value){
|
|
//.then((value) => {
|
|
.then(function(value){
|
|
// writeToBody(topic);
|
|
|
|
setTimeout(function(){
|
|
|
|
try {
|
|
|
|
if(value.status == 200)
|
|
{
|
|
Statementsmaster.findAll({
|
|
where :{is_active : 1} ,
|
|
attributes: ['id', 'statement', 'is_active'],
|
|
include :[{
|
|
association: 'sectionsmasterData' ,
|
|
where :{is_active : 1} ,
|
|
attributes: ['id', 'section', 'is_active'],
|
|
include :[{
|
|
association: 'subsectionsmasterData' ,
|
|
where :{is_active : 1} ,
|
|
attributes: ['id', 'subsection','itemtext', 'is_active'],
|
|
required :false
|
|
}],
|
|
required :false
|
|
}],
|
|
required :false
|
|
})
|
|
.then(MasterData =>
|
|
{
|
|
//setTimeout(
|
|
Entities.findAll({where : { losid } , attributes: ['id', 'losid' , 'pan' , 'cin' , 'bizname' , 'entity_type' , 'activity_group' , 'biz_act_desc' ] })
|
|
// ,2000)
|
|
.then(EntitiesData => {
|
|
console.log(EntitiesData)
|
|
let data = [];
|
|
EntitiesData.forEach((value, key)=>{
|
|
obj_data = { ...value.dataValues , statementsmasterrData:MasterData }
|
|
|
|
data.push(obj_data);
|
|
}); // end of EntitiesData foreach
|
|
console.log(data)
|
|
logMsg.info("MenuList api working")
|
|
Promise.resolve(res.send({'losid':losid,'status':200,'message':"success",'data':data}))
|
|
// return (data);
|
|
}); // end of findall EntitiesData
|
|
}); // end of findall masters datas
|
|
} // end of starter function if condition
|
|
//return {'status':200,'message':"success",'data':data};
|
|
}
|
|
|
|
catch (err) {
|
|
console.log
|
|
}
|
|
},1000);
|
|
})
|
|
// .then((value) =>{
|
|
// console.log(value)
|
|
// console.log('last')
|
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.testwo = async (req, res) => {
|
|
console.log( "testtwo")
|
|
req_obj ={"losid":"TEST123"}
|
|
testhree(req_obj);
|
|
|
|
|
|
};
|
|
|
|
function testhree(req , res) {
|
|
console.log( "testthree")
|
|
|
|
console.log( req.losid)
|
|
res.send({'status':200,'message':"success"});
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.MenuList = (req, res) => {
|
|
|
|
//Statementsmaster.findAll({ where :{is_active : 1} , include: { all: true, nested: true , where :{is_active : 1} , required:false}})
|
|
try {
|
|
const losid = req.query.losid
|
|
// call starter function here
|
|
|
|
req_obj ={"losid":losid}
|
|
|
|
starter_response = starter(req_obj);
|
|
|
|
setTimeout(()=>{
|
|
if(starter_response.status == 200)
|
|
{
|
|
Statementsmaster.findAll({
|
|
where :{is_active : 1} ,
|
|
attributes: ['id', 'statement', 'is_active'],
|
|
include :[{
|
|
association: 'sectionsmasterData' ,
|
|
where :{is_active : 1} ,
|
|
attributes: ['id', 'section', 'is_active'],
|
|
include :[{
|
|
association: 'subsectionsmasterData' ,
|
|
where :{is_active : 1} ,
|
|
attributes: ['id', 'subsection','itemtext', 'is_active'],
|
|
required :false
|
|
}],
|
|
required :false
|
|
}],
|
|
required :false
|
|
})
|
|
.then(MasterData => {
|
|
Entities.findAll({where : { losid } , attributes: [ 'id', 'losid' , 'pan' , 'cin' , 'bizname' , 'entity_type' , 'activity_group' , 'biz_act_desc' , 'process_instance_id' ] })
|
|
.then(EntitiesData => {
|
|
let data = [];
|
|
EntitiesData.forEach((value, key)=>{
|
|
|
|
instancesid = value.dataValues.process_instance_id;
|
|
taskid = camundaHelper.financialsListOfProcessInstances(instancesid);
|
|
taskid.then(function(result){
|
|
formVariable = camundaHelper.financialsFormVariables(result);
|
|
formVariable.then(function(form_result){
|
|
formVariableResult = JSON.parse(form_result);
|
|
if(formVariableResult.type){ camunda_status = {"process_status":"NULL"}; } else { camunda_status =JSON.parse(form_result); }
|
|
obj_data = { ...value.dataValues ,status:camunda_status , statementsmasterrData:MasterData }
|
|
data.push(obj_data);
|
|
});
|
|
});
|
|
// obj_data = { ...value.dataValues , statementsmasterrData:MasterData }
|
|
// data.push(obj_data);
|
|
|
|
}); // end of EntitiesData foreach
|
|
|
|
setTimeout(()=>{
|
|
// below code for overall sum object push process
|
|
sum_data = { ...{'losid':losid,'bizname':"Consolidated Financials Summary",'is_consolidated_api_call':1} , statementsmasterrData:MasterData };
|
|
data.push(sum_data);
|
|
// send respose to FE
|
|
res.send({'status':200,'message':"success",'data':data});
|
|
},5000)
|
|
}); // end of findall EntitiesData
|
|
}); // end of findall masters datas
|
|
} // end of starter function if condition
|
|
},5000)
|
|
} catch (err) {
|
|
console.log(err)
|
|
return res.status(500).json({'status':404,'message':"failed",'data':"No data"})
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.readLogFileName = async (req , res) =>
|
|
{
|
|
try
|
|
{
|
|
folderName = req;
|
|
const logFilePath = 'storage/log';
|
|
|
|
const fileNames = fs.readdirSync(logFilePath);
|
|
// Remove the first element (0th index)
|
|
const [, ...data] = fileNames;
|
|
return data;
|
|
|
|
}
|
|
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.readLogFile = async (req , res) =>
|
|
{
|
|
try
|
|
{
|
|
folderName = req.body.folder;
|
|
fileName = req.body.file;
|
|
const logFilePath = 'storage/log/'+fileName;
|
|
|
|
fs.readFile(logFilePath, 'utf8', (err, data) => {
|
|
if (err) {
|
|
console.error(err);
|
|
res.status(500).send({'status':404,'message': err.message || "Error reading log file." ,'data': "No data"});
|
|
}
|
|
res.send({'status':200 , message:"Success." ,'data': data});
|
|
});
|
|
|
|
}
|
|
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.viewLandingPage = async (req , res) =>
|
|
{
|
|
try
|
|
{
|
|
moduleName = [ { "module":"FINANCIAL","folder":"smc_cet_financials_backend"} ];
|
|
img = []
|
|
for(const [index,val] of moduleName.entries())
|
|
{
|
|
fileName = await this.readLogFileName(val.folder);
|
|
console.log(fileName);
|
|
for (let i = 0; i < fileName.length; i++)
|
|
{
|
|
filePath = 'storage/log/'+fileName[i];
|
|
const logData = fs.readFileSync(filePath);
|
|
// Convert the file content to Base64
|
|
const base64Data = logData.toString('base64');
|
|
// Create Base64 URL from Base64 data
|
|
const base64Url = `data:application/octet-stream;base64,${encodeURIComponent(base64Data)}`;
|
|
img.push(base64Url)
|
|
}
|
|
moduleName[index] = await Object.assign(val,{'file':fileName , 'img':img});
|
|
};
|
|
res.render( 'module' , { 'data' : moduleName } ,function (err, html ) {
|
|
res.send(html)
|
|
})
|
|
|
|
}
|
|
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.deleteLogFile = async (req , res) =>
|
|
{
|
|
try
|
|
{
|
|
folderName = req.body.folder;
|
|
fileName = req.body.file;
|
|
|
|
// folderName = 'smc_cet_creditpd_backend';
|
|
// fileName = 'msg.log.2023-07-10';
|
|
const logFilePath = 'storage/log/'+fileName;
|
|
fs.unlink(logFilePath, (err) => {
|
|
if (err) {
|
|
console.error(`Error deleting file: ${err}`);
|
|
return;
|
|
}
|
|
|
|
console.log('File deleted successfully.');
|
|
res.send({'status':200 , message:"Success." ,'data': 'No data'});
|
|
});
|
|
|
|
}
|
|
catch(err)
|
|
{
|
|
res.status(500).send({'status':404,
|
|
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
|
|
});
|
|
} //end of try catch
|
|
};
|
|
|
|
|