-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspaces.ts
103 lines (89 loc) · 2.86 KB
/
spaces.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
import {
Block,
DataApi,
Paginated,
paginatedResponse,
Space,
SpaceExtension
} from "../interfaces";
import HttpResponse from "../response";
import HttpComponent from "./httpComponent";
class Spaces extends HttpComponent {
async getList(query: any): Promise<HttpResponse> {
const url = this.urlQuery(`${this.cli.apiUrl}/spaces`, query);
return await this.cli.get(url);
}
async orgSpaces(org_id: string, query: any): Promise<HttpResponse> {
const url = this.urlQuery(
`${this.cli.apiUrl}/orgs/${org_id}/spaces`,
query
);
return await this.cli.get(url);
}
async get(space_id: string): Promise<Space> {
const url = `${this.cli.apiUrl}/spaces/${space_id}`;
const response = await this.cli.get(url);
return response.data as Space;
}
async create(org_id: string, body: Record<string, any>): Promise<Space> {
const url = `${this.cli.apiUrl}/orgs/${org_id}/spaces`;
const response = await this.cli.post(url, {
body,
});
return response.data as Space;
}
async update(space_id: string, body: Record<string, any>): Promise<Space> {
const url = `${this.cli.apiUrl}/spaces/${space_id}`;
const response = await this.cli.patch(url, {
body,
});
return response.data as Space;
}
async delete(space_id: string): Promise<void> {
const url = `${this.cli.apiUrl}/spaces/${space_id}`;
await this.cli.delete(url);
}
async getBlocks(space_id: string, query?: any): Promise<Paginated<Block>> {
const url = this.urlQuery(
`${this.cli.apiUrl}/spaces/${space_id}/services`,
query
);
const response = await this.cli.get(url);
return paginatedResponse<Block>(response);
}
loader(query?: any): DataApi<Space> {
return this.cli.loader(`${this.cli.apiUrl}/spaces`, query);
}
blocksLoader(space_id: string): DataApi<Block> {
return this.cli.loader(`${this.cli.apiUrl}/spaces/${space_id}/services`);
}
extensionsLoader(space_id: string): DataApi<SpaceExtension> {
return this.cli.loader(`${this.cli.apiUrl}/spaces/${space_id}/extensions`);
}
async getExtensions(
space_id: string,
query?: any
): Promise<Paginated<SpaceExtension>> {
const url = this.urlQuery(
`${this.cli.apiUrl}/spaces/${space_id}/extensions`,
query
);
const response = await this.cli.get(url);
return paginatedResponse<SpaceExtension>(response);
}
async updateExtension(space_id: string, body: any): Promise<SpaceExtension> {
const url = `${this.cli.apiUrl}/spaces/${space_id}/extensions`;
const response = await this.cli.post(url, {
body,
});
return response.data as SpaceExtension;
}
async removeExtension(
space_id: string,
extension_name: string
): Promise<void> {
const url = `${this.cli.apiUrl}/spaces/${space_id}/extensions/${extension_name}`;
await this.cli.delete(url);
}
}
export default Spaces;