From 3ca8bb266c3ecc74ad233587748b0a3787a18aa0 Mon Sep 17 00:00:00 2001 From: Dennis Eriksen Date: Thu, 23 May 2013 17:15:49 +0200 Subject: added method to get recent activity for all projects a user belongs to --- models/pPost.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/models/pPost.js b/models/pPost.js index 7181b69..c6def28 100644 --- a/models/pPost.js +++ b/models/pPost.js @@ -40,7 +40,8 @@ pPostSchema.statics = { .exec(callback); }, - /** + + /** * Find all posts that belong to a project, by project id * * @param {ObjectId} project @@ -53,6 +54,24 @@ pPostSchema.statics = { .populate('user') .sort({ 'when': -1 }) .exec(callback); + }, + + + /** + * Find last ten posts belonging projects a user is part of, by project ids + * + * @param {Array[ObjectId]} projects + * @param {Function} callback + * @api private + */ + + loadByProjects: function(projects, callback) { + this.find({ project: { $in: projects } }) + .populate({ path: 'user', select: 'name email status' }) + .populate({ path: 'project', select: 'name shortURL' }) + .limit(10) + .sort({ 'when': -1 }) + .exec(callback); } } -- cgit v1.2.3