codecombat/app/models/CourseInstance.coffee

42 lines
1.1 KiB
CoffeeScript
Raw Normal View History

2015-08-29 10:15:35 -04:00
CocoModel = require './CocoModel'
schema = require 'schemas/models/course_instance.schema'
module.exports = class CourseInstance extends CocoModel
@className: 'CourseInstance'
@schema: schema
urlRoot: '/db/course_instance'
upsertForHOC: (opts) ->
options = {
url: _.result(@, 'url') + '/~/create-for-hoc'
type: 'POST'
}
_.extend options, opts
@fetch(options)
2015-12-04 15:08:08 -05:00
addMember: (userID, opts) ->
options = {
method: 'POST'
url: _.result(@, 'url') + '/members'
data: { userID: userID }
}
_.extend options, opts
@fetch(options)
2015-12-04 15:08:08 -05:00
if userID is me.id
unless me.get('courseInstances')
me.set('courseInstances', [])
me.get('courseInstances').push(@id)
removeMember: (userID, opts) ->
options = {
url: _.result(@, 'url') + '/members'
type: 'DELETE'
data: { userID: userID }
}
_.extend options, opts
@fetch(options)
me.set('courseInstances', _.without(me.get('courseInstances'), @id)) if userID is me.id
2015-12-04 15:08:08 -05:00
firstLevelURL: ->
"/play/level/dungeons-of-kithgard?course=#{@get('courseID')}&course-instance=#{@id}"