Skip to content

Commit

Permalink
Issue developer-job-simulation#3 Implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
clowjs committed Nov 28, 2023
1 parent f8e7637 commit dde1683
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/routes/pokemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,18 @@ 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 requestedType =
req.params.type.charAt(0).toUpperCase() +
req.params.type.slice(1).toLowerCase();

const result = pokedex.filter(pokemon => pokemon.type.includes(requestedType));

if (!result || result.length === 0) {
res.status(400).json({ error: "Bad request"});
return;
}

res.status(200).json(result);
return;
});

Expand Down

0 comments on commit dde1683

Please sign in to comment.