<commit_before>const md5 = require('js-md5');
const {User, Room, Note} = require('./db-config');

const createNewUser = ({facebookId, name, email, pictureUrl, gender}, cb) => {

  User.findOrCreate({
    where: {
      facebookId: facebookId
    },
    defaults: {
      name: name,
      email: email,
      pictureUrl: pictureUrl,
      gender: gender
    }
  })
  .spread((user, created) => {
    // created is true  if new user
    // created is false if user already exists
    cb(user, created);
  });
};

const createNewRoom = ({topic, className, lecturer, hostId}, cb) => {
  // { topic, class, lecturer, hostId }
  const pathUrl = md5(topic + className + lecturer + hostId + Date()).slice(0, 5);

  Room.create({
    pathUrl: pathUrl,
    topic: topic,
    class: className,
    lecturer: lecturer,
    hostId: hostId
  })
  .then((roomInfo) => {
    cb(roomInfo);
  });
};

const joinRoom = (userId, pathUrl, cb) => {
  User.findOne({
    where: { id: userId }
  })
  .then((currentUser) => {
    Room.findOne({
      where: { pathUrl: pathUrl }
    })
    .then((currentRoom) => {
      currentUser.addLectureRoom(currentRoom);
      cb(currentRoom);
    });
  });
};

const createNewNote = ({content, roomId, originalUserId}, cb) => {
  // content, audioTimestamp, show, roomId, editingUserId, originalUserId

  User.findOne({
    where: { id: originalUserId }
  })
  .then((user) => {
    Room.findOne({
      where: { id: roomId }
    })
    .then((room) => {
      Note.create({
        content: content,
        audioTimestamp: Date(),
        show: true
      })
      .then((note) => {
        note.setOriginalUser(user);<commit_msg>(dev) fix syntax error during user/room association<commit_after>const md5 = require('js-md5');
const {User, Room, Note} = require('./db-config');

const createNewUser = ({facebookId, name, email, pictureUrl, gender}, cb) => {

  User.findOrCreate({
    where: {
      facebookId: facebookId
    },
    defaults: {
      name: name,
      email: email,
      pictureUrl: pictureUrl,
      gender: gender
    }
  })
  .spread((user, created) => {
    // created is true  if new user
    // created is false if user already exists
    cb(user, created);
  });
};

const createNewRoom = ({topic, className, lecturer, hostId}, cb) => {
  // { topic, class, lecturer, hostId }
  const pathUrl = md5(topic + className + lecturer + hostId + Date()).slice(0, 5);

  Room.create({
    pathUrl: pathUrl,
    topic: topic,
    class: className,
    lecturer: lecturer,
    hostId: hostId
  })
  .then((roomInfo) => {
    cb(roomInfo);
  });
};

const joinRoom = (userId, pathUrl, cb) => {
  User.findOne({
    where: { id: userId }
  })
  .then((currentUser) => {
    Room.findOne({
      where: { pathUrl: pathUrl }
    })
    .then((currentRoom) => {
      currentUser.addRoom(currentRoom);
      cb(currentRoom);
    });
  });
};

const createNewNote = ({content, roomId, originalUserId}, cb) => {
  // content, audioTimestamp, show, roomId, editingUserId, originalUserId

  User.findOne({
    where: { id: originalUserId }
  })
  .then((user) => {
    Room.findOne({
      where: { id: roomId }
    })
    .then((room) => {
      Note.create({
        content: content,
        audioTimestamp: Date(),
        show: true
      })
      .then((note) => {
        note.setOriginalUser(user);
{'fraction_non_alphanumeric': 0.16111611161116113, 'fraction_numerical': 0.003000300030003, 'mean_word_length': 2.6318082788671022, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '1980661', 'n_tokens_mistral': 1097, 'n_tokens_neox': 1094, 'n_words': 257}