Trying to validate the request through the DTO by calling the @requestBody annotation at the controller route.
Controller Method -
@httpPost('/login')
public async login(@request() req: Request, @response() res: Response, @requestBody() body: LoginDto): Promise<any> {
console.log(" ~ file: auth.controller.ts:20 ~ AuthController ~ login ~ body:", body)
return res.status(200).json(body);
}
DTO -
export interface LoginDto {
email: string;
password: string;
}
Request Body -
{
email: 'helloworld@email.com',
password: '1234',
confirm_password: '1234'
}
Expected Output -
~ file: auth.controller.ts:20 ~ AuthController ~ login ~ body: {
email: 'helloworld@email.com',
password: '1234'
}
Actual Output -
~ file: auth.controller.ts:20 ~ AuthController ~ login ~ body: {
email: 'helloworld@email.com',
password: '1234',
confirm_password: '1234'
}
The DTO is not working as expected.Not sure whats going on wrong.If anyone has experienced this before and have a solution for it, then it would be helpful. Thanks !