-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SystemRule.ts
66 lines (58 loc) · 2.11 KB
/
SystemRule.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
import { QlikRepositoryClient } from "qlik-rest-api";
import { IUpdateObjectOptions } from "./types/interfaces";
import { IHttpStatus } from "./types/ranges";
import { ISystemRule, ISystemRuleUpdate } from "./types/interfaces";
import { UpdateCommonProperties } from "./util/UpdateCommonProps";
import { calculateActions, getRuleContext } from "./util/generic";
export interface IClassSystemRule {
remove(): Promise<IHttpStatus>;
update(arg: ISystemRuleUpdate): Promise<ISystemRule>;
details: ISystemRule;
}
export class SystemRule implements IClassSystemRule {
#id: string;
#repoClient: QlikRepositoryClient;
details: ISystemRule;
constructor(
repoClient: QlikRepositoryClient,
id: string,
details?: ISystemRule
) {
if (!id) throw new Error(`systemRules.get: "id" parameter is required`);
this.#id = id;
this.#repoClient = repoClient;
if (details) this.details = details;
}
async init() {
if (!this.details) {
this.details = await this.#repoClient
.Get<ISystemRule>(`systemrule/${this.#id}`)
.then((res) => res.data);
}
}
public async remove() {
return await this.#repoClient
.Delete(`systemrule/${this.#id}`)
.then((res) => res.status);
}
public async update(arg: ISystemRuleUpdate, options?: IUpdateObjectOptions) {
if (arg.name) this.details.name = arg.name;
if (arg.rule) this.details.rule = arg.rule;
if (arg.resourceFilter) this.details.resourceFilter = arg.resourceFilter;
if (arg.comment) this.details.comment = arg.comment;
if (arg.disabled) this.details.disabled = arg.disabled;
if (arg.category) this.details.category = arg.category;
if (arg.actions) this.details.actions = calculateActions(arg.actions);
if (arg.context) this.details.ruleContext = getRuleContext(arg.context);
let updateCommon = new UpdateCommonProperties(
this.#repoClient,
this.details,
arg,
options
);
this.details = await updateCommon.updateAll();
return await this.#repoClient
.Put<ISystemRule>(`systemrule/${this.details.id}`, { ...this.details })
.then((res) => res.data);
}
}