-
-
Notifications
You must be signed in to change notification settings - Fork 68
/
Overrides.ts
47 lines (39 loc) · 1.16 KB
/
Overrides.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import ApiCall from './ApiCall'
import Collections from './Collections'
import { OverrideSchema } from './Override'
const RESOURCEPATH = '/overrides'
export interface OverrideCreateSchema {
rule: {
query: string
match: 'exact' | 'contains'
}
filter_by?: string
remove_matched_tokens?: boolean
includes?: [
{
id: string
position: number
}
]
excludes?: [{ id: string }]
}
export interface OverridesRetrieveSchema {
overrides: OverrideSchema[]
}
export default class Overrides {
constructor(private collectionName: string, private apiCall: ApiCall) {}
async upsert(overrideId: string, params: OverrideCreateSchema): Promise<OverrideSchema> {
return this.apiCall.put<OverrideSchema>(this.endpointPath(overrideId), params)
}
async retrieve(): Promise<OverridesRetrieveSchema> {
return this.apiCall.get<OverridesRetrieveSchema>(this.endpointPath())
}
private endpointPath(operation?: string): string {
return `${Collections.RESOURCEPATH}/${this.collectionName}${Overrides.RESOURCEPATH}${
operation === undefined ? '' : '/' + operation
}`
}
static get RESOURCEPATH(): string {
return RESOURCEPATH
}
}