mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-24 16:17:57 -05:00
32 lines
882 B
CoffeeScript
32 lines
882 B
CoffeeScript
mongoose = require 'mongoose'
|
|
log = require 'winston'
|
|
config = require '../../server_config'
|
|
plugins = require '../plugins/plugins'
|
|
User = require '../users/User'
|
|
jsonSchema = require '../../app/schemas/models/clan.schema'
|
|
|
|
ClanSchema = new mongoose.Schema {}, {strict: false, minimize: false, read:config.mongo.readpref}
|
|
|
|
ClanSchema.pre 'save', (next) ->
|
|
User.update {_id: @get('ownerID')}, {$addToSet: {clans: @get('_id')}}, (err) =>
|
|
if err
|
|
log.error err
|
|
return next(err)
|
|
next()
|
|
|
|
ClanSchema.statics.privateProperties = []
|
|
ClanSchema.statics.editableProperties = [
|
|
'description'
|
|
'members'
|
|
'name'
|
|
'type'
|
|
]
|
|
|
|
ClanSchema.plugin plugins.NamedPlugin
|
|
|
|
# TODO: Do we need this?
|
|
# ClanSchema.plugin plugins.SearchablePlugin, {searchable: ['name']}
|
|
|
|
ClanSchema.statics.jsonSchema = jsonSchema
|
|
|
|
module.exports = Clan = mongoose.model 'clan', ClanSchema, 'clans'
|