File

src/common/decorators/disallowedcname.decorator.ts

Index

Methods

Constructor

constructor(configService: ConfigService)
Parameters :
Name Type Optional
configService ConfigService No

Methods

defaultMessage
defaultMessage()
Returns : any
validate
validate(value: any)
Parameters :
Name Type Optional
value any No
Returns : boolean
import {
  ValidatorConstraintInterface,
  ValidatorConstraint,
  ValidationOptions,
  registerDecorator,
} from 'class-validator';

import { ConfigService } from '@nestjs/config';
import { Injectable } from '@nestjs/common';
import { GenericRespEnum } from '../../utils/enums/responses.enum';

@ValidatorConstraint({ name: 'DisallowedCnames' })
@Injectable()
export class DisallowedCnamesRule implements ValidatorConstraintInterface {
  constructor(private readonly configService: ConfigService) {}

  validate(value: any) {
    return !this.configService.get('disallowedCnames').includes(value);
  }
  defaultMessage() {
    return GenericRespEnum.ERR_CNAME_INVALID;
  }
}

export function DisallowedCname(validationOptions?: ValidationOptions) {
  return function (object: any, propertyName: string) {
    registerDecorator({
      name: 'DisallowedCnames',
      target: object.constructor,
      propertyName: propertyName,
      options: validationOptions,
      validator: DisallowedCnamesRule,
    });
  };
}

results matching ""

    No results matching ""