I am trying to do update an array "projects" depending on a query to a db forEach value from the array. When I get the value and assign it to the current index of the projects, it does not update on the actual array.
I've already tried some resolve reject promise structure, .map, .forEach, a normal for loop, a callback inside the query, but none of these have work.
projects.forEach((project, i) => {
let query = squel
.select()
.field("s.Clave_Proyecto")
.field("s.Semana_Numero")
.field("s.Porcentaje_Semana")
.from("Semana", "s")
.where("s.Clave_Proyecto = ?", project["Clave_Proyecto"])
.toParam();
db.get().query(query.text, query.values, (error, weeks) => {
if(error) return res.status(400).send(error);
if(weeks) project["weeks"] = Object.values(JSON.stringify(weeks));
else project["weeks"] = ["No weeks available"];
projects[i] = project;
console.log(projects[i]);
});
});
It should return the project instance updated with the new "weeks" attribute as an array.