Skip to content

WebApiFilter

Niels Steenbeek edited this page Mar 24, 2020 · 5 revisions

Filter interface

The Filter interface wraps the complex, hard to read and hard to write $filter.

It uses Condition.

type FilterType = 'and' | 'or' | 'not';
export interface Filter {
    type?: FilterType;
    conditions: Condition[];
    filters?: Filter[];
}

Example simple Filter

const filters: Filter[] = [{
          conditions: [{
              attribute: 'name',
              value: 'accountName'
          }]
      }],
      nrAccounts = await AccountService.count(filters);

Example or Filter

const filters: Filter[] = [{
          type: 'or',
          conditions: [{
              attribute: 'name',
              value: 'accountName'
          }, {
              attribute: 'description',
              value: 'some description'
          }]
      }],
      nrAccounts = await AccountService.count(filters);

Example multiple Filter

const filters: Filter[] = [{
          conditions: [{
              attribute: 'name',
              value: 'accountName'
          }]
      }, {
          conditions: [{
              attribute: 'description',
              value: 'some description'
          }]
      }]
      nrAccounts = await AccountService.count(filters);

Example nested Filter

const filters: Filter[] = [{
          conditions: [{
              attribute: 'name',
              value: 'accountName'
          }],
          filters: [{
              conditions: [{
                  attribute: 'description',
                  value: 'some description'
              }]
          }]
      }],
      nrAccounts = await AccountService.count(filters);