diff options
-rw-r--r-- | index.js | 2 | ||||
-rw-r--r-- | routes/api/members.js | 13 |
2 files changed, 13 insertions, 2 deletions
@@ -9,7 +9,7 @@ const app = express(); // Body Parser Middleware app.use(express.json()); -app.use(express.urlencoded({exnteded: false})); +app.use(express.urlencoded({extended: false})); // Set static directory app.use(express.static(path.join(__dirname, 'public'))); diff --git a/routes/api/members.js b/routes/api/members.js index a7c71cd..c0186f6 100644 --- a/routes/api/members.js +++ b/routes/api/members.js @@ -1,4 +1,5 @@ const express = require('express'); +const uuid = require('uuid/v4'); const router = express.Router(); const members = require('../../Members'); @@ -21,8 +22,18 @@ router.get('/:id', (req, res) => { // Create Member router.post('/', (req, res) => { const newMember = { - + id: uuid(), + name: req.body.name, + email: req.body.email, + status: 'active' } + + if(!newMember.name || !newMember.email) { + return res.status(400).json({ msg: 'Please populate name and email' }); + } + + members.push(newMember); + res.json(members); }); module.exports = router; |