MCPcopy Create free account
hub / github.com/codecombat/codecombat / getHocCourseInstanceId

Method getHocCourseInstanceId

app/models/User.js:320–337  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

318 }
319
320 getHocCourseInstanceId () {
321 const courseInstanceIds = me.get('courseInstances') || []
322 if (courseInstanceIds.length === 0) { return }
323 const courseInstancePromises = []
324 courseInstanceIds.forEach(id => {
325 return courseInstancePromises.push(api.courseInstances.get({ courseInstanceID: id }))
326 })
327
328 return Promise.all(courseInstancePromises)
329 .then(courseInstances => {
330 let courseInstancesHoc = courseInstances.filter(c => c.courseID === utils.hourOfCodeOptions.courseId)
331 if (courseInstancesHoc.length === 0) { return }
332 if (courseInstancesHoc.length === 1) { return courseInstancesHoc[0]._id }
333 // return the latest course instance id if there are multiple
334 courseInstancesHoc = _.sortBy(courseInstancesHoc, c => c._id)
335 return _.last(courseInstancesHoc)._id
336 }).catch(err => console.error('Error in fetching hoc course instance', err))
337 }
338
339 isSessionless () {
340 return Boolean((utils.getQueryVariable('dev', false) || this.isTeacher()) && utils.getQueryVariable('course', false) && !utils.getQueryVariable('course-instance'))

Callers

nothing calls this directly

Calls 3

filterMethod · 0.80
getMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected