<commit_before>Meteor.methods

  addRegistrant: (details) ->
    registrantId = Registrants.insert details
    teamRegistration = modelHelpers.buildTeamRegistration registrantId
    modelHelpers.upsertTeamRegistration details.userId, teamRegistration
    registrantId

  addTeamToRegistrant: (registrantId, teamId) ->
    existing = Registrants.findOne registrantId
    for team in existing.teams
      if team is teamId then found = team
    if found
      teamRegistration = modelHelpers.buildTeamRegistration registrantId
      modelHelpers.upsertTeamRegistration existing.userId, teamRegistration
      return
    Registrants.update registrantId, $push: teams: teamId

  removeTeamFromRegistrant: (registrantId, teamId) ->
    registrant = Registrants.findOne registrantId
    Registrants.update registrantId, $pull: teams: teamId
    # TODO: If there are no more teams now, delete this registrant document
    modelHelpers.removeTeamRegistration registrant.userId, registrantId

  updateRegistrant: (registrant) ->
    existing = Registrants.findOne
      userId: registrant.userId
      tournamentId: registrant.tournamentId
    update =
      'function': registrant.function
      'accessCode': registrant.accessCode.toUpperCase()
    Registrants.update existing._id, $set: update
    teamRegistration = modelHelpers.buildTeamRegistration existing._id
    modelHelpers.upsertTeamRegistration existing.userId, teamRegistration

  createNewUser: (user) ->
    newUser =
      email: user.email
      profile:
        email: user.email.toLowerCase()
        firstName: user.firstName
        lastName: user.lastName
        fullName: user.firstName + ' ' + user.lastName
        photoFilename: user.photoFilename
        gender: user.gender || 'female'
        slug: user.firstName + user.lastName
        admin: user.admin
        isNew: user.isNew
    newUserId = Accounts.createUser newUser
    modelHelpers.upsertUserRegistration {
      _id: newUserId
      email: newUser.email
      slug: newUser.profile.slug
      gender: newUser.profile.gender
      fullName: newUser.profile.fullName
      photoFilename: newUser.profile.photoFilename
    }
    newUserId

  updateUser: (user) ->
    firstName = user.firstName
    lastName = user.lastName
    Meteor.users.update user._id, $set: profile: {
      email: user.email.toLowerCase(),
      firstName: firstName,
      lastName: lastName,
      fullName: firstName + ' ' + lastName,
      photoFilename: user.photoFilename,
      gender: user.gender || 'female',
      slug: firstName.replace(/\s/g,'') + lastName.replace(/\s/g,''),
      admin: user.admin,
      isNew: user.isNew
    }
    modelHelpers.upsertUserRegistration {
      _id: user._id
      slug: user.slug
      email: user.email
      gender: user.gender
      fullName: user.fullName
      photoFilename: user.photoFilename
    }
    false

  deleteUser: (userId) ->
    Meteor.users.remove userId
    Volunteers.remove userId
    Registrants.remove userId: userId
    Registrations.remove userId

  createNewVolunteer: (volunteer) ->
    Volunteers.insert {
      _id: volunteer._id,
      birthdate: volunteer.birthdate || '',
      shirtSize: volunteer.shirtSize?.toUpperCase() || '',
      homePhone: volunteer.homePhone || '',
      mobilePhone: volunteer.mobilePhone || '',
      address: volunteer.address || '',
      city: volunteer.city || '',
      suburb: volunteer.suburb || '',
      postalCode: volunteer.postalCode || '',
      notes: volunteer.notes || ''
    }
<commit_msg>Fixed bug with renaming users<commit_after>Meteor.methods

  addRegistrant: (details) ->
    registrantId = Registrants.insert details
    teamRegistration = modelHelpers.buildTeamRegistration registrantId
    modelHelpers.upsertTeamRegistration details.userId, teamRegistration
    registrantId

  addTeamToRegistrant: (registrantId, teamId) ->
    existing = Registrants.findOne registrantId
    for team in existing.teams
      if team is teamId then found = team
    if found
      teamRegistration = modelHelpers.buildTeamRegistration registrantId
      modelHelpers.upsertTeamRegistration existing.userId, teamRegistration
      return
    Registrants.update registrantId, $push: teams: teamId

  removeTeamFromRegistrant: (registrantId, teamId) ->
    registrant = Registrants.findOne registrantId
    Registrants.update registrantId, $pull: teams: teamId
    # TODO: If there are no more teams now, delete this registrant document
    modelHelpers.removeTeamRegistration registrant.userId, registrantId

  updateRegistrant: (registrant) ->
    existing = Registrants.findOne
      userId: registrant.userId
      tournamentId: registrant.tournamentId
    update =
      'function': registrant.function
      'accessCode': registrant.accessCode.toUpperCase()
    Registrants.update existing._id, $set: update
    teamRegistration = modelHelpers.buildTeamRegistration existing._id
    modelHelpers.upsertTeamRegistration existing.userId, teamRegistration

  createNewUser: (user) ->
    newUser =
      email: user.email
      profile:
        email: user.email.toLowerCase()
        firstName: user.firstName
        lastName: user.lastName
        fullName: user.firstName + ' ' + user.lastName
        photoFilename: user.photoFilename
        gender: user.gender || 'female'
        slug: user.firstName + user.lastName
        admin: user.admin
        isNew: user.isNew
    newUserId = Accounts.createUser newUser
    modelHelpers.upsertUserRegistration {
      _id: newUserId
      email: newUser.email
      slug: newUser.profile.slug
      gender: newUser.profile.gender
      fullName: newUser.profile.fullName
      photoFilename: newUser.profile.photoFilename
    }
    newUserId

  updateUser: (user) ->
    firstName = user.firstName
    lastName = user.lastName
    gender = user.gender || 'female'
    fullName = firstName + ' ' + lastName
    slug = firstName.replace(/\s/g,'') + lastName.replace(/\s/g,'')
    Meteor.users.update user._id, $set: profile: {
      email: user.email.toLowerCase()
      firstName: firstName
      lastName: lastName
      fullName: fullName
      photoFilename: user.photoFilename
      gender: gender
      slug: slug
      admin: user.admin
      isNew: user.isNew
    }
    modelHelpers.upsertUserRegistration {
      _id: user._id
      slug: slug
      email: user.email
      gender: gender
      fullName: fullName
      photoFilename: user.photoFilename
    }
    false

  deleteUser: (userId) ->
    Meteor.users.remove userId
    Volunteers.remove userId
    Registrants.remove userId: userId
    Registrations.remove userId

  createNewVolunteer: (volunteer) ->
    Volunteers.insert {
      _id: volunteer._id,
      birthdate: volunteer.birthdate || '',
      shirtSize: volunteer.shirtSize?.toUpperCase() || '',
      homePhone: volunteer.homePhone || '',
      mobilePhone: volunteer.mobilePhone || '',
      address: volunteer.address || '',
      city: volunteer.city || '',
      suburb: volunteer.suburb || '',
      postalCode: volunteer.postalCode || '',
      notes: volunteer.notes || ''
    }

{'fraction_non_alphanumeric': 0.08997320547172472, 'fraction_numerical': 0.0, 'mean_word_length': 3.0688468158347675, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '4974278', 'n_tokens_mistral': 2009, 'n_tokens_neox': 2043, 'n_words': 442}