I have spend hours trying to revolve this but I can not.
function get(req, res) {
let results = {};
req.body.vehiculos.forEach(async vehiculo => {
const response = await axios.get(`https://api/foo=${vehiculo}`)
response.data.data.forEach(async truck => {
results[truck.id] = [];
let queryresult = await sql.query(`SELECT x from x where = ${vehiculo}`)
results[truck.id].push({ ...truck, ...queryresult.recordset[0] });
console.log('------------------------------');
console.log(results);
});
})
return res.status(200).send({ message: "Success", data: results })
}
This is my JavaScript function I need to fill the results variable with the data that the axios returns, I have the data but can not access to the results variable, I can read it but can not rewrite, hope you can help me, I am new in JavaScript. Greetings.