0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-13 06:32:39 +00:00

Added in full test coverage of current spec

This commit is contained in:
Scott Tolksdorf
2017-01-06 17:45:48 -05:00
parent 987363ed41
commit ca40ec5a2d
14 changed files with 413 additions and 170 deletions

View File

@@ -14,35 +14,36 @@ router.get('/api/brew', (req, res, next) => {
//Get
router.get('/api/brew/:shareId', mw.viewBrew, (req, res, next) => {
return res.json(req.brew);
return res.json(req.brew.toJSON());
});
//Create
router.post('/api/brew', (req, res, next)=>{
const newBrew = req.body;
if(req.account) newBrew.authors = [req.account.username];
BrewData.create(newBrew)
const brew = req.body;
if(req.account) brew.authors = [req.account.username];
BrewData.create(brew)
.then((brew) => {
return res.json(brew);
return res.json(brew.toJSON());
})
.catch(next)
});
//Update
router.put('/api/brew/:editId', mw.loadBrew, (req, res, next)=>{
const brew = req.body || {};
if(req.account){
req.brew.authors = _.uniq(_.concat(req.brew.authors, req.account.username));
brew.authors = _.uniq(_.concat(brew.authors, req.account.username));
}
BrewData.update(req.brew)
BrewData.update(req.params.editId, brew)
.then((brew) => {
return res.json(brew);
return res.json(brew.toJSON());
})
.catch(next);
});
//Delete
router.delete('/api/brew/:editId', mw.loadBrew, (req, res, next) => {
BrewData.remove(req.brew.editId)
BrewData.remove(req.params.editId)
.then(()=>{
return res.sendStatus(200);
})