@@ -10,27 +10,62 @@ router.get("/", function (req, res, next) {
1010/* GET Pokemon by Id. */
1111router . 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 */
1827router . 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 */
2539router . 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 */
3256router . 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