-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildRoom.ts
More file actions
68 lines (60 loc) · 1.62 KB
/
buildRoom.ts
File metadata and controls
68 lines (60 loc) · 1.62 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
64
65
66
67
68
import {Admin, RoomBuilder} from "../../api/admin";
import {Callback} from "../../model/models";
import Axios from "axios";
class RoomBuilderImpl implements RoomBuilder {
private admin: Admin;
private attributes: { [key: string]: any };
private appends: string[];
constructor(admin: Admin) {
this.admin = admin;
this.attributes = {};
this.appends = [];
}
public members(first: string, ...others: string[]): RoomBuilder {
this.appends.push(first);
if (others) {
for (const s of others) {
this.appends.push(s);
}
}
return this;
}
public attribute(key: string, value: any): RoomBuilder {
this.attributes[key] = value;
return this;
}
public ok(callback?: Callback<string>): Admin {
const op = this.admin.options();
const url = `${op.server}/rooms`;
const body = {
members: this.appends,
};
const config = {headers: op.headers};
Axios.post(url, JSON.stringify(body), config)
.then((response) => {
return response.data as string;
})
.then((roomid) => {
const url2 = `${op.server}/rooms/${roomid}/attributes`;
const postData = JSON.stringify(this.attributes);
return Axios.post(url2, postData, {headers: op.headers})
.then((ignore) => {
return roomid;
});
})
.then((roomid) => {
if (callback) {
callback(null, roomid);
}
})
.catch((e) => {
if (callback) {
callback(e);
}
});
return this.admin;
}
}
export {
RoomBuilderImpl,
};