<commit_before>var async = require('async');
var _ = require('lodash');
var logger = require('../../lib/logger.lib');
var usersModel = require('../models/users.model');
var rolesModel = require('../models/roles.model');

/**
 * 用户列表
 * @param {Object} options
 *        {String} options.type
 * @param callback
 */
exports.list = function (options, callback) {
  var query = {};

  if (options.type) query.type = options.type;

  usersModel.find(query)
    .select('type nickname email role')
    .populate('role', 'name description authorities')
    .lean()
    .exec(function (err, users) {
      if (err) {
        err.type = 'database';
        return callback(err);
      }

      callback(null, users);
    });
};

/**
 * 查询用户
 * @param {Object} options
 *        {String} options.email
 *        {MongoId} options._id
 *        {Boolean} options.selectPassword
 * @param callback
 */
exports.one = function (options, callback) {
  var selectPassword = options.selectPassword || false;

  var query = {};

  if (options.email) query.email = options.email;
  if (options._id) query._id = options._id;

  usersModel.findOne(query)
    .select('type nickname email password role')
    .populate('role', 'name description authorities')
    .lean()
    .exec(function (err, user) {
      if (err) {
        err.type = 'database';
        return callback(err);
      }

      if (!user) return callback();

      if (!selectPassword) {
        delete user.password;
      }

      callback(null, user);
    });
};

/**
 * 存储用户
 * @param {Object} options
 *        {MongoId} options._id
 *        {Object} options.data
 * @param {Function} callback<commit_msg>auto<commit_after>var async = require('async');
var _ = require('lodash');
var logger = require('../../lib/logger.lib');
var usersModel = require('../models/users.model');
var rolesModel = require('../models/roles.model');

/**
 * 用户列表
 * @param {Object} options
 *        {String} options.type
 * @param callback
 */
exports.list = function (options, callback) {
  var query = {};

  if (options.type) query.type = options.type;

  usersModel.find(query)
    .select('type nickname email role')
    .populate('role', 'name description authorities')
    .lean()
    .exec(function (err, users) {
      if (err) {
        err.type = 'database';
        return callback(err);
      }

      callback(null, users);
    });
};

/**
 * 查询用户
 * @param {Object} options
 *        {String} options.email
 *        {MongoId} options._id
 *        {Boolean} options.selectPassword
 * @param callback
 */
exports.one = function (options, callback) {
  var selectPassword = options.selectPassword || false;

  var query = {};

  if (options.email) query.email = options.email;
  if (options._id) query._id = options._id;

  console.log(JSON.stringify(query))
  usersModel.findOne(query)
    .select('type nickname email password role')
    .populate('role', 'name description authorities')
    .lean()
    .exec(function (err, user) {
      if (err) {
        err.type = 'database';
        return callback(err);
      }

      if (!user) return callback();

      if (!selectPassword) {
        delete user.password;
      }

      callback(null, user);
    });
};

/**
 * 存储用户
 * @param {Object} options
 *        {MongoId} options._id
 *        {Object} options.data
 * @param {Function} callback
{'fraction_non_alphanumeric': 0.15839808726838014, 'fraction_numerical': 0.0, 'mean_word_length': 2.686123348017621, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5028202', 'n_tokens_mistral': 1043, 'n_tokens_neox': 1026, 'n_words': 248}