I have the error from my orderController.js file below When I make a post request, it's giving back a 500 internal server error and not reading _id
I am trying to get the user response from the response, then add it to the request
I have the userController, mongodb already added _id, and I have access to it from a req
import asyncHandler from "express-async-handler";
import Order from "../models/productModel.js";
// desc Create order
// route POST /api/orders
// access Private
const addOrderItems = asyncHandler(async (req, res) => {
const {
orderItems,
shippingAddress,
paymentMethod,
itemsPrice,
taxPrice,
shippingPrice,
totalPrice,
} = req.body;
if (orderItems && orderItems.length === 0) {
res.status(400);
throw new Error("No items in cart");
return;
} else {
const order = new Order({
orderItems,
user: res.user._id,
shippingAddress,
paymentMethod,
itemsPrice,
taxPrice,
shippingPrice,
totalPrice,
});
const createdOrder = await order.save();
res.status(201).json(createdOrder);
}
});
export { addOrderItems };
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>