challenge-api
challenge-api copied to clipboard
Challenge phases not working properly
There is one phase in timeline template doesn't exist in all challenge phases (https://api.topcoder-dev.com/v5/challenge-phases):
{
"phaseId": "6950164f-3c5e-4bdc-abc8-22aaf5a1bd49",
"defaultDuration": 48
},
the front end can't find the phase with id "6950164f-3c5e-4bdc-abc8-22aaf5a1bd49" in challenge phase so it will ignore this phase.
This phase doesn't come down from this endpoint: https://api.topcoder-dev.com/v5/challenge-phases
This line seems to be the culprit, in PhaseService.js:
const list = await helper.scan('Phase')
The scan will only return the first 20 phases, but we need to pull all of them.
I'm not sure where this issue is specifically caused, but it looks like the update function calls populatePhases which uses:
https://github.com/topcoder-platform/challenge-api/blob/develop/src/services/ChallengeService.js#L331
But these .scan( calls are going to bite us. Make sure if you have IDs you're looking up, you should be using the getById on each ID and querying the db rather than scanning. It's more efficient to loop through IDs and query for each one, than scan, especially because of the pagination.
For now, I have updated the code to return the first 100 instead of 20 by default. This fixed the issue temporarily but we should indeed get rid of .scan()