codecombat/server/clans/Clan.coffee

33 lines
882 B
CoffeeScript
Raw Normal View History

mongoose = require 'mongoose'
log = require 'winston'
config = require '../../server_config'
plugins = require '../plugins/plugins'
2015-04-02 20:00:28 -04:00
User = require '../users/User'
jsonSchema = require '../../app/schemas/models/clan.schema'
ClanSchema = new mongoose.Schema {}, {strict: false, minimize: false, read:config.mongo.readpref}
2015-04-02 20:00:28 -04:00
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 = [
2015-04-03 17:09:43 -04:00
'description'
'members'
2015-04-03 17:09:43 -04:00
'name'
'type'
]
ClanSchema.plugin plugins.NamedPlugin
2015-04-03 17:09:43 -04:00
# TODO: Do we need this?
# ClanSchema.plugin plugins.SearchablePlugin, {searchable: ['name']}
ClanSchema.statics.jsonSchema = jsonSchema
module.exports = Clan = mongoose.model 'clan', ClanSchema, 'clans'