generator-angular-fullstack icon indicating copy to clipboard operation
generator-angular-fullstack copied to clipboard

Email Validation always returns error 422

Open palfaro91 opened this issue 6 years ago • 0 comments

  • [X] I understand that GitHub issues are not for tech support, but for questions specific to this generator, bug reports, and feature requests.
Item Version
generator-angular-fullstack 4.2.2
Node 8.9.2
npm 5.6.0
Operating System OS X 10.12.6
Item Answer
Transpiler Babel
Markup HTML
CSS CSS
Router ui-router
Client Tests Mocha
DB MongoDB
Auth Y
mongoose 4.1.2

Hello! I'm having an issue where I try to update a user's email but the validation always, always returns an error. The error response says "email cannot be blank" but I can see that an email is present and not blank. If I comment out the blank email validation out it then throws the duplicate email validation error even though the email does not exist in the db.

validation code

UserSchema  
  .path('email')  
  .validate(function(email){  
    if(authTypes.indexOf(this.provider) !== -1) { return true; }  
    return !!(email && email.length);  
}, 'Email cannot be blank');

route controller

export function updateContact(req, res){
  if(req.body._id) { Reflect.deleteProperty(req.body, '_id');}  
  let update = new User(req.body);  
  let setUpdate = { $set: { email: update.email, phoneNumber: update.phoneNumber, } };  
  return User.findByIdAndUpdate(req.params.id, setUpdate, {new:true, upsert:true, 
     setDefaultsOnInsert:true, runValidators:true}).exec()  
    .then( (user) => res.json(user); )  
    .catch(validationError(res));  
}

I'm not sure what I am doing wrong.

palfaro91 avatar Apr 05 '18 17:04 palfaro91