-
Notifications
You must be signed in to change notification settings - Fork 394
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
question: how to auto-transform body instance to plain in routing-controllers #1133
Comments
@ermal-abiti you can disable class transformation in either the global settings of routing-controller or per parameter basis. Please take a look at the documentation and search for class-transformer |
@attilaorosz attilaorosz useExpressServer(app, {
routePrefix: '/api',
validation: {
whitelist: true,
},
controllers: [AuthController],
defaultErrorHandler: true,
classTransformer: false,
}); But now it is not validating the body and it is not applying the DTO: export class RegisterDto {
@IsString()
username: string;
@IsString()
password: string;
} And I am sending this json request body: {
"username":"test",
"password:"test"
"name": "test"
} And the console is outputing this: Also if i remove one of the fields and i send this json for ex: |
Any solution for this ? |
Sorry for the late reply, do you happen to have a repro repo for this? I have no idea what |
@attilaorosz // index.js
...
useExpressServer(app, {
routePrefix: '/api',
validation: {
whitelist: true,
},
controllers: [AuthController],
defaultErrorHandler: true,
classTransformer: true,
});
... // auth.controller.ts
@JsonController('/auth')
@Service()
export class AuthController {
constructor(private readonly authService: AuthService) {}
@Post('/register')
@HttpCode(201)
async registerUser (@Body() body: RegisterDto) {
console.log(body)
return this.authService.register(body);
}
} The problem is at |
I have this following code:
As you can see the controller is using validation.
After I call the api endpoint, the console outputs
RegisterDto { username: 'test', password: 'test' }
.Coming from a nestjs perspective, it would automatically convert this dto instance to a plain object, and the console would output this
{ username: 'ermal1', password: 'dasd' }
.How can i achieve this using routing-controllers ?
The text was updated successfully, but these errors were encountered: