0

Api routes:

router.get("/", passport.authenticate('jwt', { session: false }), Controller.getAll);
router.get("/category_items",  passport.authenticate('jwt', { session: false }), Controller.getCategoryItems);

Error Message on postman and console :

{
    "message": "TypeError: Cannot read properties of undefined (reading 'itemCategories')"
}

The error occurs because of a getById route, which is not the route that I want to send the request to.

I have an API with following Routes:

router.get("/:id", passport.authenticate('jwt', { session: false }), Controller.getById);
router.get("/", passport.authenticate('jwt', { session: false }), Controller.getAll);
router.get("/category_items",  passport.authenticate('jwt', { session: false }), Controller.getCategoryItems);
router.post("/", passport.authenticate('jwt', { session: false }), Controller.create);
router.put("/", passport.authenticate('jwt', { session: false }), Controller.update);
router.delete("/:id", passport.authenticate('jwt', { session: false }), Controller.destroy

The problem is that when I try to test getCategoryItems on Postman by typing /category_items after my link, post counts category_items as an id, so an error in getById method appears in the console.

Does anybody have any idea about this issue?

Phil
  • 157,677
  • 23
  • 242
  • 245
  • 1
    `:id` is added first so picks up first, so it serves anything that follows `/`. Move the `:id` handler below the `/category_items` one and test again. – Joachim Isaksson Jan 04 '23 at 07:51

0 Answers0