adapted /measurements to use sample_id
This commit is contained in:
@ -12,13 +12,14 @@ export default class MeasurementValidate {
|
||||
Joi.boolean(),
|
||||
Joi.array()
|
||||
)
|
||||
.allow(null)
|
||||
)
|
||||
};
|
||||
|
||||
static input (data, param) { // validate input, set param to 'new' to make all attributes required
|
||||
if (param === 'new') {
|
||||
return Joi.object({
|
||||
condition_id: IdValidate.get().required(),
|
||||
sample_id: IdValidate.get().required(),
|
||||
values: this.measurement.values.required(),
|
||||
measurement_template: IdValidate.get().required()
|
||||
}).validate(data);
|
||||
@ -37,7 +38,7 @@ export default class MeasurementValidate {
|
||||
data = IdValidate.stringify(data);
|
||||
const {value, error} = Joi.object({
|
||||
_id: IdValidate.get(),
|
||||
condition_id: IdValidate.get(),
|
||||
sample_id: IdValidate.get(),
|
||||
values: this.measurement.values,
|
||||
measurement_template: IdValidate.get()
|
||||
}).validate(data, {stripUnknown: true});
|
||||
|
@ -1,7 +1,7 @@
|
||||
import Joi from '@hapi/joi';
|
||||
|
||||
export default class ParametersValidate {
|
||||
static input (data, parameters, param) { // data to validate, parameters from template, param: 'new', 'change'
|
||||
static input (data, parameters, param) { // data to validate, parameters from template, param: 'new', 'change', 'null'(null values are allowed)
|
||||
let joiObject = {};
|
||||
parameters.forEach(parameter => {
|
||||
if (parameter.range.hasOwnProperty('values')) { // append right validation method according to parameter
|
||||
@ -39,6 +39,9 @@ export default class ParametersValidate {
|
||||
if (param === 'new') {
|
||||
joiObject[parameter.name] = joiObject[parameter.name].required()
|
||||
}
|
||||
else if (param === 'null') {
|
||||
joiObject[parameter.name] = joiObject[parameter.name].allow(null)
|
||||
}
|
||||
});
|
||||
return Joi.object(joiObject).validate(data);
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ export default class TemplateValidate {
|
||||
.min(1),
|
||||
|
||||
parameters: Joi.array()
|
||||
.min(1)
|
||||
.items(
|
||||
Joi.object({
|
||||
name: Joi.string()
|
||||
|
Reference in New Issue
Block a user