code improvements

This commit is contained in:
VLE2FE
2020-09-03 15:51:53 +02:00
parent 1440e9a6fc
commit c38d0be457
73 changed files with 276 additions and 1686 deletions

View File

@ -63,7 +63,7 @@ export class ValidationService {
return {ok: true, error: ''};
}
stringOf(data, list) {
stringOf(data, list) { // string must be in list
const {ignore, error} = Joi.string().allow('').valid(...list.map(e => e.toString())).validate(data);
if (error) {
return {ok: false, error: 'must be one of ' + list.join(', ')};
@ -71,7 +71,7 @@ export class ValidationService {
return {ok: true, error: ''};
}
stringNin(data, list) {
stringNin(data, list) { // string must not be in list
const {ignore, error} = Joi.string().invalid(...list).validate(data);
if (error) {
return {ok: false, error: 'value not allowed'};
@ -79,7 +79,7 @@ export class ValidationService {
return {ok: true, error: ''};
}
stringLength(data, length) {
stringLength(data, length) { // string with maximum length
const {ignore, error} = Joi.string().max(length).allow('').validate(data);
if (error) {
return {ok: false, error: 'must contain max ' + length + ' characters'};
@ -87,7 +87,7 @@ export class ValidationService {
return {ok: true, error: ''};
}
minMax(data, min, max) {
minMax(data, min, max) { // number between min and max
const {ignore, error} = Joi.number().allow('').min(min).max(max).validate(data);
if (error) {
return {ok: false, error: `must be between ${min} and ${max}`};
@ -95,7 +95,7 @@ export class ValidationService {
return {ok: true, error: ''};
}
min(data, min) {
min(data, min) { // number above min
const {ignore, error} = Joi.number().allow('').min(min).validate(data);
if (error) {
return {ok: false, error: `must not be below ${min}`};
@ -103,7 +103,7 @@ export class ValidationService {
return {ok: true, error: ''};
}
max(data, max) {
max(data, max) { // number below max
const {ignore, error} = Joi.number().allow('').max(max).validate(data);
if (error) {
return {ok: false, error: `must not be above ${max}`};