mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -05:00
🐛Restrict course level progress to course levels
This commit is contained in:
parent
50f7391e76
commit
3eb450631a
1 changed files with 14 additions and 5 deletions
|
@ -1,5 +1,6 @@
|
|||
async = require 'async'
|
||||
Handler = require '../commons/Handler'
|
||||
Campaign = require '../campaigns/Campaign'
|
||||
Course = require './Course'
|
||||
CourseInstance = require './CourseInstance'
|
||||
LevelSession = require '../levels/sessions/LevelSession'
|
||||
|
@ -88,8 +89,16 @@ CourseInstanceHandler = class CourseInstanceHandler extends Handler
|
|||
CourseInstance.findById courseInstanceID, (err, courseInstance) =>
|
||||
return @sendDatabaseError(res, err) if err
|
||||
return @sendNotFoundError(res) unless courseInstance
|
||||
Course.findById courseInstance.get('courseID'), (err, course) =>
|
||||
return @sendDatabaseError(res, err) if err
|
||||
return @sendNotFoundError(res) unless course
|
||||
Campaign.findById course.get('campaignID'), (err, campaign) =>
|
||||
return @sendDatabaseError(res, err) if err
|
||||
return @sendNotFoundError(res) unless campaign
|
||||
levelIDs = (levelID for levelID of campaign.get('levels'))
|
||||
memberIDs = _.map courseInstance.get('members') ? [], (memberID) -> memberID.toHexString?() or memberID
|
||||
LevelSession.find {creator: {$in: memberIDs}}, (err, documents) =>
|
||||
query = {$and: [{creator: {$in: memberIDs}}, {'level.original': {$in: levelIDs}}]}
|
||||
LevelSession.find query, (err, documents) =>
|
||||
return @sendDatabaseError(res, err) if err?
|
||||
cleandocs = (LevelSessionHandler.formatEntity(req, doc) for doc in documents)
|
||||
@sendSuccess(res, cleandocs)
|
||||
|
|
Loading…
Reference in a new issue