2015-08-29 10:15:35 -04:00
|
|
|
mongoose = require 'mongoose'
|
|
|
|
config = require '../../server_config'
|
|
|
|
plugins = require '../plugins/plugins'
|
|
|
|
jsonSchema = require '../../app/schemas/models/course.schema'
|
2016-08-20 12:12:07 -04:00
|
|
|
{sortCourses} = require '../../app/core/utils'
|
2015-08-29 10:15:35 -04:00
|
|
|
|
|
|
|
CourseSchema = new mongoose.Schema {}, {strict: false, minimize: false, read:config.mongo.readpref}
|
|
|
|
|
|
|
|
CourseSchema.plugin plugins.NamedPlugin
|
|
|
|
CourseSchema.plugin plugins.SearchablePlugin, {searchable: ['name', 'description']}
|
2016-08-16 12:24:34 -04:00
|
|
|
CourseSchema.plugin(plugins.TranslationCoveragePlugin)
|
2016-09-07 19:15:54 -04:00
|
|
|
CourseSchema.plugin(plugins.PatchablePlugin)
|
2015-08-29 10:15:35 -04:00
|
|
|
|
|
|
|
CourseSchema.statics.privateProperties = []
|
2016-08-16 12:24:34 -04:00
|
|
|
CourseSchema.statics.editableProperties = [
|
|
|
|
'i18n',
|
|
|
|
'i18nCoverage'
|
|
|
|
]
|
2015-08-29 10:15:35 -04:00
|
|
|
|
|
|
|
CourseSchema.statics.jsonSchema = jsonSchema
|
|
|
|
|
2016-07-16 03:31:53 -04:00
|
|
|
CourseSchema.statics.sortCourses = (courses) ->
|
2016-08-20 12:12:07 -04:00
|
|
|
sortCourses(courses)
|
|
|
|
|
2016-08-16 12:24:34 -04:00
|
|
|
CourseSchema.post 'init', (doc) ->
|
|
|
|
if !doc.get('i18nCoverage')
|
|
|
|
doc.set('i18nCoverage', [])
|
2016-07-16 03:31:53 -04:00
|
|
|
|
2015-08-29 10:15:35 -04:00
|
|
|
module.exports = Course = mongoose.model 'course', CourseSchema, 'courses'
|