Skip to content

Commit

Permalink
feat: pokemon details page get
Browse files Browse the repository at this point in the history
  • Loading branch information
felixtanhm committed May 7, 2024
1 parent 05d3144 commit b20c0b7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,20 @@ exports.pokeList = async function (req, res, next) {
return next(error);
}
};

exports.pokeDetails = async function (req, res, next) {
try {
const pokemon = await Pokemons.findOne({ dexId: req.params.dexId })
.populate("details")
.exec();
if (pokemon === null) {
const error = new Error("Pokemon not found");
error.status = 404;
return next(error);
}

res.status(200).json(pokemon);
} catch (error) {
return next(error);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ const pokeController = require("../controllers/pokeController");
/* GET Pokemon List */
router.get("/pokemon", pokeController.pokeList);

router.get("/pokemon/:pokemonId", function (req, res, next) {
console.log("get individual pokemon: " + `${req.params.pokemonId}`);
});
router.get("/pokemon/:dexId", pokeController.pokeDetails);

module.exports = router;

0 comments on commit b20c0b7

Please sign in to comment.