<commit_before>var _ = require('underscore'),
    q = require('q');

var Service = require('../models/service'),
    User = require('../models/user');

var ServiceRoute = {
  add: function (req, res) {
    Service.add(req.user, req.body, function (err, service) {
      if (err) { return res.json(400, err); }
      return res.json(service);
    });
  },

  list: function (req, res) {
    Service.all(req.user, function (err, services) {
      if (err) { return res.json(400, err); }

      var actions = _.chain(services)
        .map(function (service) { return service.user; })
        .uniq()
        .map(function (id) { return q.nfcall(User.findOne.bind(User), { _id: id }); })
        .value();
      q.all(actions).then(function (users) {
        var output = [];
        var userMap = _.groupBy(users, 
          function (user) {
            return user._id;
          });
        _.each(services, function (service) {
          var json = service.toJSON();
          json.user = userMap[service.user][0];
          output.push(json);
        });

        return res.json(output);        
      });
    });
  },

  update: function (req, res) {
    var serviceID = req.param('id');
    console.log (serviceID);
    console.log (req.body);
    res.send('Hello, World');
  }

};

(function () {
  module.exports = ServiceRoute;
})();<commit_msg>Use new service update function in route.<commit_after>var _ = require('underscore'),
    q = require('q');

var Service = require('../models/service'),
    User = require('../models/user');

var ServiceRoute = {
  add: function (req, res) {
    Service.add(req.user, req.body, function (err, service) {
      if (err) { return res.json(400, err); }
      return res.json(service);
    });
  },

  list: function (req, res) {
    Service.all(req.user, function (err, services) {
      if (err) { return res.json(400, err); }

      var actions = _.chain(services)
        .map(function (service) { return service.user; })
        .uniq()
        .map(function (id) { return q.nfcall(User.findOne.bind(User), { _id: id }); })
        .value();
      q.all(actions).then(function (users) {
        var output = [];
        var userMap = _.groupBy(users, 
          function (user) {
            return user._id;
          });
        _.each(services, function (service) {
          var json = service.toJSON();
          json.user = userMap[service.user][0];
          output.push(json);
        });

        return res.json(output);        
      });
    });
  },

  update: function (req, res) {
    var serviceID = req.param('id');

    Service.update(serviceID, req.body, function (err, service) {
      if (err) { return res.json(400, err); }
      return res.json(service);
    });
  }

};

(function () {
  module.exports = ServiceRoute;
})();
{'fraction_non_alphanumeric': 0.17201998572448252, 'fraction_numerical': 0.006067094932191292, 'mean_word_length': 2.2404624277456646, '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': '6391521', 'n_tokens_mistral': 900, 'n_tokens_neox': 876, 'n_words': 198}