🐛Fix course victory dialog level progress counts

Use classroom versioned levels instead of latest course levels.
Use current level session instead of stale one.
This commit is contained in:
Matt Lott 2016-07-11 13:28:48 -07:00
parent 0cf04a9658
commit 16c9f10043
3 changed files with 15 additions and 19 deletions

View file

@ -5,12 +5,6 @@ module.exports = class LevelSessionCollection extends CocoCollection
url: '/db/level.session' url: '/db/level.session'
model: LevelSession model: LevelSession
fetchMineForCourseInstance: (courseInstanceID, options) ->
options = _.extend({
url: "/db/course_instance/#{courseInstanceID}/my-course-level-sessions"
}, options)
@fetch(options)
fetchForCourseInstance: (courseInstanceID, options) -> fetchForCourseInstance: (courseInstanceID, options) ->
options = _.extend({ options = _.extend({
url: "/db/course_instance/#{courseInstanceID}/my-course-level-sessions" url: "/db/course_instance/#{courseInstanceID}/my-course-level-sessions"

View file

@ -131,6 +131,8 @@ module.exports = class CourseVictoryModal extends ModalView
for newItem in @newItems.models for newItem in @newItems.models
@views.push(new NewItemView({item: newItem})) @views.push(new NewItemView({item: newItem}))
@levelSessions?.remove(@session)
@levelSessions?.add(@session)
progressView = new ProgressView({ progressView = new ProgressView({
level: @level level: @level
nextLevel: @nextLevel nextLevel: @nextLevel

View file

@ -142,13 +142,13 @@ CourseInstanceHandler = class CourseInstanceHandler extends Handler
CourseInstance.findById courseInstanceID, (err, courseInstance) => CourseInstance.findById courseInstanceID, (err, courseInstance) =>
return @sendDatabaseError(res, err) if err return @sendDatabaseError(res, err) if err
return @sendNotFoundError(res) unless courseInstance return @sendNotFoundError(res) unless courseInstance
Course.findById courseInstance.get('courseID'), (err, course) => Classroom.findById courseInstance.get('classroomID'), (err, classroom) =>
return @sendDatabaseError(res, err) if err return @sendDatabaseError(res, err) if err
return @sendNotFoundError(res) unless course return @sendNotFoundError(res) unless classroom
Campaign.findById course.get('campaignID'), (err, campaign) => levelIDs = []
return @sendDatabaseError(res, err) if err for course in classroom.get('courses') when course._id.equals(courseInstance.get('courseID'))
return @sendNotFoundError(res) unless campaign for level in course.levels when not _.contains(level.type, 'ladder')
levelIDs = (levelID for levelID, level of campaign.get('levels') when not _.contains(level.type, 'ladder')) levelIDs.push(level.original + "")
query = {$and: [{creator: req.user.id}, {'level.original': {$in: levelIDs}}]} query = {$and: [{creator: req.user.id}, {'level.original': {$in: levelIDs}}]}
cursor = LevelSession.find(query) cursor = LevelSession.find(query)
cursor = cursor.select(req.query.project) if req.query.project cursor = cursor.select(req.query.project) if req.query.project