company.service.ts:`
async get(id: FindOneOptions<Company>): Promise<Company | null>{
console.log(id)
return await this.companyRespository.findOne(id);
}
company.controller.ts:
@Get(':id')
findOneCompany(@Param('id') id: FindOneOptions<Company>){
return this.companyService.get(id);
}
I have written the following code but whenever I try to get by FindOne my console says that "You must provide selection conditions in order to find a single row.". I tried all possible solution on the web including adding curly braces and also using other FindOptions nothing seems to make this error go away. My API platform shows an internal server error.
If it's an id I don't know why it's type is an interface. I think that's why you have vscode telling you that's an error. You should as @DinuMinhea says:
service.ts
async get(id: string | number): Promise<Company | null>{
console.log(id)
return await this.companyRespository.findOne({where: {id}});
}
company.controller.ts:
@Get(':id') findOneCompany(@Param('id') id: string | number){
return this.companyService.get(id);
}
You should use findByOne
rather than findOne
, since findOne
expects parameters such as id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With