Skip to content

Commit 0a5450c

Browse files
Nisreen OweidatNisreen Oweidat
authored andcommitted
Implemented Pokemon API fixes and enhancements
1 parent 8f80953 commit 0a5450c

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

src/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ app.use("/pokemon", pokemonRouter);
2222
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
2323

2424
module.exports = app;
25+
app.listen(3000,console.log("Server running on port 3000"));

src/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"version": "0.0.0",
44
"private": true,
55
"scripts": {
6-
"start": "node ./bin/www"
6+
"start": "node ./bin/www",
7+
"start" : "nodemon ./bin/www"
78
},
89
"dependencies": {
910
"cookie-parser": "~1.4.4",

src/routes/pokemon.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,62 @@ router.get("/", function (req, res, next) {
1010
/* GET Pokemon by Id. */
1111
router.get("/:id", function (req, res, next) {
1212
// TODO: Implement this route. See swagger docs for details, by visiting http://localhost:3000/api-docs
13+
14+
const id = req.params.id;
15+
const pokemon = pokedex.find(p => p.id == id);
16+
17+
if (pokemon) {
18+
res.json(pokemon);
19+
return;
20+
}
21+
1322
res.status(501).json({ message: "Not Implemented" });
1423
return;
1524
});
1625

1726
/* GET Pokemon by English Name */
1827
router.get("/name/:name", function (req, res, next) {
1928
// TODO: Implement this route. See swagger docs for details, by visiting http://localhost:3000/api-docs
20-
res.status(501).json({ message: "Not Implemented" });
21-
return;
29+
30+
const name = req.params.name;
31+
const pokemon = pokedex.find(p => p.name.english === "Pikachu");
32+
if (!pokemon) {
33+
return res.status(404).json({ error: "Pokemon not found" });
34+
}
35+
res.json(pokemon);
2236
});
2337

2438
/* GET Pokemon by Type */
2539
router.get("/type/:type", function (req, res, next) {
2640
// TODO: Implement this route. See swagger docs for details, by visiting http://localhost:3000/api-docs
41+
42+
const type = req.params.type;
43+
const pokemon = pokedex.filter(p => p.type.includes("Fire"));
44+
45+
if (pokemon) {
46+
res.json(pokemon);
47+
return;
48+
}
49+
50+
2751
res.status(501).json({ message: "Not Implemented" });
2852
return;
2953
});
3054

3155
/* GET Pokemon by HP */
3256
router.get("/hp", function (req, res, next) {
3357
// TODO: Implement this route. See swagger docs for details, by visiting http://localhost:3000/api-docs
58+
59+
const hp = req.params.hp;
60+
const pokemon = pokedex.filter(p => p.base.HP >= 90);
61+
62+
if (pokemon) {
63+
res.json(pokemon);
64+
return;
65+
}
66+
67+
68+
3469
res.status(501).json({ message: "Not Implemented" });
3570
return;
3671
});

0 commit comments

Comments
 (0)