0
//get Logged in user orders
exports.myOrders = catchAsyncErrors(async (req, res, next) => {
  const orders = await Order.find({ user: req.user._id });

  res.status(200).json({
    success: true,
    orders,
  });
});

const express = require("express");
const { isAuthenticatedUser, authorizeRoles } = require("../middleware/auth");
const {
  newOrder,
  getSingleOrder,
  myOrders,
} = require("../controller/orderController");
const router = express.Router();

router.route("/order/new").post(isAuthenticatedUser, newOrder);

router
  .route("/orders/:id")
  .get(isAuthenticatedUser, authorizeRoles("admin"), getSingleOrder);

//getting error in this /orders/me route
router.route("/orders/me").get(isAuthenticatedUser, myOrders);

module.exports = router;

image of the postmen when i try to access the orders when loged In

I was trying to get all the orders by the logged in user but getting an error in the routing

  • 1
    Move `/orders/me` **above** `/orders/:id`. See [Order of router precedence in express.js](https://stackoverflow.com/q/32603818/283366) – Phil Jun 23 '23 at 01:07

0 Answers0