mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-30 10:56:53 -05:00
🐛Fix course solutions level ordering
This commit is contained in:
parent
e91a15338e
commit
5a6bed96b2
2 changed files with 8 additions and 3 deletions
|
@ -24,10 +24,15 @@ module.exports =
|
||||||
campaign = yield Campaign.findById course.get('campaignID')
|
campaign = yield Campaign.findById course.get('campaignID')
|
||||||
throw new errors.NotFound('Campaign not found.') unless campaign
|
throw new errors.NotFound('Campaign not found.') unless campaign
|
||||||
|
|
||||||
levelOriginals = (mongoose.Types.ObjectId(levelID) for levelID of campaign.get('levels'))
|
# TODO: why does campaign.get('levels') return opposite order from direct db query?
|
||||||
|
sortedLevelIDs = _.keys campaign.get('levels')
|
||||||
|
sortedLevelIDs.reverse()
|
||||||
|
|
||||||
|
levelOriginals = (mongoose.Types.ObjectId(levelID) for levelID in sortedLevelIDs)
|
||||||
query = { original: { $in: levelOriginals }, slug: { $exists: true }}
|
query = { original: { $in: levelOriginals }, slug: { $exists: true }}
|
||||||
select = {documentation: 1, intro: 1, name: 1, slug: 1, thangs: 1}
|
select = {documentation: 1, intro: 1, name: 1, original: 1, slug: 1, thangs: 1}
|
||||||
levels = yield Level.find(query).select(select).lean()
|
levels = yield Level.find(query).select(select).lean()
|
||||||
|
levels.sort((a, b) -> sortedLevelIDs.indexOf(a.original + '') - sortedLevelIDs.indexOf(b.original + ''))
|
||||||
res.status(200).send(levels)
|
res.status(200).send(levels)
|
||||||
|
|
||||||
fetchNextLevel: wrap (req, res) ->
|
fetchNextLevel: wrap (req, res) ->
|
||||||
|
|
|
@ -150,8 +150,8 @@ describe 'GET /db/course/:handle/level-solutions', ->
|
||||||
paredLevelB = _.pick(res.body, 'name', 'original', 'type')
|
paredLevelB = _.pick(res.body, 'name', 'original', 'type')
|
||||||
|
|
||||||
campaignJSONA = { name: 'Campaign A', levels: {} }
|
campaignJSONA = { name: 'Campaign A', levels: {} }
|
||||||
campaignJSONA.levels[paredLevelA.original] = paredLevelA
|
|
||||||
campaignJSONA.levels[paredLevelB.original] = paredLevelB
|
campaignJSONA.levels[paredLevelB.original] = paredLevelB
|
||||||
|
campaignJSONA.levels[paredLevelA.original] = paredLevelA
|
||||||
[res, body] = yield request.postAsync({uri: getURL('/db/campaign'), json: campaignJSONA})
|
[res, body] = yield request.postAsync({uri: getURL('/db/campaign'), json: campaignJSONA})
|
||||||
@campaignA = yield Campaign.findById(res.body._id)
|
@campaignA = yield Campaign.findById(res.body._id)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue