-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TODO] egg-validate 集成 #70
Comments
已经在 #69 中引入了,但只在 POST topic/create 中使用了。还有遗留的工作是 render validate error. |
这一块有人在跟进吗?egg-validate 不能自定义错误提示文字? |
@sinchang const Parameter = require('parameter');
const parameter = new Parameter();
function checkAge(rule, value) {
if (typeof value !== 'number') {
return this.t('年龄必须是数字');
}
if (value > 100) {
return this.t('年龄不能大于 200');
}
if (rule.rule) {
return this.validate(rule.rule, value);
}
}
parameter.addRule('age', checkAge)
const data = {
name: 'foo',
age: 'yibai',
// age: 200,
};
const rule = {
name: 'string',
age: 'age',
};
const errors = parameter.validate(rule, data);
console.log(errors)
// [ { message: '年龄不能大于 200', code: 'invalid', field: 'age' } ]
// [ { message: '年龄必须是数字', code: 'invalid', field: 'age' } ] |
i18n 那个?我之前提了 RFC 但后面没时间搞 |
好的好的,去看看,有时间搞一下~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The text was updated successfully, but these errors were encountered: