aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
Diffstat (limited to 'routes')
-rw-r--r--routes/api/members.js20
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;