diff options
author | William Harrington <kb0iic@berzerkula.org> | 2019-04-17 22:31:34 -0500 |
---|---|---|
committer | William Harrington <kb0iic@berzerkula.org> | 2019-04-17 22:31:34 -0500 |
commit | b90d55622f8ad987a1d6d900f5f5837168ed7d92 (patch) | |
tree | 6cc0f6e76704b3f5a0aee9844486f701b0c14c4e /routes/api/members.js | |
parent | d6e3532db9af9c01478770e0fd46673b35582069 (diff) |
Extract member routes to api.
Diffstat (limited to 'routes/api/members.js')
-rw-r--r-- | routes/api/members.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/routes/api/members.js b/routes/api/members.js index e69de29..d1c3bf9 100644 --- a/routes/api/members.js +++ b/routes/api/members.js @@ -0,0 +1,21 @@ +const express = require('express'); +const router = express.Router(); + + +// Gets all members +router.get('/api/members', (req, res) => res.json(members)); + +// Get single member +router.get('/api/members/:id', (req, res) => { + const found = members.some(member => member.id === parseInt(req.params.id)); + + if(found) { + 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}` + }); + } +}); + + |