<commit_before>(function($, angular) {

  var Movement = function() {
    this.date = moment();
    this.executionDate = moment();
    this.bankId = null;
    this.description = null;
    this.direction = null;
    this.amount = 0;

    // links
    this.account = null;
    this.category = null;
    this.source = null;
    this.sourceMovement = null; // link to the inverse movement in the source account
    this.destination = null;
    this.destinationMovement = null; // link to the inverse movement in the destination account
  };
  Movement.DIRECTION_IN = 'in';
  Movement.DIRECTION_OUT = 'out';

  var CategoriesRepository = function(Restangular) {
    this.all = [];

    var repo = this;
    this.loaded = Restangular.all('categories').getList({sort_by: 'name'}).then(function(categories) {
      // index categories by id
      var catById = {};
      _.each(categories, function(category) {
        catById[category._id] = category;
      });
      repo.all = catById;
    });
  };
  CategoriesRepository.$inject = ['Restangular'];
  CategoriesRepository.prototype.find = function(id) {
    return _.find(this.all, {_id: id});
  };

  var AccountsRepository = function(Restangular) {
    this.bankAccounts = [];
    this.people = [];
    this.all = [];
    this.moneyAccount = {
      _id: 'money',
      name: 'Contanti',
      avatarUrl: 'images/money.jpg'
    };

    var repo = this;
    this.loaded = Restangular.all('accounts').getList().then(function(accounts) {
      repo.all = accounts;
      _.each(accounts, function(account) {
        if ('bank_account' === account.type) {
          repo.bankAccounts.push(account);
        } else if ('person' === account.type) {
          repo.people.push(account);
        }
      });
    });
  };
  AccountsRepository.$inject = ['Restangular'];
  AccountsRepository.prototype.findByName = function(name) {
    return _.find(this.all, {name: name});
  };
  AccountsRepository.prototype.find = function(id) {
    return _.find(this.all, {'_id': id});
  };

  /**
   * Stores the list of all movements, sorted by date ASC.
   * Retrieves the list on creation, can be updated via "add" and "remove".
   *
   * @param $q
   * @param Restangular
   * @param CategoriesRepository
   * @param AccountsRepository
   * @constructor
   */
  var MovementsRepository = function($q, Restangular, CategoriesRepository, AccountsRepository) {
    this.$q = $q;
    this.all = [];
    this.movementsEndpoint = Restangular.all('movements');

    // load movements only after accounts and categories
    var repo = this;
    this.loaded = $q.all([CategoriesRepository.loaded, AccountsRepository.loaded]).then(function() {
      repo.movementsEndpoint.getList({pagesize: 1000}/*{filter: {hidden: false}}*/).then(function(movements) {
        repo.all = _.sortBy(movements, function(movement) {
          return movement.date.toISOString();
        });
      });
    });
  };
  MovementsRepository.$inject = ['$q', 'Restangular', 'CategoriesRepository', 'AccountsRepository'];

  /**
   * Append to movements
   *
   * @param movements
   */
  MovementsRepository.prototype.add = function(movements) {
    if (!_.isArray(movements)) {
      movements = [movements];
    }
    var repo = this;
    var movementsEndpoint = this.movementsEndpoint;
    var promises = _.map(movements, function(movement) {
      return movementsEndpoint.post(movement);<commit_msg>Add filter for logically deleted records.<commit_after>(function($, angular) {

  var Movement = function() {
    this.date = moment();
    this.executionDate = moment();
    this.bankId = null;
    this.description = null;
    this.direction = null;
    this.amount = 0;
    this.deleted = false;

    // links
    this.account = null;
    this.category = null;
    this.source = null;
    this.sourceMovement = null; // link to the inverse movement in the source account
    this.destination = null;
    this.destinationMovement = null; // link to the inverse movement in the destination account
  };
  Movement.DIRECTION_IN = 'in';
  Movement.DIRECTION_OUT = 'out';

  var CategoriesRepository = function(Restangular) {
    this.all = [];

    var repo = this;
    this.loaded = Restangular.all('categories').getList({sort_by: 'name'}).then(function(categories) {
      // index categories by id
      var catById = {};
      _.each(categories, function(category) {
        catById[category._id] = category;
      });
      repo.all = catById;
    });
  };
  CategoriesRepository.$inject = ['Restangular'];
  CategoriesRepository.prototype.find = function(id) {
    return _.find(this.all, {_id: id});
  };

  var AccountsRepository = function(Restangular) {
    this.bankAccounts = [];
    this.people = [];
    this.all = [];
    this.moneyAccount = {
      _id: 'money',
      name: 'Contanti',
      avatarUrl: 'images/money.jpg'
    };

    var repo = this;
    this.loaded = Restangular.all('accounts').getList().then(function(accounts) {
      repo.all = accounts;
      _.each(accounts, function(account) {
        if ('bank_account' === account.type) {
          repo.bankAccounts.push(account);
        } else if ('person' === account.type) {
          repo.people.push(account);
        }
      });
    });
  };
  AccountsRepository.$inject = ['Restangular'];
  AccountsRepository.prototype.findByName = function(name) {
    return _.find(this.all, {name: name});
  };
  AccountsRepository.prototype.find = function(id) {
    return _.find(this.all, {'_id': id});
  };

  /**
   * Stores the list of all movements, sorted by date ASC.
   * Retrieves the list on creation, can be updated via "add" and "remove".
   *
   * @param $q
   * @param Restangular
   * @param CategoriesRepository
   * @param AccountsRepository
   * @constructor
   */
  var MovementsRepository = function($q, Restangular, CategoriesRepository, AccountsRepository) {
    this.$q = $q;
    this.all = [];
    this.movementsEndpoint = Restangular.all('movements');

    // load movements only after accounts and categories
    var repo = this;
    this.loaded = $q.all([CategoriesRepository.loaded, AccountsRepository.loaded]).then(function() {
      repo.movementsEndpoint.getList({pagesize: 1000, filter: {deleted: false}}).then(function(movements) {
        repo.all = _.sortBy(movements, function(movement) {
          return movement.date.toISOString();
        });
      });
    });
  };
  MovementsRepository.$inject = ['$q', 'Restangular', 'CategoriesRepository', 'AccountsRepository'];

  /**
   * Append to movements
   *
   * @param movements
   */
  MovementsRepository.prototype.add = function(movements) {
    if (!_.isArray(movements)) {
      movements = [movements];
    }
    var repo = this;
    var movementsEndpoint = this.movementsEndpoint;
    var promises = _.map(movements, function(movement) {
      return movementsEndpoint.post(movement);
{'fraction_non_alphanumeric': 0.13993871297242083, 'fraction_numerical': 0.0014592149423610099, 'mean_word_length': 3.008187134502924, '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': '466917', 'n_tokens_mistral': 2048, 'n_tokens_neox': 2012, 'n_words': 445}