Untitled
unknown
plain_text
7 months ago
615 B
97
Indexable
Never
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 }); } };