/
Item.ts
128 lines (118 loc) · 2.74 KB
/
Item.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import { QlikSaaSClient } from "qlik-rest-api";
import { Privileges, ResourceType } from "../types/types";
import { IApp } from "./Apps.interfaces";
import { ILinks } from "../types/Common";
export interface IResourceAttributeNote {
thumbnail: string;
}
export interface IResourceAttributeLink {
linkType: string;
url: string;
}
export interface IITemCollections {
createdAt: string;
creatorId: string;
description: string;
id: string;
itemCount: number;
links: {
items: {
href: string;
};
self: {
href: string;
};
};
meta: {
items: {
data: IItem[];
links: {
collection: {
href: string;
};
next: {
href: string;
};
prev: {
href: string;
};
self: {
href: string;
};
};
};
};
name: string;
tenantId: string;
type: string;
updatedAt: string;
updaterId: string;
}
// TODO: more definitions for resourceAttributes
export interface IItem {
name: string;
description: string;
resourceAttributes: IApp | IResourceAttributeNote | IResourceAttributeLink;
resourceCustomAttributes: null;
resourceUpdatedAt: string;
resourceType: ResourceType;
resourceId: string;
resourceCreatedAt: string;
id: string;
createdAt: string;
updatedAt: string;
creatorId: string;
updaterId: string;
tenantId: string;
isFavorited: boolean;
links: ILinks;
actions: Privileges[];
collectionIds: string[];
meta: {
isFavorited: boolean;
actions: Privileges[];
tags: { id: string; name: string }[];
collections: string[];
};
ownerId: string;
resourceReloadEndTime: string;
resourceReloadStatus: string;
resourceSize: {
appFile: number;
appMemory: number;
};
itemViews: {};
}
export class Item {
#id: string;
#saasClient: QlikSaaSClient;
details: IItem;
constructor(saasClient: QlikSaaSClient, id: string, details?: IItem) {
if (!id) throw new Error(`app.get: "id" parameter is required`);
this.details = details ?? ({} as IItem);
this.#id = id;
this.#saasClient = saasClient;
}
async init() {
if (!this.details || Object.keys(this.details).length == 0) {
this.details = await this.#saasClient
.Get<IItem>(`items/${this.#id}`)
.then((res) => res.data);
}
}
async remove() {
return await this.#saasClient
.Delete(`items/${this.#id}`)
.then((res) => res.status);
}
async collections() {
return await this.#saasClient
.Get<IITemCollections[]>(`items/${this.#id}/collections`)
.then((res) => res.data);
}
async publishedItems() {
return await this.#saasClient
.Get<IITemCollections[]>(`items/${this.#id}/publisheditems`)
.then((res) => res.data);
}
}