-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildGetAttribute.ts
More file actions
63 lines (54 loc) · 1.4 KB
/
buildGetAttribute.ts
File metadata and controls
63 lines (54 loc) · 1.4 KB
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
import Axios from "axios";
import {CommonService, GetAttributesBuilder} from "../../api/common";
import {Callback} from "../../model/models";
class GetAttributesBuilderImpl implements GetAttributesBuilder {
private id: string;
private attr: string;
private common: CommonService;
constructor(common: CommonService, id: string, attr?: string) {
this.common = common;
this.id = id;
this.attr = attr;
}
public forUser(callback?: Callback<any>) {
if (!callback) {
return;
}
this.forAttr(`/ctx/${this.id}`, callback);
}
public forGroup(callback?: Callback<any>) {
if (!callback) {
return;
}
this.forAttr(`/groups/${this.id}`, callback);
}
public forRoom(callback?: Callback<any>) {
if (!callback) {
return;
}
this.forAttr(`/rooms/${this.id}`, callback);
}
private forAttr(path: string, callback: Callback<any>) {
let url = `${this.common.options().server}${path}/attributes`;
if (this.attr) {
url += `/${this.attr}`;
}
Axios.get(url, {headers: this.common.options().headers})
.then((response) => {
return response.data as string;
})
.then((result) => {
if (callback) {
callback(null, result);
}
})
.catch((e) => {
if (callback) {
callback(e);
}
});
}
}
export {
GetAttributesBuilderImpl,
};