I am trying to write a function to handle the Get request, here is my code:
@Get('/find')
async find(@Param() testname: NameDto) {
console.log(testname.name);
}
Here is my dto:
export class NameDto {
@IsString()
@ApiProperty({ required: true })
name: string;
}
I am using the Swagger to test this API :
When I input a signle a , I got the following response:
{
"statusCode": 400,
"message": [
"name must be a string"
],
"error": "Bad Request"
}
here are more input example :
They all return the same response.
Then, I change the find function like this with @Query:
@Get('/find')
async find(@Query() testname: NameDto) {
console.log(testname.name);
}
here is my input :
I can have the 200-ok response.
Here is another example:
I enter 1 as the input, and I still can get the 200 response. The dto is not working as expected.
Am I missing something? Any help would be appreciate.