<commit_before>
const config = require('georap-config');
const db = require('georap-db');
const bcrypt = require('bcryptjs');

module.exports = function (userParams, callback) {
  // Create user account. Does not check if user exists.
  //
  // Parameters:
  //   userParams
  //     name
  //       string
  //     email
  //       string
  //     password
  //       string
  //     role
  //       string, optional
  //   callback
  //     function (err)
  //
  const users = db.collection('users');

  const username = userParams.name;
  const email = userParams.email;
  const password = userParams.password;
  const r = config.bcrypt.rounds;
  const role = userParams.role ? userParams.role : config.defaultRole;

  bcrypt.hash(password, r, (berr, pwdHash) => {
    if (berr) {
      return callback(berr);
    }

    const now = (new Date()).toISOString();

    users.insert({
      createdAt: now,
      deleted: false,
      email: email,
      hash: pwdHash,
      loginAt: now,
      name: username,
      points: 0, // updated by worker
      points7days: 0, // updated by worker
      points30days: 0, // updated by worker
      points365days: 0, // updated by worker
      role: role,
      securityToken: '',
      flagsCreated: [], // updated by worker
      locationsCreated: 0, // updated by worker
      postsCreated: 0, // updated by worker
      locationsClassified: 0, // updated by worker
      commentsCreated: 0, // updated by worker
    }, (qerr) => {
      if (qerr) {
        return callback(qerr);
      }
      // User inserted successfully
      return callback();
    });<commit_msg>replace deprecated collection.insert with .insertOne<commit_after>
const config = require('georap-config');
const db = require('georap-db');
const bcrypt = require('bcryptjs');

module.exports = function (userParams, callback) {
  // Create user account. Does not check if user exists.
  //
  // Parameters:
  //   userParams
  //     name
  //       string
  //     email
  //       string
  //     password
  //       string
  //     role
  //       string, optional
  //   callback
  //     function (err)
  //
  const users = db.collection('users');

  const username = userParams.name;
  const email = userParams.email;
  const password = userParams.password;
  const r = config.bcrypt.rounds;
  const role = userParams.role ? userParams.role : config.defaultRole;

  bcrypt.hash(password, r, (berr, pwdHash) => {
    if (berr) {
      return callback(berr);
    }

    const now = (new Date()).toISOString();

    users.insertOne({
      createdAt: now,
      deleted: false,
      email: email,
      hash: pwdHash,
      loginAt: now,
      name: username,
      points: 0, // updated by worker
      points7days: 0, // updated by worker
      points30days: 0, // updated by worker
      points365days: 0, // updated by worker
      role: role,
      securityToken: '',
      flagsCreated: [], // updated by worker
      locationsCreated: 0, // updated by worker
      postsCreated: 0, // updated by worker
      locationsClassified: 0, // updated by worker
      commentsCreated: 0, // updated by worker
    }, (qerr) => {
      if (qerr) {
        return callback(qerr);
      }
      // User inserted successfully
      return callback();
    });
{'fraction_non_alphanumeric': 0.12224938875305623, 'fraction_numerical': 0.008557457212713936, 'mean_word_length': 2.1440922190201728, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4722480', 'n_tokens_mistral': 983, 'n_tokens_neox': 951, 'n_words': 282}