Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- setDuplicateEmailValidation(){
- this.schema.path('email').validate((email, fn) => {
- let User = mongoose.model('User');
- // Check only when it is a new user or when email field is modified
- if (this.isNew || this.isModified('email')) {
- User.find({ email: email }).exec((err, users) => {
- fn(!err && users.length === 0);
- });
- } else fn(true);
- }, 'Email already exists');
- }
- function setDuplicateEmailValidation() {
- var _this = this;
- this.schema.path('email').validate(function (email, fn) {
- var User = _mongoose2['default'].model('User');
- // Check only when it is a new user or when email field is modified
- if (_this.isNew || _this.isModified('email')) {
- User.find({ email: email }).exec(function (err, users) {
- fn(!err && users.length === 0);
- });
- } else fn(true);
- }, 'Email already exists');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement