Skip to content

Commit c75bd83

Browse files
committed
Fix: Communities service was broken during spawn of the library
1 parent d96d672 commit c75bd83

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .",
3232
"test": "npm run lint && npm run jest"
3333
},
34-
"version": "0.3.3",
34+
"version": "0.3.4",
3535
"dependencies": {
3636
"auth0-js": "^6.8.4",
3737
"isomorphic-fetch": "^2.2.1",

src/services/communities.js

+24-14
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,21 @@
22
* @module "services.communities"
33
* @desc Communities service.
44
*/
5+
import _ from 'lodash';
56
import fetch from 'isomorphic-fetch';
67
import qs from 'qs';
78
import { config } from 'topcoder-react-utils';
89

10+
/**
11+
* Returns Community App URL, or throws an error if URL cannot be found in
12+
* config.
13+
*/
14+
function getCommunityAppUrl() {
15+
const url = _.get(config, 'URL.COMMUNITY_APP');
16+
if (!url) throw new Error('No URL.COMMUNITY_APP param found in config');
17+
return url;
18+
}
19+
920
/**
1021
* Client-side version of the service.
1122
*/
@@ -24,33 +35,32 @@ class Communities {
2435
* @return {Promise} Resolves to the array of community data objects. Each of
2536
* the objects indludes only the most important data on the community.
2637
*/
27-
getList(userGroupIds) {
28-
let url = `/community-app-assets/api/tc-communities?${qs.stringify({ groups: userGroupIds })}`;
29-
if (config.URL && config.URL.COMMUNITY_APP) {
30-
url = `${config.URL.COMMUNITY_APP}url`;
31-
}
32-
return fetch(url, {
38+
async getList(userGroupIds) {
39+
let url = getCommunityAppUrl();
40+
url += '/community-app-assets/api/tc-communities?';
41+
url += qs.stringify({ groups: userGroupIds });
42+
const res = await fetch(url, {
3343
headers: {
3444
authorization: this.private.tokenV3,
3545
},
36-
}).then(res => res.json());
46+
});
47+
return res.json();
3748
}
3849

3950
/**
4051
* Gets metadata for the specified community.
4152
* @param {String} communityId
4253
* @return {Promise} Resolves to the community metadata.
4354
*/
44-
getMetadata(communityId) {
45-
let url = `/community-app-assets/api/tc-communities/${communityId}/meta`;
46-
if (config.URL && config.URL.COMMUNITY_APP) {
47-
url = `${config.URL.COMMUNITY_APP}url`;
48-
}
49-
return fetch(url, {
55+
async getMetadata(communityId) {
56+
let url = getCommunityAppUrl();
57+
url += `/community-app-assets/api/tc-communities/${communityId}/meta`;
58+
const res = await fetch(url, {
5059
headers: {
5160
authorization: this.private.tokenV3,
5261
},
53-
}).then(res => res.json());
62+
});
63+
return res.json();
5464
}
5565
}
5666

0 commit comments

Comments
 (0)