Skip to content

Instantly share code, notes, and snippets.

@anymaniax
Last active November 23, 2016 19:46
Show Gist options
  • Save anymaniax/b074bb9630c45293680cff52f0260f6c to your computer and use it in GitHub Desktop.
Save anymaniax/b074bb9630c45293680cff52f0260f6c to your computer and use it in GitHub Desktop.
let mongoose = require('mongoose')
let userSchema = new mongoose.Schema({
lastname: {
type: String,
required: true
},
firstname: {
type: String,
required: true
},
username: {
type: String,
required: true,
index: {
unique: true
}
},
password: {
type: String,
required: true
},
birthdate: {
type: Date,
required: true
},
email: {
type: String,
required: true
},
address: {
street: {
type: String,
required: true
},
postalCode: {
type: Number,
required: true
},
country: {
type: String,
required: true
}
},
sex: {
type: Boolean,
required: true
},
phone: {
type: Number,
required: true
},
role: {
type: String,
required: true
},
})
userSchema.methods.comparePassword = function(candidatePassword, cb) {
bcrypt.compare(candidatePassword, this.password, function(err, isMatch) {
if (err) return cb(err);
cb(null, isMatch);
});
};
module.exports = mongoose.model('User', userSchema)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment