-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbranches.js
79 lines (70 loc) · 2.23 KB
/
branches.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
request = require('./lib/request');
class Branches {
constructor(hostname, token) {
this.hostname = hostname;
this.token = token;
this._request = request;
}
/**
* Get Branches
*/
getBranches() {
return this._request('GET', `branches`);
}
/**
* Get Branch
* @param {String} branchId the id of the wanted branch
*/
getBranch(branchId) {
return this._request('GET', `branches/id:${branchId}`);
}
/**
* Create Branch
* @param obj The insertion object.
* @param obj.name The name of the branch.
* @param obj.description The Description of the branch.
*/
createBranch(obj) {
if(!obj.name || !obj.description) {
throw new Error('Branch has to have name and description');
}
return this._request('POST', `createbranch`, obj);
}
/**
* Delete Branch
* @param obj The object.
* @param obj.branch_id The id of the branch.
* @param obj.deleted_by_user_id Deleted by user id.
*/
deleteBranch(obj) {
if(!obj.branch_id || !obj.deleted_by_user_id) {
throw new Error('To delete a branch branch_id and deleted_by_user_id are requied');
}
return this._request('POST', `createbranch`, obj);
}
/**
* Change the status (active or inactive) of a branch
* @param {String} branchId the id of the wanted branch
* @param {String} status [active, inactive]
*/
branchSetStatus(branchId, status) {
return this._request('GET', `branchsetstatus/branch_id:${branchId},status:${status}`);
}
/**
* Add a user to a branch
* @param {String} branchId the id of the wanted branch
* @param {String} userId id of the user
*/
addUsertoBranch(branchId, userId) {
return this._request('GET', `addusertobranch/user_id:${userId},branch_id:${branchId}`);
}
/**
* Add a course to a branch
* @param {String} branchId the id of the wanted branch
* @param {String} courseId id of the course
*/
addCoursetoBranch(branchId, courseId) {
return this._request('GET', `addcoursetobranch/course_id:${courseId},branch_id:${branchId}`);
}
}
module.exports = Branches;