added templates component

This commit is contained in:
VLE2FE
2020-07-27 17:52:03 +02:00
parent 15aeeb27ee
commit 55248e25ef
42 changed files with 862 additions and 57 deletions

View File

@ -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`};
}
}
}