Skip to content

question: how to auto-transform body instance to plain in routing-controllers #1133

Open
@ermal-abiti

Description

@ermal-abiti

I have this following code:

@JsonController('/auth')
@Service()
export class AuthController {
    constructor(private readonly authService: AuthService) {}

    @Post('/register')
    @HttpCode(201)
    @Serialize(UserDto)
    async registerUser (@Body() body: RegisterDto) {
        console.log(body)
        return this.authService.register(body.toJson());
    }
}

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 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: questionQuestions about the usage of the library.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions