this module does not appear to work
drj-io opened this issue · 2 comments
drj-io commented
model:
module.exports = {
attributes: {
email: {
type: 'email',
required: true,
unique: true
},
password: {
type: 'string',
minLength: 6,
maxLength: 256,
required: true
},
username: {
type: 'string',
minLength: 2,
maxLength: 20,
required: true,
unique: true
},
},
validationMessages: { //hand for i18n & l10n
email: {
required: 'Email is required',
email: 'Provide valid email address',
unique: 'Email address is already taken'
},
username: {
required: 'Username is required'
}
},
}
in the controller I used User.save() and User.update() and neither "err" had a property of "error"
user.save(function(err){
if(err){
console.log("-->",err.error);
return res.serverError();
}
req.user=user;
userProfilePage(req,res);
})
log: --> undefined
err contains:
Details: Details: Invalid attributes sent to Users:
• email
• `undefined` should be a email (instead of "", which is a string)
• "required" validation rule failed for input: ''
not very useful
finally, using update:
User.update({ id: req.user.id }, { email: "fdkljajklfdas" })
.exec(function(error, user){
console.log("->",error);
console.log("-->",user)
res.send('...');
})
error is the same object as usual
and error.error is of course undefined.
nahanil commented
https://github.com/lykmapipo/sails-hook-validation#create
States you should have error.Errors & error.Errors.email
Been a long while since I set this up myself though so I probably can't be of much more help.