skip to Main Content

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.

3

Answers


  1. Try to specify the Entity field that you’re searching by. In your case this is the id.

    company.service.ts

    ...
    async get(id: string | number): Promise<Company | null>{    
        console.log(id)
        return await this.companyRespository.findOne({ id });
    }
    
    Login or Signup to reply.
  2. async get(id: FindOneOptions<Company>): Promise<Company | null>{    
    console.log(id)
    return await this.companyRespository.findOne({id: id});
    }
    
    Login or Signup to reply.
  3. 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); 
      }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search