aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/app/models/pPost.js
diff options
context:
space:
mode:
authorDennis Eriksen <dennis.se@gmail.com>2013-05-25 11:17:42 +0200
committerDennis Eriksen <dennis.se@gmail.com>2013-05-25 11:17:42 +0200
commite582c3b84c6090b08f33d599c354968fcd868d14 (patch)
treeb6de1b7b1f708bf9126ccb709d5129e91a67c7d5 /app/models/pPost.js
parentchanged what gets collected (diff)
downloadDivid-e582c3b84c6090b08f33d599c354968fcd868d14.tar.gz
moved and renamed files to match the filesetup we want.
havebeen using a dev-setup till now.
Diffstat (limited to 'app/models/pPost.js')
-rw-r--r--app/models/pPost.js78
1 files changed, 78 insertions, 0 deletions
diff --git a/app/models/pPost.js b/app/models/pPost.js
new file mode 100644
index 0000000..1f53984
--- /dev/null
+++ b/app/models/pPost.js
@@ -0,0 +1,78 @@
+
+/**
+ * Module dependencies
+ */
+
+var mongoose = require('mongoose')
+ , Schema = mongoose.Schema;
+
+var pPostSchema = new Schema({
+ user: { type: Schema.ObjectId, ref: 'User' },
+ for: { type: Schema.ObjectId, ref: 'User' },
+ project: { type: Schema.ObjectId, ref: 'Project' },
+ what: { type: String, default: '', trim: true },
+ comment: { type: String, default: '', trim: true },
+ participants: [],
+ value: { type: Number, defailt: 0 },
+ file: { type: String, default: '', trim: true },
+ currency: { type: String, default: 'kr', trim: true },
+ created: { type: Date, default: Date.now },
+ updated: { type: Date, default: Date.now },
+ when: { type: Date, default: Date.now }
+});
+
+
+
+
+pPostSchema.statics = {
+
+ /**
+ * Find post by id
+ *
+ * @param {ObjectId} id
+ * @param {Function} callback
+ * @api private
+ */
+
+ load: function(id, callback) {
+ this.findOne({ _id: id })
+ .populate({ path: 'user', select: '_id, name'})
+ .exec(callback);
+ },
+
+
+ /**
+ * Find all posts that belong to a project, by project id
+ *
+ * @param {ObjectId} project
+ * @param {Function} callback
+ * @api private
+ */
+
+ loadProject: function(project, callback) {
+ this.find({ project: project })
+ .populate('user')
+ .sort({ 'when': -1, 'created': -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: '_id name' })
+ .populate({ path: 'project', select: 'name shortURL' })
+ .sort({ 'when': -1, 'created': -1 })
+ .exec(callback);
+ }
+
+}
+
+mongoose.model('pPost', pPostSchema);