My function should assign an employee on a seat if the seat is available. I do not understand why the program doesn\'t act as synchronous even though I used \"await\".
I
The easiest solution is to use an actual for loop instead of forEach
for this task. forEach()
won't wait to iterate over everything.
try {
for (const seat of seats) {
var employee = await connection.EmployeesGraph.findAll({
where: {
id: seat.EmployeeGraphId
}
})
.catch(err => {
res.status(err.status).json(err)
});
employees.push(employee);
}
} catch (err) {
res.status(err.status).json(err)
}