title: NESTJS Validation Pipe and CustomValidatorDecorator with Service Layer
body: <p>Hello i am recently new on NESTJS and i need help to solve this problem. the problem consist that i need on the validation pipe to have access to the token of the request to call antoher api ( with the same token ) and using the HttpModule to check if the id sent was valid or not.</p>
  
  <p>Validation Pipe ( Sample from nestjs docs): </p>
  
  <pre><code>@Injectable()
  export class ValidationPipe implements PipeTransform&lt;any&gt; {
    async transform(value, { metatype }: ArgumentMetadata) {
      if (!metatype || !this.toValidate(metatype)) {
        return value;
      }
      const object = plainToClass(metatype, value);
      const errors = await validate(object);
      if (errors.length &gt; 0) {
        throw new BadRequestException('Validation failed');
      }
      return value;
    }
  
    private toValidate(metatype): boolean {
      const types = [String, Boolean, Number, Array, Object];
      return !types.find((type) =&gt; metatype === type);
    }
  }
  </code></pre>
  
  <p>Custom Validator : </p>
  
  <pre><code>import { registerDecorator, ValidationOptions, ValidationArguments } from 'class-validator';
  
  export function IsLanguageValid(property: string, validationOptions?: ValidationOptions) {
    return function(object: Object, propertyName: string) {
      registerDecorator({
        name: 'isLanguageValid',
        target: object.constructor,
        propertyName: propertyName,
        constraints: [property],
        options: validationOptions,
        validator: {
          validate(value: any, args: ValidationArguments) {
            const [relatedPropertyName] = args.constraints;
            const relatedValue = (args.object as any)[relatedPropertyName];
  
            // WHERE HOW CAN I ACCESS TO A SERVICE AND TOKEN OF THE REQUEST
            this.httpModule.get('url to other api', { headers: { authrorization : TOKEN }})
          },
        },
      });
    };
  }
  </code></pre>
  
  <p>What is the propose of that, on the DTO i put the decorators for validation and then he calls the api automatically to check the language_id exist or not.</p>
  
  <pre><code>  @ApiModelProperty()
    @IsLanguageValid({}, { message: 'the language id sent is not valid'})
    @IsNumber({}, { message: 'the id should be a number' })
    language_id: number;
  </code></pre>