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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user