aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/models
diff options
context:
space:
mode:
authorDennis Eriksen <dennis.se@gmail.com>2013-05-23 17:15:49 +0200
committerDennis Eriksen <dennis.se@gmail.com>2013-05-23 17:15:49 +0200
commit3ca8bb266c3ecc74ad233587748b0a3787a18aa0 (patch)
treee0633da48c49457b0fc4d765d02b88d2cbf48e78 /models
parentfixed last activity on project page, and bug when posting new items (diff)
downloadDivid-3ca8bb266c3ecc74ad233587748b0a3787a18aa0.tar.gz
added method to get recent activity for all projects a user belongs to
Diffstat (limited to 'models')
-rw-r--r--models/pPost.js21
1 files changed, 20 insertions, 1 deletions
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);
}
}