   name:
     type: String
     required: true
+    unique: true
   emails:
     type: [ mongoose.SchemaTypes.Email ]
     validate: [ ((v) -> v.length <= 4), 'max' ]

      error.errors._base = 'max'
      next error

# create invites
TeamSchema.pre 'save', (next) ->
  for email in @emails

    max = 225 + 1 # +1 because team fortnight labs doesn't count
    next null, count < max, max - count

TeamSchema.static 'uniqueName', (name, next) ->
  Team.count { name: name }, (err, count) ->
    return next err if err
    next null, !count

# min people validation
TeamSchema.pre 'save', (next) ->
  if @people_ids.length + @emails.length == 0
