implemented added filters
This commit is contained in:
@ -175,7 +175,7 @@ export default class SampleValidate {
|
||||
let validator;
|
||||
let field = data.filters[i].field
|
||||
if (/material\./.test(field)) { // select right validation model
|
||||
validator = MaterialValidate.outputV();
|
||||
validator = MaterialValidate.outputV().append({number: Joi.string().max(128).allow('')});
|
||||
field = field.replace('material.', '');
|
||||
}
|
||||
else if (/measurements\./.test(field)) {
|
||||
@ -195,7 +195,7 @@ export default class SampleValidate {
|
||||
validator = Joi.object(this.sample);
|
||||
}
|
||||
const {value, error} = validator.validate({[field]: e});
|
||||
if (error) throw error; // reject invalid values
|
||||
if (error) throw error; // reject invalid values // TODO: return exact error description, handle in frontend filters
|
||||
return value[field];
|
||||
});
|
||||
}
|
||||
@ -215,7 +215,7 @@ export default class SampleValidate {
|
||||
filters: Joi.array().items(Joi.object({
|
||||
mode: Joi.string().valid('eq', 'ne', 'lt', 'lte', 'gt', 'gte', 'in', 'nin'),
|
||||
field: Joi.string().pattern(new RegExp('^(' + this.fieldKeys.join('|').replace(/\./g, '\\.').replace(/\*/g, '.+') + ')$', 'm')),
|
||||
values: Joi.array().items(Joi.alternatives().try(Joi.string().max(128), Joi.number(), Joi.boolean())).min(1)
|
||||
values: Joi.array().items(Joi.alternatives().try(Joi.string().max(128), Joi.number(), Joi.boolean(), Joi.date().iso())).min(1)
|
||||
})).default([])
|
||||
}).with('to-page', 'page-size').validate(data);
|
||||
}
|
||||
|
Reference in New Issue
Block a user