0

Lets say I have the following two models in Loopback4 (Typescript):

The RiskManagerDTO Model

 // RiskManagerDTO

  // id?: string;
  // name: string;
  // risks: Risk[];

I have the other model which is similiar:


  // RiskManager
  // id?: string;
  // name: string;
  // riskIds: string[];

In the input of a controllers method I have the following clause : Where

Using the RiskManagerDTO I can arrive at RiskManager. I tried to do the following:

  async count(where?: Where<RiskManagerDTO>) {
    const whereProfile: Where<RiskManager> = {
      id: where.id,
      name: where.name,
      riskIds: where.risks.map(risk=> risk.id),
    };
    return this.riskManagerRepository.count(whereProfile);
  }

The errors happen because it tells me id,name and alerts do not exist. Note that the riskManagerRepository requires a RiskManager type, that's why I need the conversion. I see that the errors might pop up because of nullity but I could not find a solution to it.

I tried to use ? for each property but does not solve the problem.

rodonal
  • 3
  • 3

0 Answers0