/
CollectionItem.ts
92 lines (87 loc) · 1.93 KB
/
CollectionItem.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
90
91
92
import { QlikSaaSClient } from "qlik-rest-api";
export interface ICollectionItem {
actions: [];
collectionIds: string[];
createdAt: string;
creatorId: string;
description: string;
id: string;
isFavorited: true;
links: {
collections: {
href: string;
};
open: {
href: string;
};
self: {
href: string;
};
thumbnail: {
href: string;
};
};
meta: {
actions: [];
collections: {
id: string;
name: string;
}[];
isFavorited: boolean;
tags: {
id: string;
name: string;
}[];
};
ownerId: string;
name: string;
resourceAttributes: {};
resourceCreatedAt: string;
resourceCustomAttributes: {};
resourceId: string;
resourceLink: string;
resourceReloadEndTime: string;
resourceReloadStatus: string;
resourceSize: {
appFile: number;
appMemory: number;
};
resourceSubType: string;
resourceType: string;
resourceUpdatedAt: string;
spaceId: string;
tenantId: string;
thumbnailId: string;
updatedAt: string;
updaterId: string;
}
export class CollectionItem {
#id: string;
#saasClient: QlikSaaSClient;
details: ICollectionItem;
collectionId: string;
constructor(
saasClient: QlikSaaSClient,
id: string,
collectionId: string,
details?: ICollectionItem
) {
if (!id) throw new Error(`collectionItems.get: "id" parameter is required`);
this.details = details ?? ({} as ICollectionItem);
this.#id = id;
this.collectionId = collectionId;
this.#saasClient = saasClient;
}
async init() {
if (!this.details || Object.keys(this.details).length == 0) {
this.details = await this.#saasClient
.Get<ICollectionItem>(`collections/${this.#id}/items/${this.#id}`)
.then((res) => res.data);
}
}
async remove() {
return await this.#saasClient
.Delete(`collections/${this.collectionId}/items/${this.#id}`)
.then((res) => res.status);
}
}