<commit_before>var models = require('../db/models.js');
var util = require('../core/utilities.js');
module.exports = function(router) {

  //{x: float, y: float, z: float}
  router.get('/messages', function (req, res) {
    util.log('RECEIVED a GET request', req.query);
    models.retrieveMarks(req.query)
      .then(function(msg) {
        util.log('SENT message array to user', msg);
        res.status(200);
        res.send(msg);
      }, function(err) {
        util.log('SENT error code to user', err);
        res.sendStatus(400);
      });
  });

  //{messageId: string}
  router.get('/comment', function(req, res) {
    util.log('RECEIVED a GET request', req.query);
    models.retrieveComments(+req.query.messageId)
      .then(function(comments) {
        util.log('SENT comments to user', comments);
        res.status(200);
        res.send(comments);
      }, function(err) {
        util.log('SENT error code to user', err);
        res.sendStatus(400);
      });
  });
};
<commit_msg>Refactor duplicate GET requests code<commit_after>var models = require('../db/models.js');
var util = require('../core/utilities.js');

var reject = function(req, res, err) {
  util.log('RECEIVED a GET request', req.query);
  util.log('SENT error code to user', err);
  res.sendStatus(400);
};

var resolve = function(req, res, success) {
  util.log('RECEIVED a GET request', req.query);
  util.log('SENT successful response to user', success);
  res.status(200);
  res.send(success);
};

module.exports = function(router) {

  //{x: float, y: float, z: float}
  router.get('/messages', function (req, res) {
    models.retrieveMarks(req.query).then(
          resolve.bind(this, req, res),
          reject.bind(this, req, res)
          );
  });

  //{messageId: string}
  router.get('/comment', function(req, res) {
    models.retrieveComments(req.query.messageId).then(
          resolve.bind(this, req, res),
          reject.bind(this, req, res)
          );
  });
};

{'fraction_non_alphanumeric': 0.17459514170040485, 'fraction_numerical': 0.009109311740890687, 'mean_word_length': 2.930417495029821, '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': '328745', 'n_tokens_mistral': 666, 'n_tokens_neox': 646, 'n_words': 144}