added templates component
This commit is contained in:
@ -121,4 +121,53 @@ export class ValidationService {
|
||||
}
|
||||
return {ok: true, error: ''};
|
||||
}
|
||||
|
||||
parameterName(data) {
|
||||
const {ignore, error} = Joi.string()
|
||||
.max(128)
|
||||
.invalid('condition_template', 'material_template')
|
||||
.pattern(/^[^.]+$/)
|
||||
.required()
|
||||
.messages({'string.pattern.base': 'name must not contain a dot'})
|
||||
.validate(data);
|
||||
if (error) {
|
||||
return {ok: false, error: error.details[0].message};
|
||||
}
|
||||
return {ok: true, error: ''};
|
||||
}
|
||||
|
||||
parameterRange(data) {
|
||||
if (data) {
|
||||
try {
|
||||
const {ignore, error} = Joi.object({
|
||||
values: Joi.array()
|
||||
.min(1),
|
||||
|
||||
min: Joi.number(),
|
||||
|
||||
max: Joi.number(),
|
||||
|
||||
type: Joi.string()
|
||||
.valid('array')
|
||||
})
|
||||
.oxor('values', 'min')
|
||||
.oxor('values', 'max')
|
||||
.oxor('type', 'values')
|
||||
.oxor('type', 'min')
|
||||
.oxor('type', 'max')
|
||||
.required()
|
||||
.validate(JSON.parse(data));
|
||||
if (error) {
|
||||
return {ok: false, error: error.details[0].message};
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
return {ok: false, error: `no valid JSON`};
|
||||
}
|
||||
return {ok: true, error: ''};
|
||||
}
|
||||
else {
|
||||
return {ok: false, error: `no valid value`};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user