/
ODAGService.ts
58 lines (49 loc) · 1.6 KB
/
ODAGService.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
import { QlikRepositoryClient } from "qlik-rest-api";
import { IODAGService, IODAGServiceUpdate } from "./types/interfaces";
export class ODAGService {
#id: string;
#repoClient: QlikRepositoryClient;
details: IODAGService;
constructor(
repoClient: QlikRepositoryClient,
id: string,
details?: IODAGService
) {
if (!id) throw new Error(`odag.get: "id" parameter is required`);
this.#id = id;
this.#repoClient = repoClient;
if (details) this.details = details;
}
async init(): Promise<IODAGService> {
if (!this.details) {
this.details = await this.#repoClient
.Get<IODAGService>(`odagservice/${this.#id}`)
.then((res) => res.data);
}
return;
}
public async remove(): Promise<number> {
return await this.#repoClient
.Delete(`odagservice/${this.#id}`)
.then((res) => res.status);
}
public async update(arg: IODAGServiceUpdate): Promise<IODAGService> {
if (arg.anonymousProxyUser && !arg.anonymousProxyUser.userId)
throw new Error(
`odag.update: "anonymousProxyUser.userId" value is missing`
);
if (arg.anonymousProxyUser && !arg.anonymousProxyUser.userDirectory)
throw new Error(
`odag.update: "anonymousProxyUser.userDirectory" value is missing`
);
return await this.#repoClient
.Put<IODAGService>(`odagservice/${this.#id}`, { settings: arg })
.then((res) => {
// update the current instance values with the values from the arguments
Object.entries(arg).map(([n, v]) => {
this.details[n] = v;
});
return res.data;
});
}
}