1
0
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:
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

@@ -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);