Advertisement
Guest User

Untitled

a guest
Jul 4th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. setDuplicateEmailValidation(){
  2. this.schema.path('email').validate((email, fn) => {
  3. let User = mongoose.model('User');
  4.  
  5. // Check only when it is a new user or when email field is modified
  6. if (this.isNew || this.isModified('email')) {
  7. User.find({ email: email }).exec((err, users) => {
  8. fn(!err && users.length === 0);
  9. });
  10. } else fn(true);
  11. }, 'Email already exists');
  12. }
  13.  
  14. function setDuplicateEmailValidation() {
  15. var _this = this;
  16. this.schema.path('email').validate(function (email, fn) {
  17. var User = _mongoose2['default'].model('User');
  18.  
  19. // Check only when it is a new user or when email field is modified
  20. if (_this.isNew || _this.isModified('email')) {
  21. User.find({ email: email }).exec(function (err, users) {
  22. fn(!err && users.length === 0);
  23. });
  24. } else fn(true);
  25. }, 'Email already exists');
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement