Skip to content

Commit 21f79ca

Browse files
authored
Merge pull request #373 from topcoder-platform/hot-fix-listChallengesByMember
paginate through the results when fetching members challenges
2 parents 9501599 + d2476e5 commit 21f79ca

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/common/helper.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -687,9 +687,28 @@ function calculateChallengeEndDate (challenge, data) {
687687
*/
688688
async function listChallengesByMember (memberId) {
689689
const token = await getM2MToken()
690-
const url = `${config.RESOURCES_API_URL}/${memberId}/challenges?perPage=10000`
691-
const res = await axios.get(url, { headers: { Authorization: `Bearer ${token}` } })
692-
return res.data || []
690+
let allIds = []
691+
// get search is paginated, we need to get all pages' data
692+
let page = 1
693+
while (true) {
694+
const result = await axios.get(`${config.RESOURCES_API_URL}/${memberId}/challenges`, {
695+
headers: { Authorization: `Bearer ${token}` },
696+
params: {
697+
page,
698+
perPage: 10000
699+
}
700+
})
701+
const ids = result.data || []
702+
if (ids.length === 0) {
703+
break
704+
}
705+
allIds = allIds.concat(ids)
706+
page += 1
707+
if (result.headers['x-total-pages'] && page > Number(result.headers['x-total-pages'])) {
708+
break
709+
}
710+
}
711+
return allIds
693712
}
694713

695714
/**

0 commit comments

Comments
 (0)