Last active
December 23, 2015 11:15
-
-
Save mrm8488/89adc5b3edb150e96ccd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongoose = require('mongoose'); | |
var schema = new mongoose.Schema({ | |
name: { | |
type: String, | |
required: true, | |
index: {unique: true} | |
}, | |
banned: { | |
type: Boolean, | |
default: false | |
} | |
}); | |
// statics methods | |
schema.statics.findUserById = function(userId) { | |
return Promise.resolve(this.findById(userId).exec()); | |
} | |
schema.statics.findAllUsers = function() { | |
return Promise.resolve(this.find({}).exec()); | |
} | |
schema.statics.saveUser = function(user) { | |
return Promise.resolve(this.save(user)); | |
} | |
schema.statics.removeUserByName = function(name) { | |
return Promise.resolve(this.findOneAndRemove({name: name}).exec()); | |
} | |
// And so on.. | |
var User = mongoose.model('User', schema); | |
module.exports = User; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment