<commit_before>function LevelService(Restangular) {

  var service = {};

  service.getLevels = function(opts = {}) {
    opts.embedded = angular.toJson({
      statistics: 1
    });
    return Restangular.all('levels').getList(opts || {});
  };

  service.getOrganizationLevel = function(organization, level) {
    return Restangular.all('organization-levels')
      .getList({
        where: angular.toJson({
          organization: organization._id,
          level: level._id
        })
      })
      .then(function(orgLevels) {
        return orgLevels[0] || {};
      });
  }

  service.getLevelsByOrganizationId = function(orgId, opts) {

    opts = opts || {};
    opts.embedded = JSON.stringify({
        level: 1
    });
    opts.where = opts.where || {};
    opts.where.organization = orgId;

    return Restangular.all('organization-levels').getList(opts || {})
      .then(function(orgLevels) {
        var levels = [];

        _.forEach(orgLevels, function(orgLevel) {
          levels.push(orgLevel.level);
        });

        return levels;
      });
  };

  // takes an object with a level attribute containing the level ID
  service.getLevelInstances = function(opts) {
    opts = opts || {};
    opts.embedded = JSON.stringify({
      server: 1
    });

    return Restangular.all('level-instances').getList(opts);
  };

  service.buyLevelbyOrganizationId = function(levelId, orgId, opts) {
    return Restangular.all('organization-levels').post({
      organization: orgId,
      level: levelId
    });
  };

  service.getLevel = function(levelId) {
    return Restangular.one('levels', levelId).get({
      embedded: angular.toJson({
        statistics: 1
      })
    })
      .then(function(response) {
        return response.data;
      });
  };

  return service;

}

angular
  .module('portal.levels')
  .factory('LevelService', LevelService);
<commit_msg>Adding Session filter to get levels<commit_after>function LevelService(Restangular) {

  var service = {};

  service.getLevelsBySessionId = function(sessionId, opts = {}) {

    opts.where = angular.toJson({
      'availability.sessions': sessionId
    });

    opts.embedded = angular.toJson({
      statistics: 1
    });
    
    return Restangular.all('levels').getList(opts || {});
  };

  service.getOrganizationLevel = function(organization, level) {
    return Restangular.all('organization-levels')
      .getList({
        where: angular.toJson({
          organization: organization._id,
          level: level._id
        })
      })
      .then(function(orgLevels) {
        return orgLevels[0] || {};
      });
  }

  service.getLevelsByOrganizationId = function(orgId, opts) {

    opts = opts || {};
    opts.embedded = JSON.stringify({
        level: 1
    });
    opts.where = opts.where || {};
    opts.where.organization = orgId;

    return Restangular.all('organization-levels').getList(opts || {})
      .then(function(orgLevels) {
        var levels = [];

        _.forEach(orgLevels, function(orgLevel) {
          levels.push(orgLevel.level);
        });

        return levels;
      });
  };

  // takes an object with a level attribute containing the level ID
  service.getLevelInstances = function(opts) {
    opts = opts || {};
    opts.embedded = JSON.stringify({
      server: 1
    });

    return Restangular.all('level-instances').getList(opts);
  };

  service.buyLevelbyOrganizationId = function(levelId, orgId, opts) {
    return Restangular.all('organization-levels').post({
      organization: orgId,
      level: levelId
    });
  };

  service.getLevel = function(levelId) {
    return Restangular.one('levels', levelId).get({
      embedded: angular.toJson({
        statistics: 1
      })
    })
      .then(function(response) {
        return response.data;
      });
  };

  return service;

}

angular
  .module('portal.levels')
  .factory('LevelService', LevelService);

{'fraction_non_alphanumeric': 0.14106502816180236, 'fraction_numerical': 0.002560163850486431, 'mean_word_length': 2.600921658986175, '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': '7557615', 'n_tokens_mistral': 1204, 'n_tokens_neox': 1133, 'n_words': 208}