Untitled
unknown
plain_text
3 years ago
615 B
116
Indexable
export const getProducts = async (req, res) => {
try {
const products = await Product.find();
const productsWithStats = await Promise.all(
products.map(async (product) => {
const stat = await ProductStat.find({
productId: product._id,
});
return {
...product._doc,
stat,
};
})
);
res.status(200).json(productsWithStats);
} catch (error) {
res.status(404).json({ message: error.message });
}
};Editor is loading...