I want to rate product, but when using postman its working but when hitting request on frontend by axios error showing that id is unefined which I am sending by request.params.
const { comment, rating } = req.body;
console.log(rating);
const { id } = req.params;
console.log(id);
// find product
const product = await productModel.findById(id);
This is backend code in which id is getting by request.params and router URL is
router.put("/:id/review", requireSignIn, userRatings);
const submitHandler = async (e, id) => {
e.preventDefault();
try {
const { data } = await axios.put(`/api/dp/${id}/review`, {
comment,
rating,
});
console.log(data.message);
toast.success(data.message);
setComment("");
setRating(0);
} catch (error) {
console.log(error);
}
};
This is the front end function on click. In this function when seing on consol showing id UNDEFINED ?
data: “Proxy error: Could not proxy request /api/dp/undefined/review from localhost:3000
In that case I am using PUT method to rate product.