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?