<commit_before>'use strict';

var async = require('async');

module.exports = function(options){
  var seneca = this;
  var plugin = 'cd-agreements';
  var ENTITY_NS = 'cd/agreements';

  seneca.add({role: plugin, cmd: 'get_agreements'}, cmd_get_agreements);

  function cmd_get_agreements(args, done){
    var seneca = this, usersIds = [], agreements_ent;

    usersIds = args.usersIds;
    
    if(!usersIds || !usersIds.length > 0){
      done("An error occurred");
    }

    agreements_ent =  seneca.make(ENTITY_NS);
    
    function get_agreement(id, cb){
      var agreements_ent =  seneca.make(ENTITY_NS);

      agreements_ent.list$({userId: id}, function(err, agreement){
        if(err){
          return cb(err);
        }

        return cb(null, agreement[0]);
      });
    }

    async.mapSeries(usersIds, get_agreement, function(err, results){
      if(err){
        return done(err);
      }

      return done(null, results);
    });

  }

  return {
    name: plugin
  };<commit_msg>Add count method<commit_after>'use strict';

var async = require('async');

module.exports = function(options){
  var seneca = this;
  var plugin = 'cd-agreements';
  var ENTITY_NS = 'cd/agreements';

  seneca.add({role: plugin, cmd: 'get_agreements'}, cmd_get_agreements);
  seneca.add({role: plugin, cmd: 'count'}, cmd_count);

  function cmd_get_agreements(args, done){
    var seneca = this, usersIds = [], agreements_ent;

    usersIds = args.usersIds;
    
    if(!usersIds || !usersIds.length > 0){
      done("An error occurred");
    }

    agreements_ent =  seneca.make(ENTITY_NS);
    
    function get_agreement(id, cb){
      var agreements_ent =  seneca.make(ENTITY_NS);

      agreements_ent.list$({userId: id}, function(err, agreement){
        if(err){
          return cb(err);
        }

        return cb(null, agreement[0]);
      });
    }

    async.mapSeries(usersIds, get_agreement, function(err, results){
      if(err){
        return done(err);
      }

      return done(null, results);
    });

  }

  function cmd_count(args, done){
    var seneca = this, query = {};

    query = args.query ? args.query : {};
    query.limit$ = query.limit$ ? query.limit$ : 'NULL';

    seneca.make(ENTITY_NS).list$(query, function(err, agreements){
      if(err){
        return done(err);
      }

      var noOfAgreements = agreements.length;

      done(null, {noOfAgreements: noOfAgreements});
    });
  }

  return {
    name: plugin
  };
{'fraction_non_alphanumeric': 0.14279918864097363, 'fraction_numerical': 0.0016227180527383367, 'mean_word_length': 2.8173374613003097, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '708541', 'n_tokens_mistral': 837, 'n_tokens_neox': 798, 'n_words': 169}