<commit_before>const express = require('express');
const _ = require('lodash');
const queries = require('../../db/queries');

const router = express.Router();

router.get('/', (req, res, next) => {
  queries.getAllExample()
    .then(result => res.status(200).json(result))
    .catch(error => next(error));
});

router.get('/:id', (req, res, next) => {
  queries.getExampleById(req.params.id)
    .then(result => res.status(200).json(result))
    .catch(error => next(error));
});

router.post('/', (req, res, next) => {
  queries.addExample(req.body)
    .then(id => queries.getExampleById(id))
    .then(result => res.status(200).json(result))
    .catch(error => next(error));
});

router.put('/:id', (req, res, next) => {
  if (_.has(req.body, 'id')) {
    return res.status(400).json({
      error: 'Id field cannot be updated',
    });
  }

  return queries.update(req.params.id, req.body)
    .then(() => queries.getExampleById(req.params.id))
    .then(result => res.status(200).json(result))
    .catch(error => next(error));
});

router.delete('/:id', (req, res, next) => {
  queries.deleteExample(req.params.id)
    .then(result => res.status(200).json(result))
    .catch(error => next(error));
});

module.exports = router;
<commit_msg>Fix tests<commit_after>const express = require('express');
const _ = require('lodash');
const queries = require('../../db/queries');

const router = express.Router();

router.get('/', (req, res, next) => {
  queries.getAllExample()
    .then(result => res.status(200).json(result))
    .catch(error => next(error));
});

router.get('/:id', (req, res, next) => {
  queries.getExampleById(req.params.id)
    .then(result => res.status(200).json(result))
    .catch(error => next(error));
});

router.post('/', (req, res, next) => {
  queries.addExample(req.body)
    .then(id => queries.getExampleById(id))
    .then(result => res.status(200).json(result))
    .catch(error => next(error));
});

router.put('/:id', (req, res, next) => {
  if (_.has(req.body, 'id')) {
    return res.status(400).json({
      error: 'Id field cannot be updated',
    });
  }

  return queries.updateExample(req.params.id, req.body)
    .then(() => queries.getExampleById(req.params.id))
    .then(result => res.status(200).json(result))
    .catch(error => next(error));
});

router.delete('/:id', (req, res, next) => {
  queries.deleteExample(req.params.id)
    .then(result => res.status(200).json(result))
    .catch(error => next(error));
});

module.exports = router;

{'fraction_non_alphanumeric': 0.22532960447463043, 'fraction_numerical': 0.014382740711146624, 'mean_word_length': 3.852713178294574, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 37, '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': '2612303', 'n_tokens_mistral': 889, 'n_tokens_neox': 868, 'n_words': 153}