Update routeRestaurant.js
This commit is contained in:
@@ -77,15 +77,20 @@ router.get("/dishes", (req, res) => {
|
|||||||
if (err) {
|
if (err) {
|
||||||
res.sendStatus(404);
|
res.sendStatus(404);
|
||||||
} else {
|
} else {
|
||||||
const dishesCount = result.dishes.length;
|
var dishesCount = result.dishes.length;
|
||||||
let dishes = [];
|
let dishes = [];
|
||||||
result.dishes.forEach((element) => {
|
result.dishes.forEach((element) => {
|
||||||
Dish.findById(element, (err, result) => {
|
Dish.findById(element, (err, result) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log("ERROR fetching dish");
|
res.sendStatus(500);
|
||||||
} else {
|
} else {
|
||||||
dishes.push(result);
|
if (result === null) {
|
||||||
if (dishes.length == dishesCount) res.send(dishes);
|
dishesCount--;
|
||||||
|
if (dishes.length == dishesCount) res.send(dishes);
|
||||||
|
} else {
|
||||||
|
dishes.push(result);
|
||||||
|
if (dishes.length == dishesCount) res.send(dishes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user