I am new to this world of NodeJS and I have a question about the processing of the JS node with the use of express ...
Problem: I am running a routine that I created to compile data from 2 api of 2 sectors and in the routine I make the data come from 1 type only by changing the sector identifier ... when I squeeze from a sector it is processing normal and inserts the data right so if I call to process the 2 sectors at the same time the routine gets mixed up the data of the sectors.
In php if I do this it does not mix the data it does both independent processing.
Example of data: Call sector 1
{
"key": 12045,
"tittle": "Help with my pc",
"sector": 1
}
Call sector 2
{
"key": "Task-I12",
"tittle": "License expire",
"sector": 2
}
when processing processing together it blends data from sector 1 with 2 as 1 processing
{
"key": 12045,
"tittle": "License expire",
"sector": 1
}
Exemplo Code:
app.get('/api/up',async (req, res) => {
populateData = await PopulateDataBug.populate(req.query).then(result => {
return result;
});
res.send({ populateData });
});
async function populate(req) {
let tasks = {};
if(req.sector == 2){
tasks = await getFromHelpDesk();
}else{
tasks = await getFromTI();
}
for (let index = 0; index < tasks.length; index++) {
const bug = tasks[index];
let sql = `INSERT INTO bi_task_data (task_data_id,task_date,task_data_sector)
VALUES ('${bug.id}','${bug.closed_time}',${sector})`;
await MysqlConn.query(sql).then(r => {
return r
});
}
return tasks;
}