<commit_before>_ = require 'underscore'
mongoose = require 'mongoose'
rbytes = require 'rbytes'

InviteSchema = require './invite'
Invite = mongoose.model 'Invite'
Person = mongoose.model 'Person'

TeamSchema = module.exports = new mongoose.Schema
  name:
    type: String
    required: true
  emails:
    type: [ mongoose.SchemaTypes.Email ]
    validate: [ ((v) -> v.length <= 4), 'max' ]
  invites: [ InviteSchema ]
  people_ids:
    type: [ mongoose.Schema.ObjectId ]
    index: true
  code:
    type: String
    default: -> rbytes.randomBytes(12).toString('base64')
TeamSchema.plugin require('mongoose-types').useTimestamps

TeamSchema.method 'includes', (person, code) ->
  @code == code or _.any @people_ids, (id) -> id.equals(person?.id)

TeamSchema.method 'people', (callback) ->
  Person.find _id: { '$in': @people_ids }, callback

TeamSchema.method 'invited', (invite) ->
  _.detect @invites, (i) -> i.code == invite<commit_msg>id.equals(null) is bad<commit_after>_ = require 'underscore'
mongoose = require 'mongoose'
rbytes = require 'rbytes'

InviteSchema = require './invite'
Invite = mongoose.model 'Invite'
Person = mongoose.model 'Person'

TeamSchema = module.exports = new mongoose.Schema
  name:
    type: String
    required: true
  emails:
    type: [ mongoose.SchemaTypes.Email ]
    validate: [ ((v) -> v.length <= 4), 'max' ]
  invites: [ InviteSchema ]
  people_ids:
    type: [ mongoose.Schema.ObjectId ]
    index: true
  code:
    type: String
    default: -> rbytes.randomBytes(12).toString('base64')
TeamSchema.plugin require('mongoose-types').useTimestamps

TeamSchema.method 'includes', (person, code) ->
  @code == code or person and _.any @people_ids, (id) -> id.equals(person.id)

TeamSchema.method 'people', (callback) ->
  Person.find _id: { '$in': @people_ids }, callback

TeamSchema.method 'invited', (invite) ->
  _.detect @invites, (i) -> i.code == invite
{'fraction_non_alphanumeric': 0.1518186610437533, 'fraction_numerical': 0.005271481286241434, 'mean_word_length': 3.968586387434555, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2803357', 'n_tokens_mistral': 640, 'n_tokens_neox': 649, 'n_words': 155}