Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. static async getPokemon(req, res) {
  2. // Get the id from the request params
  3. const { id } = req.params;
  4.  
  5. // Destructure actions
  6. const {
  7. get,
  8. found,
  9. } = actions;
  10.  
  11. // Destructure errors
  12. const {
  13. notFound,
  14. } = errors;
  15.  
  16. // Get the pokemon through the Module
  17. const pokemon = await PokemonModule.find(id);
  18.  
  19. log(get(id));
  20.  
  21. if (pokemon) {
  22. // If a pokemon was founded it will be returned
  23. log(found(pokemon));
  24. res.send({ pokemon });
  25. } else {
  26. // if error throw an error
  27. res.status(404).send({ error: notFound(id) });
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement