<commit_before>var promise = require('bluebird');

var options = {
  promiseLib: promise
};

var pgp = require('pg-promise')(options);
var connectionString = 'postgres://localhost:5432/todos';
var db = pgp(connectionString);

module.exports = {
  getAllTodos: getAllTodos,
  getTodo: getTodo,
  addTodo: addTodo,
  updateTodo: updateTodo,
  removeTodo: removeTodo
};

function getAllTodos(req, res, next) {
  db.any('select * from items')
    .then(function (data) {
      res.status(200)
        .json({
          status: 'success',
          data: data,
          message: 'Retrieved all items'
        });
    })
    .catch(function (err) {
      return next(err);
    });
}

function getTodo(req, res, next) {
  var itemID = parseInt(req.params.id);
  db.one('select * from items where id = $1', itemID)
    .then(function (data) {
      res.status(200)
        .json({
          status: 'success',
          data: data,
          message: 'Retrieved one item'
        });
    })
    .catch(function (err) {
      return next(err);
    });
}

function addTodo(req, res, next) {
  req.body.position = parseInt(req.body.position);
  req.body.dotime = parseInt(req.body.dotime);
  req.body.done = (req.body.done == 'true');
  console.log("req.body", req);
  db.none('insert into items(position, item, dotime, done)' +
      'values(${position}, ${item}, ${dotime}, ${done})', req.body)
    .then(function () {
      res.status(200)
        .json({
          status: 'success',
          message: 'Inserted one item'
        });
    })
    .catch(function (err) {
      return next(err);
    });
}

function updateTodo(req, res, next) {
  req.body.position = parseInt(req.body.position);
  req.body.dotime = parseInt(req.body.dotime);
  req.body.done = (req.body.done == 'true');
  db.none('update items set position=$1, item=$2, dotime=$3, done=$4 where id=$5', [req.body.position, req.body.item, req.body.dotime, req.body.done, parseInt(req.params.id)])
      .then(function () {
        res.status(200)
          .json({
            status: 'success',
            message: 'Updated item'
          });
      })
      .catch(function (err) {
        return next(err);
      });
}
<commit_msg>change getAllTodos function to Max's suggested method<commit_after>var promise = require('bluebird');

var options = {
  promiseLib: promise
};

var pgp = require('pg-promise')(options);
var connectionString = 'postgres://localhost:5432/todos';
var db = pgp(connectionString);

module.exports = {
  getAllTodos: getAllTodos,
  getTodo: getTodo,
  addTodo: addTodo,
  updateTodo: updateTodo,
  removeTodo: removeTodo
};

function getAllTodos() {
  return db.any('select * from items')
}

function getTodo(req, res, next) {
  var itemID = parseInt(req.params.id);
  db.one('select * from items where id = $1', itemID)
    .then(function (data) {
      res.status(200)
        .json({
          status: 'success',
          data: data,
          message: 'Retrieved one item'
        });
    })
    .catch(function (err) {
      return next(err);
    });
}

function addTodo(req, res, next) {
  req.body.position = parseInt(req.body.position);
  req.body.dotime = parseInt(req.body.dotime);
  req.body.done = (req.body.done == 'true');
  console.log("req.body", req);
  db.one('insert into items(position, item, dotime, done)' +
      'values(${position}, ${item}, ${dotime}, ${done}) returning id', req.body)
    .then(function (result) {
      res.status(200)
        .json({
          status: 'success',
          message: `${result.id}`
        });
    })
    .catch(function (err) {
      return next(err);
    });
}

function updateTodo(req, res, next) {
  req.body.position = parseInt(req.body.position);
  req.body.dotime = parseInt(req.body.dotime);
  req.body.done = (req.body.done == 'true');
  db.none('update items set position=$1, item=$2, dotime=$3, done=$4 where id=$5', [req.body.position, req.body.item, req.body.dotime, req.body.done, parseInt(req.params.id)])
      .then(function () {
        res.status(200)
          .json({
            status: 'success',
            message: 'Updated item'
          });
      })
      .catch(function (err) {
        return next(err);
      });
}

{'fraction_non_alphanumeric': 0.16750059566356923, 'fraction_numerical': 0.00976888253514415, 'mean_word_length': 2.6824561403508773, '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': '1109803', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1435, 'n_words': 298}