2015-04-01 14:56:48 -04:00
|
|
|
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'
|
2015-04-01 14:56:48 -04:00
|
|
|
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()
|
|
|
|
|
2015-04-01 14:56:48 -04:00
|
|
|
ClanSchema.statics.privateProperties = []
|
|
|
|
ClanSchema.statics.editableProperties = [
|
2015-04-03 17:09:43 -04:00
|
|
|
'description'
|
2015-04-01 14:56:48 -04:00
|
|
|
'members'
|
2015-04-03 17:09:43 -04:00
|
|
|
'name'
|
|
|
|
'type'
|
2015-04-01 14:56:48 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
ClanSchema.plugin plugins.NamedPlugin
|
2015-04-03 17:09:43 -04:00
|
|
|
|
|
|
|
# TODO: Do we need this?
|
|
|
|
# ClanSchema.plugin plugins.SearchablePlugin, {searchable: ['name']}
|
2015-04-01 14:56:48 -04:00
|
|
|
|
|
|
|
ClanSchema.statics.jsonSchema = jsonSchema
|
|
|
|
|
|
|
|
module.exports = Clan = mongoose.model 'clan', ClanSchema, 'clans'
|