<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
    }
  })
  // created is true  if new user
  // created is false if user already exists
  .spread((user, created) => cb(user, created));
};

const createNewRoom = ({topic, className, lecturer, hostId}, cb) => {
  // { topic, class, lecturer, hostId }
  const pathUrl = md5(topic + className + lecturer + hostId + Math.random()).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.findById(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

  Note.create({
    content: content,
    audioTimestamp: Date(),
    show: true,
    originalUserId: originalUserId,
    editingUserId: originalUserId,
    roomId: roomId
  })
  .then((note) => { cb(note); });
};

const showAllNotes = ({userId, roomId}, cb) => {
  Note.findAll({
    where: { editingUserId: userId },
    include: {
      model: Room,
      where: { id: roomId },
      attributes: []
    }
  })
  .then((allNotes) => cb(allNotes));
};

const showFilteredNotes = ({userId, roomId}, cb) => {
  Note.findAll({
    where: {
      editingUserId: userId,
      show: true
    },
    include: {
      model: Room,
      where: { id: roomId },
      attributes: []
    }
  })
  .then((allNotes) => cb(allNotes));
};

const findRoomId = ({pathUrl}, cb) => {
  Room.findOne({
    attribute: ['id'],
    where: {pathUrl: pathUrl}
  })
  .then((found) => {
    cb(found);
  });

};

module.exports = {
  createNewUser,
  createNewRoom,
  joinRoom,
  createNewNote,
  showAllNotes,
  showFilteredNotes,
  findRoomId
};<commit_msg>(dev) add findRoom db-helper function<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
    }
  })
  // created is true  if new user
  // created is false if user already exists
  .spread((user, created) => cb(user, created));
};

const createNewRoom = ({topic, className, lecturer, hostId}, cb) => {
  // { topic, class, lecturer, hostId }
  const pathUrl = md5(topic + className + lecturer + hostId + Math.random()).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.findById(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

  Note.create({
    content: content,
    audioTimestamp: Date(),
    show: true,
    originalUserId: originalUserId,
    editingUserId: originalUserId,
    roomId: roomId
  })
  .then((note) => { cb(note); });
};

const showAllNotes = ({userId, roomId}, cb) => {
  Note.findAll({
    where: { editingUserId: userId },
    include: {
      model: Room,
      where: { id: roomId },
      attributes: []
    }
  })
  .then((allNotes) => cb(allNotes));
};

const showFilteredNotes = ({userId, roomId}, cb) => {
  Note.findAll({
    where: {
      editingUserId: userId,
      show: true
    },
    include: {
      model: Room,
      where: { id: roomId },
      attributes: []
    }
  })
  .then((allNotes) => cb(allNotes));
};

const findRoom = (pathUrl, cb) => {
  Room.count({ where: {pathUrl: pathUrl} })
  .then((count) => { cb(count); });
};

module.exports = {
  createNewUser,
  createNewRoom,
  joinRoom,
  createNewNote,
  showAllNotes,
  showFilteredNotes,
  findRoom
};
{'fraction_non_alphanumeric': 0.16253263707571802, 'fraction_numerical': 0.002175805047867711, 'mean_word_length': 2.9527085124677557, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, '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': '7461068', 'n_tokens_mistral': 1554, 'n_tokens_neox': 1557, 'n_words': 356}