Skip to content

Commit 528f55b

Browse files
committedDec 19, 2019
Add getRolePermissions method
1 parent 20a829d commit 528f55b

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
 

‎lib/group/getRolePermissions.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Includes
2+
var http = require('../util/http.js').func
3+
var getGeneralToken = require('../util/getGeneralToken.js').func
4+
5+
exports.required = ['group', 'roleId']
6+
exports.optional = ['jar']
7+
8+
function getRolePermissions (group, roleId, jar, xcsrf) {
9+
return new Promise((resolve, reject) => {
10+
var httpOpt = {
11+
url: `https://groups.roblox.com/v1/groups/${group}/roles/${roleId}/permissions`,
12+
options: {
13+
method: 'GET',
14+
resolveWithFullResponse: true,
15+
jar: jar,
16+
headers: {
17+
'X-CSRF-TOKEN': xcsrf
18+
}
19+
}
20+
}
21+
22+
return http(httpOpt)
23+
.then(function (res) {
24+
const responseData = JSON.parse(res.body)
25+
if (res.statusCode !== 200) {
26+
let error = 'An unknown error has occurred.'
27+
if (responseData && responseData.errors) {
28+
error = responseData.errors.map((e) => e.message).join('\n')
29+
}
30+
reject(new Error(error))
31+
} else {
32+
resolve(responseData)
33+
}
34+
})
35+
})
36+
}
37+
38+
// Define
39+
exports.func = function (args) {
40+
const jar = args.jar
41+
return getGeneralToken({ jar: jar })
42+
.then(function (xcsrf) {
43+
return getRolePermissions(args.group, args.roleId, jar, xcsrf)
44+
})
45+
}

0 commit comments

Comments
 (0)
Failed to load comments.