diff options
author | Dennis Eriksen <dennis.se@gmail.com> | 2013-04-30 12:25:23 +0200 |
---|---|---|
committer | Dennis Eriksen <dennis.se@gmail.com> | 2013-04-30 12:25:23 +0200 |
commit | f51fa5f8d2c29e0bccd13bf287f917aeb121ee5c (patch) | |
tree | e2805d2c0afb718eb18e03be14dfa9f11f7eee06 /models | |
parent | made the dashboard list actice projects (diff) | |
download | Divid-f51fa5f8d2c29e0bccd13bf287f917aeb121ee5c.tar.gz |
made a function for returning all accesses for a user including their projects
Diffstat (limited to 'models')
-rw-r--r-- | models/access.js | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/models/access.js b/models/access.js index 486ef5d..ab8d257 100644 --- a/models/access.js +++ b/models/access.js @@ -7,9 +7,9 @@ var mongoose = require('mongoose') , Schema = mongoose.Schema; var AccessSchema = new Schema({ - user: { type: String, ref: 'User' }, - creator: { type: String, ref: 'User' }, - project: { type: String, ref: 'Project' }, + user: { type: Schema.ObjectId, ref: 'User' }, + creator: { type: Schema.ObjectId, ref: 'User' }, + project: { type: Schema.ObjectId, ref: 'Project' }, permissions: { type: Number, default: '3' }, created: { type: Date, default: Date.now }, updated: { type: Date, default: Date.now } @@ -17,12 +17,27 @@ var AccessSchema = new Schema({ // the four validations below only apply if you are signing up traditionally -ProjectSchema.methods = { +AccessSchema.statics = { log: function() { console.log('wat. wat logged this'); + }, + + /** + * Load ALL accesses for a single user + * + * @param {ObjectId} id + * @param {Function} callback + * @api private + */ + + loadUser: function(id, callback) { + this.find({ user: id }) + .populate('user') + .populate('project') + .sort({ 'created': -1 }) // sort by date + .exec(callback); } - } mongoose.model('Access', AccessSchema); |