<commit_before>const logger = require('logger');
const JWT = require('jsonwebtoken');
const config = require('config');
const MailService = require('services/MailService');
const UserService = require('services/user.service');
const TeamModel = require('models/team.model');

class TeamService {
  
  static verifyToken(token) {
    try { 
     return JWT.verify(token, config.get('jwt.token'));
    } catch (e){
      logger.info(`Generated token ${e}`);
    }
  }
  static generateToken(email, teamId) {
    const token = JWT.sign({ email, teamId }, config.get('jwt.token'), {});
    logger.info(`Generated token ${token}`);
    return token;
  }

  static sendNotifications(users = [], team, locale) {
    users.forEach( async (email) => {
      const generatedToken = this.generateToken(email, team.id);
      const link = `${config.get('application.url')}?callbackUrl=${config.get('application.url')}?confirmToken=${generatedToken}&confirmToken=${generatedToken}`;
      if (!team.sentInvitations.includes(email)) {
        const invitationMailId = `team-invitation-${locale || 'en'}`;
        MailService.sendMail(invitationMailId, { link }, [{ address: { email } }]);
        team.sentInvitations = team.sentInvitations.concat(email);
        await team.save;
      }
    });
  }

  static sendManagerConfirmation(confirmedUserEmail, managers = [], locale) {
    managers.forEach( async (managerId) => {
      const joinedMailId = `team-joined-${locale || 'en'}`;
      const managerEmail = UserService.getEmailById(managerId);
      MailService.sendMail(joinedMailId, { email: confirmedUserEmail }, [{ address: { managerEmail } }]);
    });
  }

  static async deleteConfirmedUserFromPreviousTeams(userId, teamId) {
    const userTeams = await TeamModel.find({ confirmedUsers: userId });
    logger.info(`User was in ${userTeams}`);
    userTeams.forEach( async (team) => {
      if (team !== teamId) {
        team.confirmedUsers = team.confirmedUsers.filter((user) => user !== userId)
        logger.info(`User ${userId} is not in ${team.confirmedUsers}`);
        await team.save;
      }
    });
    logger.info(`User is in ${userTeams}`);
  }
}
module.exports = TeamService;<commit_msg>fix: Team is not saving<commit_after>const logger = require('logger');
const JWT = require('jsonwebtoken');
const config = require('config');
const MailService = require('services/MailService');
const UserService = require('services/user.service');
const TeamModel = require('models/team.model');

class TeamService {
  
  static verifyToken(token) {
    try { 
     return JWT.verify(token, config.get('jwt.token'));
    } catch (e){
      logger.info(`Generated token ${e}`);
    }
  }
  static generateToken(email, teamId) {
    const token = JWT.sign({ email, teamId }, config.get('jwt.token'), {});
    logger.info(`Generated token ${token}`);
    return token;
  }

  static sendNotifications(users = [], team, locale) {
    users.forEach( async (email) => {
      const generatedToken = this.generateToken(email, team.id);
      const link = `${config.get('application.url')}?callbackUrl=${config.get('application.url')}?confirmToken=${generatedToken}&confirmToken=${generatedToken}`;
      if (!team.sentInvitations.includes(email)) {
        const invitationMailId = `team-invitation-${locale || 'en'}`;
        MailService.sendMail(invitationMailId, { link }, [{ address: { email } }]);
        team.sentInvitations = team.sentInvitations.concat(email);
        await team.save;
      }
    });
  }

  static sendManagerConfirmation(confirmedUserEmail, managers = [], locale) {
    managers.forEach( async (managerId) => {
      const joinedMailId = `team-joined-${locale || 'en'}`;
      const managerEmail = UserService.getEmailById(managerId);
      MailService.sendMail(joinedMailId, { email: confirmedUserEmail }, [{ address: { managerEmail } }]);
    });
  }

  static async deleteConfirmedUserFromPreviousTeams(userId, teamId) {
    const userTeams = await TeamModel.find({ confirmedUsers: userId });
    logger.info(`User was in ${userTeams}`);
    userTeams.forEach( async (team) => {
      if (team.id !== teamId) {
        const teamToChange = await TeamModel.findById(team.id);
        logger.info(`Team id ${teamToChange.id}`);
        teamToChange.confirmedUsers = teamToChange.confirmedUsers.filter((user) => user !== userId);
        logger.info(`User ${userId} is not in ${teamToChange.confirmedUsers}`);
        await teamToChange.save;
      }
    });
    logger.info(`User is in ${userTeams}`);
  }
}
module.exports = TeamService;
{'fraction_non_alphanumeric': 0.15639394604079843, 'fraction_numerical': 0.0, 'mean_word_length': 3.871794871794872, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '3495358', 'n_tokens_mistral': 1340, 'n_tokens_neox': 1351, 'n_words': 270}