diff options
author | William Harrington <kb0iic@berzerkula.org> | 2019-04-17 23:32:19 -0500 |
---|---|---|
committer | William Harrington <kb0iic@berzerkula.org> | 2019-04-17 23:32:19 -0500 |
commit | 75f296dcd907d9905e6d81c54ee2ce3c35bb6373 (patch) | |
tree | 390b44f3c59a0266b0a9a51026a21ad776e8bf82 /routes/api/members.js | |
parent | c23fe800aa5748398c6b49c25e73765e36dcb17c (diff) |
Update members fields if in request.
Diffstat (limited to 'routes/api/members.js')
-rw-r--r-- | routes/api/members.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/routes/api/members.js b/routes/api/members.js index c0186f6..471cc14 100644 --- a/routes/api/members.js +++ b/routes/api/members.js @@ -36,4 +36,24 @@ router.post('/', (req, res) => { res.json(members); }); +// Updat Member +router.put('/:id', (req, res) => { + const found = members.some(member => member.id === parseInt(req.params.id)); + + if (found) { + const updMember = req.body; + members.forEach(member => { + if(member.id === parseInt(req.params.id)) { + member.name = updMember.name ? updMember.name : member.name; + member.email = updMember.email ? updMember.email : member.email; + + res.json({ msg: 'Member updated', member }); + } + }); + } else { + res.status(400).json({ msg: `No member with the id of ${req.prams.id}` + }); + } +}); + module.exports = router; |