mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-19 03:22:45 +00:00
Small tweaks and linting
This commit is contained in:
@@ -15,12 +15,12 @@ const getGoodBrewTitle = (text) => {
|
|||||||
const ending = text.indexOf('\n', titlePos);
|
const ending = text.indexOf('\n', titlePos);
|
||||||
return text.substring(titlePos + 2, ending);
|
return text.substring(titlePos + 2, ending);
|
||||||
} else {
|
} else {
|
||||||
return _.find(text.split('\n'), line => line);
|
return _.find(text.split('\n'), (line)=>line);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const newBrew = (req, res)=>{
|
const newBrew = (req, res)=>{
|
||||||
let authors = (req.account) ? [req.account.username] : [];
|
const authors = (req.account) ? [req.account.username] : [];
|
||||||
|
|
||||||
const newHomebrew = new HomebrewModel(_.merge({},
|
const newHomebrew = new HomebrewModel(_.merge({},
|
||||||
req.body,
|
req.body,
|
||||||
@@ -45,8 +45,6 @@ const newBrew = (req, res) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
router.post('/api', newBrew);
|
|
||||||
|
|
||||||
const updateBrew = (req, res)=>{
|
const updateBrew = (req, res)=>{
|
||||||
HomebrewModel.get({ editId: req.params.id })
|
HomebrewModel.get({ editId: req.params.id })
|
||||||
.then((brew)=>{
|
.then((brew)=>{
|
||||||
@@ -75,17 +73,16 @@ const updateBrew = (req, res) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
router.put('/api/update/:id', updateBrew);
|
|
||||||
router.put('/api/:id', updateBrew);
|
|
||||||
|
|
||||||
const deleteBrew = (req, res)=>{
|
const deleteBrew = (req, res)=>{
|
||||||
HomebrewModel.find({ editId: req.params.id }, (err, objs)=>{
|
HomebrewModel.find({ editId: req.params.id }, (err, objs)=>{
|
||||||
if (!objs.length || err)
|
if(!objs.length || err) {
|
||||||
return res.status(404).send('Can not find homebrew with that id');
|
return res.status(404).send('Can not find homebrew with that id');
|
||||||
|
}
|
||||||
|
|
||||||
const brew = objs[0];
|
const brew = objs[0];
|
||||||
|
|
||||||
// Remove current user as author
|
|
||||||
if(req.account) {
|
if(req.account) {
|
||||||
|
// Remove current user as author
|
||||||
brew.authors = _.pull(brew.authors, req.account.username);
|
brew.authors = _.pull(brew.authors, req.account.username);
|
||||||
brew.markModified('authors');
|
brew.markModified('authors');
|
||||||
}
|
}
|
||||||
@@ -106,8 +103,11 @@ const deleteBrew = (req, res) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
router.get('/api/remove/:id', deleteBrew);
|
router.post('/api', newBrew);
|
||||||
|
router.put('/api/:id', updateBrew);
|
||||||
|
router.put('/api/update/:id', updateBrew);
|
||||||
router.delete('/api/:id', deleteBrew);
|
router.delete('/api/:id', deleteBrew);
|
||||||
|
router.get('/api/remove/:id', deleteBrew);
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user