codecombat/app/models/Prepaid.coffee
Scott Erickson 97cb5275c3 Fixes for courses, hoc
* Handling prepaids with strings for maxRedeemers
* Add link to TeacherCoursesView from HourOfCodeView
* Show only course instances with classrooms attached in TeacherCoursesView and StudentCoursesView
* Add event tracking to HourOfCodeView
* Add not-logged-in handling to TeacherCoursesView
* Fixed a GET prepaids bug
* Have course instances created for hour of code have hourOfCode property set to true.
2015-11-09 17:58:40 -08:00

20 lines
571 B
CoffeeScript

CocoModel = require './CocoModel'
schema = require 'schemas/models/prepaid.schema'
module.exports = class Prepaid extends CocoModel
@className: "Prepaid"
urlRoot: '/db/prepaid'
openSpots: ->
@get('maxRedeemers') - @get('redeemers')?.length
userHasRedeemed: (userID) ->
for redeemer in @get('redeemers')
return redeemer.date if redeemer.userID is userID
return null
initialize: ->
@listenTo @, 'add', ->
maxRedeemers = @get('maxRedeemers')
if _.isString(maxRedeemers)
@set 'maxRedeemers', parseInt(maxRedeemers)