diff options
author | William Harrington <kb0iic@berzerkula.org> | 2019-04-17 23:54:33 -0500 |
---|---|---|
committer | William Harrington <kb0iic@berzerkula.org> | 2019-04-17 23:54:33 -0500 |
commit | 1bf0efa123e96634c78d3d6c75c174c2c0c192b1 (patch) | |
tree | 8370d3d6e04f12a73a1d04d9a11f94874344972c /routes | |
parent | 75f296dcd907d9905e6d81c54ee2ce3c35bb6373 (diff) |
Add functionality for deleting members.
Diffstat (limited to 'routes')
-rw-r--r-- | routes/api/members.js | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/routes/api/members.js b/routes/api/members.js index 471cc14..f1498ae 100644 --- a/routes/api/members.js +++ b/routes/api/members.js @@ -56,4 +56,20 @@ router.put('/:id', (req, res) => { } }); +// Delete member +router.delete('/:id', (req, res) => { + const found = members.some(member => member.id === parseInt(req.params.id)); + + if(found) { + res.json({ msg: 'Member deleted', + members: members.filter(member => + member.id !== parseInt(req.params.id))}); + res.json(members.filter(member => + member.id !== parseInt(req.params.id))); + } else { + res.status(400).json({ msg: `No member with the id of ${req.params.id}` + }); + } +}); + module.exports = router; |