mirror of
https://github.com/stolksdorf/homebrewery.git
synced 2025-12-20 23:21:32 +00:00
Added in middleware for retriving brews by a user
This commit is contained in:
@@ -55,6 +55,22 @@ HomebrewSchema.statics.get = function(query){
|
||||
});
|
||||
};
|
||||
|
||||
HomebrewSchema.statics.getByUser = function(username, allowAccess=false){
|
||||
return new Promise((resolve, reject) => {
|
||||
let query = {authors : username, published : true};
|
||||
if(allowAccess){
|
||||
delete query.published;
|
||||
}
|
||||
Homebrew.find(query, (err, brews)=>{
|
||||
if(err) return reject('Can not find brew');
|
||||
return resolve(_.map(brews, (brew)=>{
|
||||
return brew.sanatize(!allowAccess);
|
||||
}));
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
var Homebrew = mongoose.model('Homebrew', HomebrewSchema);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user