You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, first of all thanks for this useful package 👍
Then, I'm running in couple of problems and I was wondering if someone had already went trough these:
For some model I have a complex creation logic and I want so skip standard validation for some creation flows. For doing this I have custom beforeCreate or beforeValidate for some models. What I would like to do is to manually throw your "patched" validation error if some conditions occurs. Is it possible? How?
In my controllers when I return a response in json I check whether or not there are errors. I check error.Errors in case a validation error occurs. But this is not always the case, and in many cases the structure of the errors messages are really different. How to manage this?
So far I've came to a simple
but this is not always the case, because the structure of the error can change, depending on the type of error. I know it's a broad question but I was wondering if you already faced this kind of problems.
Thanks!
The text was updated successfully, but these errors were encountered:
I have different use case but the solution might be helpful to you. In my situation, I need to do validation over 2 models in once. You might "clone" your model and put those validations for some creation flows
var objectMerge = require('object-merge');
var Promise = require('bluebird');
var User = require('./User');
var Auth = require('./Auth');
var model = {
connection: 'memory',
tableName: 'UserAuthValidation',
schema: true,
attributes: {}
};
var attributesToCheck = [ 'id', 'status', 'name', 'email', 'type', 'key', 'credential' ];
for (var key in User.attributes) {
if (attributesToCheck.indexOf(key) >= 0) {
model.attributes[key] = User.attributes[key];
}
}
for (var key in Auth.attributes) {
if (attributesToCheck.indexOf(key) >= 0) {
model.attributes[key] = Auth.attributes[key];
}
}
var key = 'validationMessages';
model[key] = objectMerge(objectMerge.createOptions({depth : 3}), User[key], Auth[key]);
module.exports = model;
Hello, first of all thanks for this useful package 👍
Then, I'm running in couple of problems and I was wondering if someone had already went trough these:
For some model I have a complex creation logic and I want so skip standard validation for some creation flows. For doing this I have custom
beforeCreate
orbeforeValidate
for some models. What I would like to do is to manually throw your "patched" validation error if some conditions occurs. Is it possible? How?In my controllers when I return a response in json I check whether or not there are errors. I check
error.Errors
in case a validation error occurs. But this is not always the case, and in many cases the structure of the errors messages are really different. How to manage this?So far I've came to a simple
but this is not always the case, because the structure of the error can change, depending on the type of error. I know it's a broad question but I was wondering if you already faced this kind of problems.
Thanks!
The text was updated successfully, but these errors were encountered: