aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/models
diff options
context:
space:
mode:
authorDennis Eriksen <dennis.se@gmail.com>2013-04-30 12:25:44 +0200
committerDennis Eriksen <dennis.se@gmail.com>2013-04-30 12:25:44 +0200
commit334cdccec27afcb1a353df49f7edb77181048843 (patch)
tree8b687012b7e20c19c36e3ed1498b3a17fbaa4bd2 /models
parentmade a function for returning all accesses for a user including their projects (diff)
downloadDivid-334cdccec27afcb1a353df49f7edb77181048843.tar.gz
made a function for returning project by ID
Diffstat (limited to 'models')
-rw-r--r--models/project.js26
1 files changed, 19 insertions, 7 deletions
diff --git a/models/project.js b/models/project.js
index 2424694..2641fe5 100644
--- a/models/project.js
+++ b/models/project.js
@@ -6,12 +6,8 @@
var mongoose = require('mongoose')
, Schema = mongoose.Schema;
-
-
-
-
var ProjectSchema = new Schema({
- user: { type: String, ref: 'User' },
+ user: { type: Schema.ObjectId, ref: 'User' },
name: { type: String, default: '', trim: true },
description: {type: String, default: '', trim: true },
currency: { type: String, default: 'kr', trim: true },
@@ -20,7 +16,6 @@ var ProjectSchema = new Schema({
updated: { type: Date, default: Date.now }
});
-
// the four validations below only apply if you are signing up traditionally
ProjectSchema.path('name').validate(function(name) {
@@ -28,12 +23,29 @@ ProjectSchema.path('name').validate(function(name) {
return name.length;
}, 'Project name cannot be blank');
-ProjectSchema.methods = {
+ProjectSchema.statics = {
log: function() {
console.log('wat. wat logged this');
+ },
+
+
+
+ /**
+ * Find project by id
+ *
+ * @param {ObjectId} id
+ * @param {Function} callback
+ * @api private
+ */
+
+ load: function(id, callback) {
+ this.findOne({ _id: id })
+ .populate('user')
+ .exec(callback);
}
+
}
mongoose.model('Project', ProjectSchema);