2015-06-05 09:48:09 -04:00
|
|
|
log = require 'winston'
|
|
|
|
mongoose = require 'mongoose'
|
|
|
|
config = require '../../server_config'
|
|
|
|
sendwithus = require '../sendwithus'
|
2016-04-06 13:56:06 -04:00
|
|
|
Prepaid = require './Prepaid'
|
2015-06-05 09:48:09 -04:00
|
|
|
jsonSchema = require '../../app/schemas/models/trial_request.schema'
|
2016-04-06 13:56:06 -04:00
|
|
|
Classroom = require './Classroom'
|
|
|
|
User = require './User'
|
2015-06-05 09:48:09 -04:00
|
|
|
|
|
|
|
TrialRequestSchema = new mongoose.Schema {}, {strict: false, minimize: false, read:config.mongo.readpref}
|
|
|
|
|
|
|
|
TrialRequestSchema.post 'save', (doc) ->
|
2016-04-07 15:52:11 -04:00
|
|
|
# Subscribe to teacher news group
|
|
|
|
User.findById doc.get('applicant'), (err, user) =>
|
|
|
|
if err
|
|
|
|
log.error "Trial request user find error: #{err}"
|
2016-02-26 09:21:28 -05:00
|
|
|
return
|
2016-04-07 15:52:11 -04:00
|
|
|
emails = _.cloneDeep(user.get('emails') ? {})
|
|
|
|
emails.teacherNews ?= {}
|
|
|
|
emails.teacherNews.enabled = true
|
|
|
|
user.update {$set: {emails: emails}}, {}, (err) =>
|
2016-01-17 10:39:30 -05:00
|
|
|
if err
|
2016-04-07 15:52:11 -04:00
|
|
|
log.error "Trial request user update error: #{err}"
|
2016-01-17 10:39:30 -05:00
|
|
|
return
|
2016-02-26 09:21:28 -05:00
|
|
|
|
2015-06-05 09:48:09 -04:00
|
|
|
TrialRequestSchema.statics.privateProperties = []
|
|
|
|
TrialRequestSchema.statics.editableProperties = [
|
2015-11-19 19:06:58 -05:00
|
|
|
'created'
|
2015-06-05 09:48:09 -04:00
|
|
|
'prepaidCode'
|
|
|
|
'properties'
|
|
|
|
'reviewDate'
|
|
|
|
'reviewer'
|
|
|
|
'status'
|
|
|
|
'type'
|
|
|
|
]
|
|
|
|
|
|
|
|
TrialRequestSchema.statics.jsonSchema = jsonSchema
|
|
|
|
module.exports = TrialRequest = mongoose.model 'trial.request', TrialRequestSchema, 'trial.requests'
|