mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-24 16:17:57 -05:00
d7cddcb136
Add a teacher survey form for applying for a free trial subscription for evaluation purposes. Add an admin trial requests review page, where admins can approve/deny requests.
36 lines
1.2 KiB
CoffeeScript
36 lines
1.2 KiB
CoffeeScript
Handler = require '../commons/Handler'
|
|
Prepaid = require './Prepaid'
|
|
|
|
# TODO: Should this happen on a save() call instead of a prepaid/-/create post?
|
|
# TODO: Probably a better way to create a unique 8 charactor string property using db voodoo
|
|
|
|
PrepaidHandler = class PrepaidHandler extends Handler
|
|
modelClass: Prepaid
|
|
jsonSchema: require '../../app/schemas/models/prepaid.schema'
|
|
allowedMethods: ['POST']
|
|
|
|
hasAccess: (req) ->
|
|
req.user?.isAdmin()
|
|
|
|
getByRelationship: (req, res, args...) ->
|
|
relationship = args[1]
|
|
return @createPrepaid(req, res) if relationship is 'create'
|
|
super arguments...
|
|
|
|
createPrepaid: (req, res) ->
|
|
return @sendForbiddenError(res) unless @hasAccess(req)
|
|
return @sendForbiddenError(res) unless req.body.type is 'subscription'
|
|
Prepaid.generateNewCode (code) =>
|
|
return @sendDatabaseError(res, 'Database error.') unless code
|
|
prepaid = new Prepaid
|
|
creator: req.user.id
|
|
type: req.body.type
|
|
status: 'active'
|
|
code: code
|
|
properties:
|
|
couponID: 'free'
|
|
prepaid.save (err) =>
|
|
return @sendDatabaseError(res, err) if err
|
|
@sendSuccess(res, prepaid.toObject())
|
|
|
|
module.exports = new PrepaidHandler()
|