-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgroups.js
82 lines (73 loc) · 2.23 KB
/
groups.js
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
request = require('./lib/request');
class Groups {
constructor(hostname, token) {
this.hostname = hostname;
this.token = token;
this._request = request;
}
/**
* Get Groups
*/
getGroups() {
return this._request('GET', `groups`);
}
/**
* Get Group
* @param {String} groupId
*/
getGroup(groupId) {
return this._request('GET', `groups/id:${groupId}`);
}
/**
* Add User To Group
* @param obj The insertion object.
* @param obj.name The name of the group.
* @param obj.description The Description of the group.
* @param obj.key group code.
* @param obj.price group price
* @param ob.creator_id creator id
*/
createGroup(obj) {
if (!obj.name || !obj.description || !obj.key) {
throw new Error('Group has to have name and description and code');
}
return this._request('POST', `creategroup`, obj);
}
/**
* Delete a Group
* @param obj The insertion object.
* @param obj.group_id The name of the group.
* @param obj.deleted_by_user_id Deleted by user id.
*/
deleteGroup(obj) {
if (!obj.group_id || !obj.deleted_by_user_id) {
throw new Error('For deleting group object has to have group_id and deleted_by_user_id');
}
return this._request('POST', `deletegroup`, obj);
}
/**
* Add User To Group
* @param userId The id of the user object.
* @param groupKey The key of the group.
*/
addUserToGroup(userId, groupKey) {
return this._request('GET', `addusertogroup/user_id:${userId},group_key:${groupKey}`);
}
/**
* Remove User From Group
* @param groupId The id of the group.
* @param userId The id of the user.
*/
removeUserFromGroup(groupId, userId) {
return this._request('GET', `removeuserfromgroup/user_id:${userId},group_id:${groupId}`);
}
/**
* Add Course To Group
* @param groupId The id of the group.
* @param courseId The id of the course.
*/
addCourseToGroup(groupId, courseId) {
return this._request('GET', `addcoursetogroup/course_id:${courseId},group_id:${groupId}`);
}
}
module.exports = Groups;