<commit_before>let express = require('express');
let router = express.Router();
let ObjectId = require('mongodb').ObjectID;
let palindrome = require('../lib/palindrome');
let MESSAGE_SCHEMA = require('../models/message');
let validator = require('jsonschema').validate;
let dateFormat = require('dateformat');
let db = require('../db');
const MESSAGES_COLLECTION = 'messages';

// middleware to validate messages and enrich req with additional properties
router.use(function(req, res, next) {
  if (req.method == 'POST') {
    let message = req.body;
    let validatorResult = validator(message, MESSAGE_SCHEMA);

    // check if message validation is ok
    if (validatorResult.errors.length > 0) {
      res.status(400).send(validatorResult.errors[0].stack);
      return;
    } else { // add Date, length of text and is palindrome to req object
      let now = new Date();
      message.date = dateFormat(now, "dddd, mmmm dS, yyyy, h:MM:ss TT");
      message.length = message.text.length;
      message.isPalindrome = palindrome(message.text);
    }
  }

  next();
});

// GET all messages
router.get('/', function(req, res) {
  db.get().collection(MESSAGES_COLLECTION)
    .find({})
    .toArray(function(err, messages) {
      if (err) return err;

      res.json(messages);
  });
});

// GET specific a message based on the id
router.get('/:id', function(req, res) {
  let id = req.params.id;
  db.get().collection(MESSAGES_COLLECTION)<commit_msg>fixed lint erros<commit_after>let express = require('express');
let router = express.Router();
let ObjectId = require('mongodb').ObjectID;
let palindrome = require('../lib/palindrome');
let MESSAGE_SCHEMA = require('../models/message');
let validator = require('jsonschema').validate;
let dateFormat = require('dateformat');
let db = require('../db');
const MESSAGES_COLLECTION = 'messages';

// middleware to validate messages and enrich req with additional properties
router.use(function(req, res, next) {
  if (req.method == 'POST') {
    let message = req.body;
    let validatorResult = validator(message, MESSAGE_SCHEMA);

    // check if message validation is ok
    if (validatorResult.errors.length > 0) {
      res.status(400).send(validatorResult.errors[0].stack);
      return;
    } else { // add Date, length of text and is palindrome to req object
      let now = new Date();
      message.date = dateFormat(now, 'dddd, mmmm dS, yyyy, h:MM:ss TT');
      message.length = message.text.length;
      message.isPalindrome = palindrome(message.text);
    }
  }

  next();
});

// GET all messages
router.get('/', function(req, res) {
  db.get().collection(MESSAGES_COLLECTION)
    .find({})
    .toArray(function(err, messages) {
      if (err) return err;

      res.json(messages);
  });
});

// GET specific a message based on the id
router.get('/:id', function(req, res) {
  let id = req.params.id;
  db.get().collection(MESSAGES_COLLECTION)
{'fraction_non_alphanumeric': 0.14977670903469598, 'fraction_numerical': 0.0034352456200618343, 'mean_word_length': 3.719611021069692, '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': '2607060', 'n_tokens_mistral': 941, 'n_tokens_neox': 921, 'n_words': 241}