Skip to content

Filtering

github-actions edited this page Nov 30, 2023 · 2 revisions

Sorting

The sorting options for the API. Are defined using the following format:

const sortBy = "<field>:<order>";

Or:

const sortBy = {
  order: "<order>",
  field: "<field>",
};

Where <field> is the field to sort by and <order> is the order to sort in. It can also be an array of the above formats.

Examples

// Simplest form
const sortBy = "<field>:ASC";
const sortBy = "<field>:DESC";
// Multiple fields
const sortBy = ["<field1>:ASC", "<field2>:DESC"];
// Object form
const sortBy = {
  order: "ASC",
  field: "<field>",
};
// Multiple fields in object form
const sortBy = [
  {
    order: "ASC",
    field: "<field1>",
  },
  {
    order: "DESC",
    field: "<field2>",
  },
];

Filtering

Contains

Filtering a field which is a list of strings can be done using the contains filter. It is defined using the following format:

const contains = "<value>";

Or if all field values must be contained:

const contains = {
  all: ["<value1>", "<value2>"],
};

Or if any field value must be contained:

const contains = {
  some: ["<value1>", "<value2>"],
};

Where <value> is the value to filter by.

Date

Filtering a field which is a date can be done using the date filter. It is defined using the following format:

const date = {
  from?: "<date>",
  to?: "<date>"
};

Where <date> is the date to filter by.

Examples

// Between two dates
const filter = {
  date: {
    from: "2019-01-01",
    to: "2019-12-31",
  },
};
// After a date
const filter = {
  date: {
    from: "2019-01-01",
  },
};
// Before a date
const filter = {
  date: {
    to: "2019-12-31",
  },
};