<commit_before>'use strict';

const Promise = require('bluebird');
const User = require('../models/User');

module.exports = function() {
  const create = function(userData) {
    return new Promise((resolve, reject) => {
      const user = new User(userData);
      user.createdAt = Date.now();
      user.updatedAt = Date.now();
      user.save()
      .then((createdUser) => {
        User.findById(createdUser.id)
          .select('-__v')
          .exec()
          .then((newUser) => {
            resolve(newUser.toObject());
          })
          .catch(reject)
        })
        .catch(reject);
    });
  };

  return {
    create: create,
  };
};<commit_msg>function to access mongo and get user by username or email<commit_after>'use strict';

const Promise = require('bluebird');
const User = require('../models/User');

module.exports = function() {
  const create = function(userData) {
    return new Promise((resolve, reject) => {
      const user = new User(userData);
      user.createdAt = Date.now();
      user.updatedAt = Date.now();
      user.save()
        .then((createdUser) => {
          User.findById(createdUser.id)
            .select('-__v')
            .exec()
            .then((newUser) => {
              resolve(newUser.toObject());
            })
            .catch(reject)
          })
          .catch(reject);
    });
  };

  const getByEmailOrUsername = function(emailOrUsername) {
    return new Promise((resolve, reject) => {
      User.findOne({
        $or: [
          { email: emailOrUsername },
          { username: emailOrUsername },
        ],
      })
        .select('-__v')
        .exec()
        .then((user) => {
          resolve(user.toObject());
        })
        .catch(reject);
    });
  };

  return {
    create: create,
    getByEmailOrUsername: getByEmailOrUsername,
  };
};
{'fraction_non_alphanumeric': 0.1570964247020585, 'fraction_numerical': 0.0, 'mean_word_length': 1.9646869983948636, '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': '4528560', 'n_tokens_mistral': 542, 'n_tokens_neox': 538, 'n_words': 104}