0

the problem that I am having is I am sending a csv string to my controller. Before reaching the controller I have a validator middleware however everything that is being received in the validator is an object

Validator

export class Validator implements PipeTransform {
  private errors = []
  constructor() {}
  async transform(dto: string, metaData: ArgumentMetadata): Promise<ModifyUsersDto | void> {
    console.log('DTO', dto) // {}
    return dto
  }
}

Controller

  @UsePipes(new Validator())
  @Post('/')
  async endpoint(@Body() dto: string, @Req() req: SessionRequest) {
    console.log('-->', dto) // {}
    return
  }

in Postman I am sending a raw text body with "foo" and a header of Content-Type: text/plain I've taken a look at this article which talks about doing it within the controller itself using the Request parameter of Nestjs, however, I don't see any documentation as to how to receive this Request parameter in a Validator

using the link above I've created a param decorator for the controller method, however, dto is still an object

Ctfrancia
  • 864
  • 1
  • 13
  • 27

0 Answers0