added notes.comment field and filter
This commit is contained in:
@ -28,7 +28,8 @@ export default class SampleValidate {
|
||||
notes: Joi.object({
|
||||
comment: Joi.string()
|
||||
.max(512)
|
||||
.allow(''),
|
||||
.allow('')
|
||||
.allow(null),
|
||||
|
||||
sample_references: Joi.array()
|
||||
.items(Joi.object({
|
||||
@ -78,6 +79,7 @@ export default class SampleValidate {
|
||||
'batch',
|
||||
'added',
|
||||
'status',
|
||||
'notes.comment',
|
||||
'material.name',
|
||||
'material.supplier',
|
||||
'material.group',
|
||||
@ -196,6 +198,7 @@ export default class SampleValidate {
|
||||
data.filters[i] = decodeURIComponent(data.filters[i]);
|
||||
}
|
||||
catch (ignore) {}
|
||||
console.log(data.filters[i]);
|
||||
data.filters[i] = JSON.parse(data.filters[i]);
|
||||
data.filters[i].values = data.filters[i].values.map(e => { // validate filter values
|
||||
if (e === null) { // null values are always allowed
|
||||
@ -223,11 +226,14 @@ export default class SampleValidate {
|
||||
});
|
||||
field = 'value';
|
||||
}
|
||||
else if (field === 'notes.comment') {
|
||||
field = 'comment';
|
||||
validator = this.sample.notes
|
||||
}
|
||||
else {
|
||||
validator = Joi.object(this.sample);
|
||||
}
|
||||
const {value, error} = validator.validate({[field]: e});
|
||||
console.log(error);
|
||||
if (error) throw error; // reject invalid values
|
||||
return value[field];
|
||||
});
|
||||
@ -260,7 +266,7 @@ export default class SampleValidate {
|
||||
new RegExp('^(' + this.fieldKeys.join('|').replace(/\./g, '\\.').replace(/\*/g, '.+') + ')$', 'm')
|
||||
).messages({'string.pattern.base': 'Invalid filter field name'}),
|
||||
values: Joi.array().items(Joi.alternatives().try(
|
||||
Joi.string().max(128), Joi.number(), Joi.boolean(), Joi.date().iso(), Joi.object(), null
|
||||
Joi.string().max(128).allow(''), Joi.number(), Joi.boolean(), Joi.date().iso(), Joi.object(), null
|
||||
)).min(1)
|
||||
})).default([])
|
||||
}).with('to-page', 'page-size').validate(data);
|
||||
|
Reference in New Issue
Block a user