/
Condition.ts
89 lines (80 loc) · 1.94 KB
/
Condition.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { QlikSaaSClient } from "qlik-rest-api";
export interface IConditionInternalBase {
created: string;
createdById: string;
description: string;
id: string;
ownerId: string;
tenantId: string;
appId: string;
bookmarkId: string;
type: "compound" | "data";
updated: string;
lastReloadTime: string;
}
export interface IConditionBase {
type: "compound" | "data";
}
export interface IConditionData extends IConditionBase {
compoundCondition: never;
dataCondition: {
conditionBase: IConditionInternalBase;
conditionData: {};
history: {
enabled: boolean;
};
selections: {
field: string;
count: number;
selectedSummary: string[];
}[];
dimensions: {
qLibraryId: string;
field: string;
title: string;
}[];
headers: [];
measures: {
qLibraryId: string;
qNumFormat: {};
title: string;
}[];
};
}
export interface IConditionComposite extends IConditionBase {
dataCondition: never;
compoundCondition: {
conditionBase: IConditionInternalBase;
data: {
history: {
enabled: boolean;
};
conditions: string[];
expression: string;
};
};
}
export type ICondition = IConditionData | IConditionComposite;
export class Condition {
#id: string;
#saasClient: QlikSaaSClient;
details: ICondition;
constructor(saasClient: QlikSaaSClient, id: string, details?: ICondition) {
if (!id) throw new Error(`conditions.get: "id" parameter is required`);
this.details = details ?? ({} as ICondition);
this.#id = id;
this.#saasClient = saasClient;
}
async init() {
if (!this.details || Object.keys(this.details).length == 0) {
this.details = await this.#saasClient
.Get<ICondition>(`conditions/${this.#id}`)
.then((res) => res.data);
}
}
async remove() {
return await this.#saasClient
.Delete(`conditions/${this.#id}`)
.then((res) => res.status);
}
}