Skip to content

Commit

Permalink
2nd gen
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin-Morette committed Nov 11, 2024
1 parent 6c19499 commit 6a9ea70
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend/src/controllers/PokemonController.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class PokemonController {

static import = (req, res) => {
// Récupère le JSON du fichier gen2.json
// eslint-disable-next-line global-require
const pokemonsList = require("../gen2.json");
const pokemonListClean = [];
// Parcours la liste de pokémons
Expand Down
17 changes: 17 additions & 0 deletions backend/src/controllers/ZoneController.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ class ZoneController {
}
});
};

static readByGeneration = (req, res) => {
const { generation } = req.params;
models.zone
.readByGeneration(generation)
.then(([rows]) => {
const zones = [];
rows.forEach((row) => {
zones.push(row.name);
});
res.send(zones);
})
.catch((err) => {
console.error(err);
res.sendStatus(500);
});
};
}

module.exports = ZoneController;
1 change: 1 addition & 0 deletions backend/src/models/PokemonManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class PokemonManager extends AbstractManager {
WHERE
z.name = ?
AND p.name != "MEW"
AND p.name != "CELEBI"
ORDER BY
p.id ASC`,
[nameZone]
Expand Down
7 changes: 7 additions & 0 deletions backend/src/models/ZoneManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ class ZoneManager extends AbstractManager {
[name]
);
}

readByGeneration(generation) {
return this.connection.query(
`SELECT name FROM ${ZoneManager.table} WHERE generation = ?`,
[generation]
);
}
}

module.exports = ZoneManager;
1 change: 1 addition & 0 deletions backend/src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ router.post("/rune/buy", RuneTrainerController.buy);
router.post("/rune/use", PokemonController.useRune);

router.get("/zone/pokemon/:name", ZoneController.findZoneByPokemonName);
router.get("/zone/:generation", ZoneController.readByGeneration);

module.exports = router;

0 comments on commit 6a9ea70

Please sign in to comment.