Home > Net >  NestJS changing param names received in post request
NestJS changing param names received in post request

Time:01-06

My goal is for an endpoint to receive firstName in the JSON request and save first_name in my DB.

I created a dto outlining the params I want to receive for the endpoint like so:

@IsNotEmpty()
@Expose({ name: 'firstName' })
first_name: string;

vscode intellisense snip

vscode even picks up that the prop name should be first_name.

However when I console.log it I receive this: (firstName instead of first_name)

{
  email: '[email protected]',
  password: 'test',
  firstName: 'first',
  lastName: 'last'
}

(My DB entity also has the field set up as first_name and it's throwing an error)

CodePudding user response:

The validation pipe's transform: true option needs to be set so that the pipe returns the class instance rather than just the validated json

  • Related