-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-group.js
More file actions
86 lines (74 loc) · 1.92 KB
/
api-group.js
File metadata and controls
86 lines (74 loc) · 1.92 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
function Group(init) {
fill(this,init,[
"id",
"label",
"count",
"audience",
"access"
]);
}
Group.prototype = Object.create({
// Create a group on the server
//
Create: function() {
var self = this;
return request("POST","groups",{},keep(this,[ "id", "label", "audience" ])).then(function(data) {
Group.call(self,data);
return self;
});
},
// List people in the group
List: function(params) {
params = params || {};
return request("GET",["groups",this.id],keep(params,[ "limit", "offset" ])).then(function(data) {
return data.list.map(Person.Cache);
});
},
// Load the group information
//
Load: function() {
var self = this;
return request("GET",["groups",this.id,"info"]).then(function(data) {
Group.call(self,data);
return self;
});
},
// Save the group information
//
Save: function() {
return request("PUT",["groups",this.id,"info"],{},keep(this,["label", "audience"]));
},
// Delete the group from the server
//
Delete: function() {
return request("DELETE",["groups",this.id]);
},
// Add a single person to this group
//
Add: function(person) {
return this.AddMany([person]);
},
// Removes a single person from this group
//
Remove: function(person) {
return this.RemoveMany([person]);
},
// Adds many people to this group
//
AddMany: function(people) {
return request("POST",["groups",this.id,"add"],{},people.map(id));
},
// Remove many people from this group
//
RemoveMany: function(people) {
return request("POST",["groups",this.id,"remove"],{},people.map(id));
},
});
// Load a list of groups from the server
//
Group.List = function(params) {
params = params || {};
return request("GET","groups",keep(params,[ "limit", "offset" ])).then(function(data) {
return data.list.map(function(init) { return new Group(init); });
});
};