/
AppActions.ts
68 lines (60 loc) · 1.8 KB
/
AppActions.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
import { QlikSaaSClient } from "qlik-rest-api";
import { Reloads } from "./Reloads";
import { IReloadTaskCreate } from "./ReloadTask.interfaces";
import { ReloadTasks } from "./ReloadTasks";
import { AppObject } from "./Apps.interfaces";
export class AppActions {
#id: string;
#saasClient: QlikSaaSClient;
private reloadTasks: ReloadTasks;
private appReload: Reloads;
constructor(saasClient: QlikSaaSClient, id: string) {
this.#id = id;
this.#saasClient = saasClient;
this.reloadTasks = new ReloadTasks(this.#saasClient);
this.appReload = new Reloads(this.#saasClient);
}
/**
* Create scheduled reload task for the app
*/
async createReloadTask(arg: Omit<IReloadTaskCreate, "appId">) {
await this.reloadTasks.create({
appId: this.#id,
...arg,
});
return true;
}
/**
* Get list of all scheduled reloads for the app
*/
async getReloadTasks() {
return await this.reloadTasks
.getAll()
.then((allTasks) => allTasks.filter((r) => r.details.appId == this.#id));
}
/**
* Reloads the app
*/
async reload(arg?: { partial: boolean }) {
if (arg && !arg.partial)
throw new Error(
`app.reload: argument object is passed but "partial" property is missing`
);
return await this.appReload.start({
appId: this.#id,
partial: arg?.partial || false,
});
}
async changeObjectOwner(arg: { objectId: string; ownerId: string }) {
if (!arg.objectId)
throw new Error(
`app.changeObjectOwner: "objectId" parameter is required`
);
if (!arg.ownerId)
throw new Error(`app.changeObjectOwner: "ownerId" parameter is required`);
return this.#saasClient.Post<AppObject>(
`apps/${this.#id}/objects/${arg.objectId}/actions/change-owner`,
{ ownerId: arg.ownerId }
);
}
}