Skip to content

WebApiCondition

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

Condition interface

The condition interface wraps the complex, hard to read and hard to write $filter compare statements. It also supports the Query Functions. Read that documentation to know how to pass the value(s).

type QueryFunction = 'Above' | 'AboveOrEqual' | 'Between' | 'Contains' | 'ContainValues' | 'DoesNotContainValues' | 'EqualBusinessId' | 'EqualUserId' | 'EqualUserLanguage' | 'EqualUserOrUserHierarchy' |
    'EqualUserOrHierarchyAndTeams' | 'EqualUserOrUserTeams' | 'EqualUserTeams' | 'In' | 'InFiscalPeriod' | 'InFiscalPeriodAndYear' | 'InFiscalYear' | 'InOrAfterFiscalPeriodAndYear' |
    'InOrBeforeFiscalPeriodAndYear' | 'Last7Days' | 'LastFiscalPeriod' | 'LastFiscalYear' | 'LastMonth' | 'LastWeek' | 'LastXDays' | 'LastXFiscalPeriods' | 'LastXFiscalYears' | 'LastXHours' |
    'LastXMonths' | 'LastXWeeks' | 'LastXYears' | 'LastYear' | 'Next7Days' | 'NextFiscalPeriod' | 'NextFiscalYear' | 'NextMonth' | 'NextWeek' | 'NextXDays' | 'NextXFiscalPeriods' |
    'NextXFiscalYears' | 'NextXHourds' | 'NextXMonths' | 'NextXWeeks' | 'NextXYears' | 'NextYear' | 'NotBetween' | 'NotEqualBusinessId' | 'NotEqualUserId' | 'NotIn' | 'NotUnder' | 'OlderThanXDays' |
    'OlderThanXHours' | 'OlderThanXMinutes' | 'OlderThanXMonths' | 'OlderThanXWeeks' | 'OlderThanXYears' | 'On' | 'OnOrAfter' | 'OnOrBefore' | 'ThisFiscalPerios' | 'ThisFiscalYear' | 'ThisMonth' |
    'ThisWeek' | 'ThisYear' | 'Today' | 'Tomorrow' | 'Under' | 'UnderOrEqual' | 'Yesterday';
const filterConditions = ['eq' , 'ne', 'gt', 'ge', 'lt', 'le'] as const;
type FilterCondition = typeof filterConditions[number]; // 'eq' | 'ne' | 'gt' | 'ge' | 'lt' | 'le';
interface Condition {
    attribute: string;
    operator?: FilterCondition | QueryFunction;
    value?: any;
}

Example simple Condition

const filters: Filter[] = [{
          conditions: [{
              attribute: 'someField',
              operator: 'lt'
              value: 10
          }]
      }],
      account = await AccountService.count(filters);

Example Query Function

const filters: Filter[] = [{
          conditions: [{
              attribute: 'someField',
              operator: 'between'
              value: [10, 20]
          }]
      }],
      account = await AccountService.count(filters);
Clone this wiki locally