Hi,
I'm new to nestjs and I am trying to make params validation for uuid.
I should do some conversion between the step of validation and usage of my uuid here ?
For now, I cannot use the id because find() operator doesn't accept my UserIdParams Object which is a string
Error message
Type 'UserIdParams' is not assignable to type 'string | FindOperator<string>'.
users.dto.ts
export class UserIdParams {
@IsNotEmpty()
@IsUUID()
readonly id: string;
}
users.controller.ts
@Get(':id')
@UsePipes(new ValidationPipe({ transform: true }))
async findById(@Param('id') id: UserIdParams): Promise<User> {
return this.userService.findById(id);
}
users.service.ts
async findById(id: UserIdParams): Promise<User> {
const user = await this.usersRepository.findOneBy({ id }); // <-------- Error Here
if (!user) {
response.statusCode = HttpStatus.BAD_REQUEST;
throw new HttpException({ message: 'User not found' }, HttpStatus.BAD_REQUEST);
}
try {
return user;
} catch (error) {
throw new HttpException({ message: 'Error finding user' }, HttpStatus.INTERNAL_SERVER_ERROR);
}
}