Archived
2

added PUT /user route

This commit is contained in:
VLE2FE
2020-04-24 17:36:39 +02:00
parent a64229d1dc
commit 7a917c1f6b
5 changed files with 304 additions and 42 deletions

View File

@ -2,34 +2,62 @@ import joi from '@hapi/joi';
import globals from '../../globals';
export default class UserValidate { // validate input for user
static input (data) {
return joi.object({
name: joi.string()
.alphanum()
.lowercase()
.required(),
private static user = {
_id: joi.any(),
name: joi.string()
.alphanum()
.lowercase(),
email: joi.string()
.email({minDomainSegments: 2})
.lowercase()
.required(),
email: joi.string()
.email({minDomainSegments: 2})
.lowercase(),
pass: joi.string()
.pattern(new RegExp('^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[!"#$%&\'()*+,-.\\/:;<=>?@[\\]^_`{|}~])(?=\\S+$).{8,}$'))
.required(),
pass: joi.string()
.pattern(new RegExp('^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[!"#%&\'()*+,-.\\/:;<=>?@[\\]^_`{|}~])(?=\\S+$).{8,}$')),
level: joi.string()
.valid(...globals.levels)
.required(),
level: joi.string()
.valid(...globals.levels),
location: joi.string()
.alphanum()
.required(),
location: joi.string()
.alphanum(),
device_name: joi.string()
.allow('')
.required()
}).validate(data);
device_name: joi.string()
.allow('')
};
static input (data, param) {
if (param === 'new') {
return joi.object({
name: this.user.name.required(),
email: this.user.email.required(),
pass: this.user.pass.required(),
level: this.user.level.required(),
location: this.user.location.required(),
device_name: this.user.device_name.required()
}).validate(data);
}
else if (param === 'change') {
return joi.object({
name: this.user.name,
email: this.user.email,
pass: this.user.pass,
location: this.user.location,
device_name: this.user.device_name
}).validate(data);
}
else if (param === 'changeadmin') {
return joi.object({
name: this.user.name,
email: this.user.email,
pass: this.user.pass,
level: this.user.level,
location: this.user.location,
device_name: this.user.device_name
}).validate(data);
}
else {
return{error: 'No parameter specified!', value: {}};
}
}
static output (data) { // validate output from database for needed properties, strip everything else