From c23fe800aa5748398c6b49c25e73765e36dcb17c Mon Sep 17 00:00:00 2001 From: William Harrington Date: Wed, 17 Apr 2019 23:17:06 -0500 Subject: Add new member functionality --- routes/api/members.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'routes/api') 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; -- cgit v1.2.3-54-g00ecf