Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create i ValidationPipe Middleware in nestjs #471

Open
AvishayIDF opened this issue Apr 6, 2024 · 0 comments
Open

Create i ValidationPipe Middleware in nestjs #471

AvishayIDF opened this issue Apr 6, 2024 · 0 comments

Comments

@AvishayIDF
Copy link

i have this ValidatorPipe that should be the same as ValidationPipe in my nestjs server:

@Injectable()
export class ValidatorPipe extends ValidationPipe implements PipeTransform<any> {
  constructor(private defaultValidatorOptions?: ValidationPipeOptions) {
    super(defaultValidatorOptions)
  }

  async transform(value: any, metadata: ArgumentMetadata) {
    const extraValidatorOptions = this.getExtraValidatorOptions(value, metadata)
    this.validatorOptions = { ...this.defaultValidatorOptions, ...extraValidatorOptions }

    // Continue with the standard validation afterwards
    return super.transform(value, metadata)
  }

  protected getExtraValidatorOptions(value: any, metadata: ArgumentMetadata): ValidationPipeOptions {
    // code that should check for extra validation options...
  }
}

I'm looking for a way to get from the request some metadata, that i can use to choose the right validation options for the call that entered the server.

i have try to send metadata.data for the request, but, i cant get anything... it always was undefined..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant