Merge branch '13702-contents-api-service'
[arvados.git] / src / common / api / filter-builder.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 export enum FilterField {
6     UUID = "uuid",
7     OWNER_UUID = "owner_uuid"
8 }
9
10 export default class FilterBuilder {
11     private filters = "";
12
13     private addCondition(field: FilterField, cond: string, value?: string, prefix: string = "", postfix: string = "") {
14         if (value) {
15             this.filters += `["${field}","${cond}","${prefix}${value}${postfix}"]`;
16         }
17         return this;
18     }
19
20     public addEqual(field: FilterField, value?: string) {
21         return this.addCondition(field, "=", value);
22     }
23
24     public addLike(field: FilterField, value?: string) {
25         return this.addCondition(field, "like", value, "", "%");
26     }
27
28     public addILike(field: FilterField, value?: string) {
29         return this.addCondition(field, "ilike", value, "", "%");
30     }
31
32     public get() {
33         return "[" + this.filters + "]";
34     }
35 }