Untitled
unknown
plain_text
2 years ago
615 B
109
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...