Skip to content

Commit

Permalink
added route to delete a dinosaur to the dinosaur router
Browse files Browse the repository at this point in the history
  • Loading branch information
ridgeO committed Jan 7, 2019
1 parent 3fdfab1 commit 15a5da8
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions routers/dinosaur.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,31 @@ router.route('/:dinosaur_id')
});
};
});
})

// define route to delete a dinosaur (accessed via DELETE http://localhost:8000/api/:dinosaur_id)
.delete(function(req, res) {
// find dinosaur record by id and execute callback function
Dinosaur.findById(req.params.dinosaur_id, function(err, dinosaur) {
if(err) {
// return an error in the response
res.send(err);
} else {
// remove the dinosaur
dinosaur.remove(function(err) {
if (err) {
// return an error in the response
res.send(err);
} else {
// return a message and the dinosaur record in the response
res.json({
message: 'Dinosaur removed!',
dinosaur
});
}
});
};
});
});

// export router for use in the application
Expand Down

0 comments on commit 15a5da8

Please sign in to comment.