Skip to content

Commit

Permalink
developer-job-simulation#3 Get Pokemon by type
Browse files Browse the repository at this point in the history
  • Loading branch information
AjelmarMedina committed Dec 16, 2023
1 parent af3921b commit d95e323
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/routes/pokemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ router.get("/name/:name", function (req, res, next) {

/* GET Pokemon by Type */
router.get("/type/:type", function (req, res, next) {
// TODO: Implement this route. See swagger docs for details, by visiting http://localhost:3000/api-docs
res.status(501).json({ message: "Not Implemented" });
const qType = req.params.type.toLowerCase();
const searchResults = pokedex.filter(pokemon => pokemon.type.find(type => type.toLowerCase() === qType));
if (searchResults) res.status(200).json(searchResults);
else res.status(404).json({ error: "Not found" });
return;
});

Expand Down

0 comments on commit d95e323

Please sign in to comment.