Skip to content

Commit

Permalink
remove execs and return to break
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminEwhite committed Jul 17, 2017
1 parent b3ca314 commit 5c67ec7
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ app.get('/restaurants', (req, res) => {
// we're limiting because restaurants db has > 25,000
// documents, and that's too much to process/return
.limit(10)
// `exec` returns a promise
.exec()
// success callback: for each restaurant we got back, we'll
// call the `.apiRepr` instance method we've created in
// models.js in order to only expose the data we want the API return.
Expand All @@ -46,7 +44,6 @@ app.get('/restaurants/:id', (req, res) => {
// this is a convenience method Mongoose provides for searching
// by the object _id property
.findById(req.params.id)
.exec()
.then(restaurant =>res.json(restaurant.apiRepr()))
.catch(err => {
console.error(err);
Expand Down Expand Up @@ -90,7 +87,7 @@ app.put('/restaurants/:id', (req, res) => {
`Request path id (${req.params.id}) and request body id ` +
`(${req.body.id}) must match`);
console.error(message);
res.status(400).json({message: message});
return res.status(400).json({message: message});
}

// we only support a subset of fields being updateable.
Expand All @@ -108,15 +105,13 @@ app.put('/restaurants/:id', (req, res) => {
Restaurant
// all key/value pairs in toUpdate will be updated -- that's what `$set` does
.findByIdAndUpdate(req.params.id, {$set: toUpdate})
.exec()
.then(restaurant => res.status(204).end())
.catch(err => res.status(500).json({message: 'Internal server error'}));
});

app.delete('/restaurants/:id', (req, res) => {
Restaurant
.findByIdAndRemove(req.params.id)
.exec()
.then(restaurant => res.status(204).end())
.catch(err => res.status(500).json({message: 'Internal server error'}));
});
Expand Down

0 comments on commit 5c67ec7

Please sign in to comment.