Loopback 4 - Loop over a Model's Field object in order to turn on/off certain fields dynamically

127 Views Asked by At

I have the following need, where I need to turn off/on certain fields in the Fields filter but I have no idea how to interact with the model called Employee.

I know that I need to do a FOR loop over the Employee model but I don't know how to access the data in the model

Could someone out there, please advise? Thank You 3000!

export class Employee extends Entity {
  @property({
    type: 'string',
    id: true,
    generated: false,
    required: true,
  })
  id: string;

  @property({
    type: 'string',
    required: false,
    default: null,
  })
  prefix: string;

  @property({
    type: 'string',
    required: false,
  })
  firstName: string;

  @property({
    type: 'string',
    required: false,
    default: null,
  })
  middleName: string;

  @property({
    type: 'string',
    required: false,
  })
  lastName: string;


  constructor(data?: Partial<Employee>) {
    super(data);
  }
}

export interface EmployeeRelations {
  // describe navigational properties here
}

export type EmployeeWithRelations = Employee & EmployeeRelations;

1

There are 1 best solutions below

0
On

To exclude a property from the results you can simply set it to false in the Fields filter like this:

/users?filter={"fields":{"password":false}}

This is an example from the docs: https://loopback.io/doc/en/lb4/Fields-filter.html