Last active
November 23, 2016 19:46
-
-
Save anymaniax/b074bb9630c45293680cff52f0260f6c 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
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