const User = require("../model/User") exports.createOrder = async (req, res) => { try { const { userId, products, totalAmount } = req.body const user = await User.findById(userId) if (!user) { return res.status(404).json({ message: "User not found" }) } const newOrder = { products: products, totalAmount: totalAmount, purchaseOn: Date.now(), } user.orderedProducts.push(newOrder) await user.save() res.status(201).json({ message: "Order created successfully", order: newOrder, }) } catch (error) { console.error(error) res.status(500).json({ message: "Internal Server Error" }) } }