I'm facing an issue where I need to query my database twice, log the data, and then send it. However, due to the promise not resolving in time, I am unable to send the data promptly. Can someone advise me on how to ensure that all promises are resolved before sending the data? Any help would be greatly appreciated.
app.get("/organizations/:slug_id/:category_id", function(req, res, next) {
queries.getAllProducts(req.params.category_id)
.then(function(result) {
return result.map(function(obj) {
queries.getAllProductsImages(obj.product_id)
.then(function(images) {
obj["images"] = images;
return obj;
})
})
})
.then(function(products) {
res.status(200).json(products)
})
.catch(function(error) {
next(error);
});
});