1
0
mirror of https://github.com/stolksdorf/homebrewery.git synced 2025-12-18 00:01:27 +00:00

Added in middleware for retriving brews by a user

This commit is contained in:
Scott Tolksdorf
2016-11-23 23:41:39 -05:00
parent 1db24d07bd
commit 750f5c1330
5 changed files with 62 additions and 18 deletions

View File

@@ -16,8 +16,6 @@ refreshCount();
const getTopBrews = (cb)=>{
HomebrewModel.find().sort({views: -1}).limit(5).exec(function(err, brews) {
cb(brews);
@@ -39,7 +37,10 @@ const getGoodBrewTitle = (text) => {
router.post('/api', (req, res)=>{
const newHomebrew = new HomebrewModel(req.body);
const newHomebrew = new HomebrewModel(_.merge({},
req.body,
{authors : [req.account.username]}
));
if(!newHomebrew.title){
newHomebrew.title = getGoodBrewTitle(newHomebrew.text);
}
@@ -57,6 +58,7 @@ router.put('/api/update/:id', (req, res)=>{
.then((brew)=>{
brew = _.merge(brew, req.body);
brew.updatedAt = new Date();
brew.authors = _.uniq(_.concat(brew.authors, req.account.username));
brew.save((err, obj)=>{
if(err) throw err;
return res.status(200).send(obj);