#Pass data to snake case, but leave camel case in DTO

3 messages · Page 1 of 1 (latest)

worn abyss
#

I want to pass data to snake case, but leave camel case in DTO.
What is the correct way to implement this in Nest.js?
For example:

sending:

{
"last_name": "foo"
}

DTO:
export class CreateUserDto {
lastName
}

thin lance
#

All you need to do for this is make sure that in your ValidationPipe options you specify "transform: true" then add a @Expose() decorator on the property for example on lastName and pass an options object saying {name: 'last_name'}
This basically tells it to map the property last_name of the plain object to the property lastName of the DTO instance