Archived
2

added user status and prediction user

This commit is contained in:
VLE2FE
2020-08-26 19:37:36 +02:00
parent efbf73032d
commit 597a8f3084
21 changed files with 477 additions and 80 deletions

View File

@ -1,4 +1,5 @@
import Joi from 'joi';
import IdValidate from './id';
export default class ModelValidate { // validate input for model
@ -29,9 +30,10 @@ export default class ModelValidate { // validate input for model
}
static output (data) { // validate output and strip unwanted properties, returns null if not valid
data = IdValidate.stringify(data);
const {value, error} = Joi.object({
group: this.model.group,
models: Joi.array().items(this.model.model)
models: Joi.array().items(this.model.model.append({_id: IdValidate.get()}))
}).validate(data, {stripUnknown: true});
return error !== undefined? null : value;
}

View File

@ -31,7 +31,13 @@ export default class UserValidate { // validate input for user
.items(Joi.string()
.allow('')
.max(128)
)
),
models: Joi.array()
.items(IdValidate.get()),
status: Joi.string()
.valid(...Object.values(globals.status))
};
private static specialUsernames: string[] = ['admin', 'user', 'key', 'new', 'passreset']; // names a user cannot take
@ -44,7 +50,8 @@ export default class UserValidate { // validate input for user
pass: this.user.pass.required(),
level: this.user.level.required(),
location: this.user.location.required(),
devices: this.user.devices.required()
devices: this.user.devices.required(),
models: this.user.models.required()
}).validate(data);
}
else if (param === 'change') {
@ -63,7 +70,8 @@ export default class UserValidate { // validate input for user
pass: this.user.pass,
level: this.user.level,
location: this.user.location,
devices: this.user.devices
devices: this.user.devices,
models: this.user.models
}).validate(data);
}
else {
@ -71,16 +79,21 @@ export default class UserValidate { // validate input for user
}
}
static output (data) { // validate output and strip unwanted properties, returns null if not valid
static output (data, param = '') { // validate output and strip unwanted properties, returns null if not valid
data = IdValidate.stringify(data);
const {value, error} = Joi.object({
const validate: {[key: string]: object} = {
_id: IdValidate.get(),
name: this.user.name,
email: this.user.email,
level: this.user.level,
location: this.user.location,
devices: this.user.devices
}).validate(data, {stripUnknown: true});
devices: this.user.devices,
models: this.user.models
}
if (param === 'admin') {
validate.status = this.user.status;
}
const {value, error} = Joi.object(validate).validate(data, {stripUnknown: true});
return error !== undefined? null : value;
}