<commit_before>var config = require('../../../config');
var dataStore = require('nedb');

function getConnectionOptions(nameCollection) {
  return  {
    filename: '../db/' +config.db.name + '/'+nameCollection,
    autoload: true,
    inMemoryOnly: false
  };
};

function getIndexOption(field, uniqueOption, sparseOption) {
  var option = {
    fieldName: field
    ,unique: uniqueOption
    ,sparse: sparseOption
  }
  return option;
}

var collection = new dataStore(getConnectionOptions("users"));
collection.ensureIndex(getIndexOption("email", true, false));

module.exports.findAllUsersWithoutPassword = function (admin, callback) {
  if(admin) {
    collection.find({ }, { password: 0 }, function (err, users) {
      callback(err, users);
    })
  } else {
    collection.find({ $or: [ {removed: { $exists: false } }, { not: { removed: true } } ] }, { password: 0 }, function (err, users) {
      callback(err, users);
    })
  }
}

module.exports.findUserByEmailWithoutPassword = function (userEmail, admin, callback) {
  if(admin) {
    collection.findOne({ email: userEmail }, 
    { password: 0 },
    function (err, findedUser) {
      callback(err, findedUser);
    }); 
  } else {
    collection.findOne({$and: [ { email: userEmail } , {$or: [ {removed: { $exists: false } }, { not: { removed: true } } ]} ]}, 
                       { password: 0 }, function (err, findedUser) {
      callback(err, findedUser);
    }); 
  }
};

module.exports.findUserByIdWithoutPassword = function (id, admin, callback) {
  if(admin) {
    collection.findOne({ id: id }, 
    { password: 0 }, function (err, findedUser) {<commit_msg>Показ статусов администраторов только администраторам.<commit_after>var config = require('../../../config');
var dataStore = require('nedb');

function getConnectionOptions(nameCollection) {
  return  {
    filename: '../db/' +config.db.name + '/'+nameCollection,
    autoload: true,
    inMemoryOnly: false
  };
};

function getIndexOption(field, uniqueOption, sparseOption) {
  var option = {
    fieldName: field
    ,unique: uniqueOption
    ,sparse: sparseOption
  }
  return option;
}

var collection = new dataStore(getConnectionOptions("users"));
collection.ensureIndex(getIndexOption("email", true, false));

module.exports.findAllUsersWithoutPassword = function (admin, callback) {
  if(admin) {
    collection.find({ }, { password: 0 }, function (err, users) {
      callback(err, users);
    })
  } else {
    collection.find({ $or: [ {removed: { $exists: false } }, { not: { removed: true } } ] }, 
    { password: 0, isAdministrator : 0 }, function (err, users) {
      callback(err, users);
    })
  }
}

module.exports.findUserByEmailWithoutPassword = function (userEmail, admin, callback) {
  if(admin) {
    collection.findOne({ email: userEmail }, 
    { password: 0 },
    function (err, findedUser) {
      callback(err, findedUser);
    }); 
  } else {
    collection.findOne({$and: [ { email: userEmail } , {$or: [ {removed: { $exists: false } }, { not: { removed: true } } ]} ]}, 
                       { password: 0 }, function (err, findedUser) {
      callback(err, findedUser);
    }); 
  }
};

module.exports.findUserByIdWithoutPassword = function (id, admin, callback) {
  if(admin) {
    collection.findOne({ id: id }, 
    { password: 0 }, function (err, findedUser) {
{'fraction_non_alphanumeric': 0.15922038980509745, 'fraction_numerical': 0.003298350824587706, 'mean_word_length': 3.389473684210526, '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': '2100846', 'n_tokens_mistral': 1049, 'n_tokens_neox': 1032, 'n_words': 236}