added model templates
This commit is contained in:
38
src/routes/validate/model.ts
Normal file
38
src/routes/validate/model.ts
Normal 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user