number prefixes are now not allowed to contain numbers
This commit is contained in:
		@@ -1,35 +1,36 @@
 | 
			
		||||
import joi from '@hapi/joi';
 | 
			
		||||
import Joi from '@hapi/joi';
 | 
			
		||||
import IdValidate from './id';
 | 
			
		||||
 | 
			
		||||
export default class TemplateValidate {
 | 
			
		||||
  private static template = {
 | 
			
		||||
    name: joi.string()
 | 
			
		||||
    name: Joi.string()
 | 
			
		||||
      .max(128),
 | 
			
		||||
 | 
			
		||||
    version: joi.number()
 | 
			
		||||
    version: Joi.number()
 | 
			
		||||
      .min(1),
 | 
			
		||||
 | 
			
		||||
    number_prefix: joi.string()
 | 
			
		||||
    number_prefix: Joi.string()
 | 
			
		||||
      .pattern(/^[a-zA-Z]+$/)
 | 
			
		||||
      .min(1)
 | 
			
		||||
      .max(16),
 | 
			
		||||
 | 
			
		||||
    parameters: joi.array()
 | 
			
		||||
    parameters: Joi.array()
 | 
			
		||||
      .min(1)
 | 
			
		||||
      .items(
 | 
			
		||||
        joi.object({
 | 
			
		||||
          name: joi.string()
 | 
			
		||||
        Joi.object({
 | 
			
		||||
          name: Joi.string()
 | 
			
		||||
            .max(128)
 | 
			
		||||
            .required(),
 | 
			
		||||
 | 
			
		||||
          range: joi.object({
 | 
			
		||||
            values: joi.array()
 | 
			
		||||
          range: Joi.object({
 | 
			
		||||
            values: Joi.array()
 | 
			
		||||
              .min(1),
 | 
			
		||||
 | 
			
		||||
            min: joi.number(),
 | 
			
		||||
            min: Joi.number(),
 | 
			
		||||
 | 
			
		||||
            max: joi.number(),
 | 
			
		||||
            max: Joi.number(),
 | 
			
		||||
 | 
			
		||||
            type: joi.string()
 | 
			
		||||
            type: Joi.string()
 | 
			
		||||
              .valid('array')
 | 
			
		||||
          })
 | 
			
		||||
            .oxor('values', 'min')
 | 
			
		||||
@@ -45,14 +46,14 @@ export default class TemplateValidate {
 | 
			
		||||
  static input (data, param, template) {  // validate data, param: new(everything required)/change(available attributes are validated)
 | 
			
		||||
    if (param === 'new') {
 | 
			
		||||
      if (template === 'treatment') {
 | 
			
		||||
        return joi.object({
 | 
			
		||||
        return Joi.object({
 | 
			
		||||
          name: this.template.name.required(),
 | 
			
		||||
          number_prefix: this.template.number_prefix.required(),
 | 
			
		||||
          parameters: this.template.parameters.required()
 | 
			
		||||
        }).validate(data);
 | 
			
		||||
      }
 | 
			
		||||
      else {
 | 
			
		||||
        return joi.object({
 | 
			
		||||
        return Joi.object({
 | 
			
		||||
          name: this.template.name.required(),
 | 
			
		||||
          parameters: this.template.parameters.required()
 | 
			
		||||
        }).validate(data);
 | 
			
		||||
@@ -60,14 +61,14 @@ export default class TemplateValidate {
 | 
			
		||||
    }
 | 
			
		||||
    else if (param === 'change') {
 | 
			
		||||
      if (template === 'treatment') {
 | 
			
		||||
        return joi.object({
 | 
			
		||||
        return Joi.object({
 | 
			
		||||
          name: this.template.name,
 | 
			
		||||
          number_prefix: this.template.number_prefix,
 | 
			
		||||
          parameters: this.template.parameters
 | 
			
		||||
        }).validate(data);
 | 
			
		||||
      }
 | 
			
		||||
      else {
 | 
			
		||||
        return joi.object({
 | 
			
		||||
        return Joi.object({
 | 
			
		||||
          name: this.template.name,
 | 
			
		||||
          parameters: this.template.parameters
 | 
			
		||||
        }).validate(data);
 | 
			
		||||
@@ -98,7 +99,7 @@ export default class TemplateValidate {
 | 
			
		||||
        parameters: this.template.parameters
 | 
			
		||||
      };
 | 
			
		||||
    }
 | 
			
		||||
    const {value, error} = joi.object(joiObject).validate(data, {stripUnknown: true});
 | 
			
		||||
    const {value, error} = Joi.object(joiObject).validate(data, {stripUnknown: true});
 | 
			
		||||
    return error !== undefined? null : value;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user