From 75f296dcd907d9905e6d81c54ee2ce3c35bb6373 Mon Sep 17 00:00:00 2001 From: William Harrington Date: Wed, 17 Apr 2019 23:32:19 -0500 Subject: Update members fields if in request. --- routes/api/members.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'routes/api') 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; -- cgit v1.2.3-54-g00ecf