All files / app/validators group-validators.ts

100% Statements 4/4
100% Branches 0/0
100% Functions 2/2
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40  1x                   1x         2x                           2x                  
import {ValidationChain} from 'express-validator';
import {ValidatorsImpl, Validators} from 'express-validator/src/chain';
 
export interface GroupValidators extends Validators<ValidationChain> {
  isGroupName(): ValidationChain;
  isGroupDescription(): ValidationChain;
}
 
/**
 * Class for additional validators related to groups.
 */
export class GroupValidatorsImpl extends ValidatorsImpl<ValidationChain> {
  /**
   * Check if group name.
   */
  isGroupName(): ValidationChain {
    return this
        .isString()
        .withMessage('Name has to be a string')
        .notEmpty()
        .withMessage('Name has to be a non empty string')
        // Sanitize name
        .trim()
        .escape();
  }
 
  /**
   * Check if group description
   */
  isGroupDescription(): ValidationChain {
    return this
        // But if it exists it has to be a non-empty string
        .isString()
        .withMessage('Description has to be a string')
        // Sanitize description
        .trim()
        .escape();
  }
}