Skip to content

Commit

Permalink
added features
Browse files Browse the repository at this point in the history
  • Loading branch information
yarenska committed Sep 28, 2019
1 parent 6daaca4 commit b5a987c
Show file tree
Hide file tree
Showing 13 changed files with 1,303 additions and 148 deletions.
17 changes: 16 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,22 @@ const Pokemon = require('./models/Pokemon')
app.get('/', (req, res) =>{
const promise = Pokemon.find({})
promise.then(data => res.json(data)).catch(err => res.json(err))

// The same works with a callback function:
/*Pokemon.find({}, function(data, err){
if(data)
res.json(data)
else
res.json(err)
})*/
})

app.get('/:id', (req, res, next) => {
const promise = Pokemon.find({national_id:req.params.id})
promise.then((pokemon) => {
if(!pokemon)
next({message: "The pokemon doesn't exist"})
res.json(pokemon)
}).catch(err => res.json(err))
})

app.listen(process.env.PORT || 3000, () => {
Expand Down
Loading

0 comments on commit b5a987c

Please sign in to comment.