-
Notifications
You must be signed in to change notification settings - Fork 0
/
controllers.js
40 lines (37 loc) · 996 Bytes
/
controllers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const pokedex = require("./functions");
const list = async (req, res) => {
try {
const pokemons = await pokedex.getPokemons();
res.status(200).send({
success: true,
content: pokemons
});
} catch (err) {
console.log(err);
res.status(500).send({
success: false,
message: err.message
});
}
};
const details = async (req, res) => {
const { id } = req.params;
try {
const pokemon = await pokedex.getPokemon(id);
if (pokemon) {
res.status(200).send({ success: true, content: pokemon });
} else {
res.status(404).send({
success: false,
message: "Pokemon not found in 1st generation"
});
}
} catch (err) {
console.log(err);
res.status(500).send({
success: false,
message: err.message
});
}
};
module.exports = { list, details };