Archived
2

added model templates

This commit is contained in:
VLE2FE
2020-08-19 13:48:47 +02:00
parent 656795f02c
commit e8529c2b23
10 changed files with 560 additions and 35 deletions

View File

@ -0,0 +1,38 @@
import Joi from 'joi';
export default class ModelValidate { // validate input for model
private static model = {
group: Joi.string()
.disallow('file')
.max(128),
model: Joi.object({
name: Joi.string()
.max(128)
.required(),
url: Joi.string()
.uri()
.max(512)
.required(),
label: Joi.string()
.allow('')
.max(128)
.required()
})
};
static input (data) { // validate input
return this.model.model.required().validate(data);
}
static output (data) { // validate output and strip unwanted properties, returns null if not valid
const {value, error} = Joi.object({
group: this.model.group,
models: Joi.array().items(this.model.model)
}).validate(data, {stripUnknown: true});
return error !== undefined? null : value;
}
}