<commit_before>var joi = require('joi');

var productData = [
  {
    id: 1,
    company: 2,
    name: '<NAME>',
    description: 'Lorem Foo Wax dolor sit amet, consectetur adipisicing elit. Perspiciatis ullam consequuntur velit quibusdam non laboriosam porro Foo eos provident ab eum, wax Foo, rem unde quos sapiente natus eaque voluptatibus!'
  },
  {
    id: 2,
    company: 1,
    name: '<NAME>',
    description: 'Bacon ipsum dolor amet beef shank alcatra pork belly sausage kielbasa hamburger pastrami spare ribs pig kevin. Shoulder hamburger biltong, jowl tenderloin doner shankle andouille salami meatball drumstick frankfurter tongue t-bone. Capicola venison cupim, kevin picanha ribeye sausage tongue beef ribs bacon alcatra jerky rump shankle.'
  },
  {
    id: 3,
    company: 4,
    name: '<NAME>',
    description: 'Porchetta ball tip pastrami swine cupim meatloaf chuck sirloin meatball pancetta fatback. Boudin brisket sirloin jowl strip steak fatback turkey doner.'
  },
  {
    id: 4,
    company: 18,
    name: '<NAME>',
    description: 'Deserunt eu id pork chop nisi consequat in commodo flank pork. Doner fugiat corned beef jerky, filet mignon ground round ut short ribs meatloaf nisi.'
  }
];

// Schema for validating new products
var productSchema = joi.object().keys({
  name: joi.string().alphanum().min(3).max(30).required(),
  description: joi.string().min(15).required()
})

var lastId = productData.length;
var getNextId = function() {
  lastId++;
  return lastId;
};

module.exports = function(app, express) {
  var router = express.Router();

  /**
   * Fetch a product by id when :id url param is given
   */
  router.param('product_id', function(req, res, next, id) {
      var i = 0;
      var len = productData.length;
      id = Number(id); // Route params are strings

      for (; i < len; i++) {
        if (productData[i].id === id) {
          req.product = productData[i];
          return next();
        }
      }

      // No product has been found, so it must not exist
      res.status(404)
        .send('Product ' + id + ' not found');<commit_msg>Fix product model validation<commit_after>var joi = require('joi');

var productData = [
  {
    id: 1,
    company: 2,
    name: '<NAME>',
    description: 'Lorem Foo Wax dolor sit amet, consectetur adipisicing elit. Perspiciatis ullam consequuntur velit quibusdam non laboriosam porro Foo eos provident ab eum, wax Foo, rem unde quos sapiente natus eaque voluptatibus!'
  },
  {
    id: 2,
    company: 1,
    name: '<NAME>',
    description: 'Bacon ipsum dolor amet beef shank alcatra pork belly sausage kielbasa hamburger pastrami spare ribs pig kevin. Shoulder hamburger biltong, jowl tenderloin doner shankle andouille salami meatball drumstick frankfurter tongue t-bone. Capicola venison cupim, kevin picanha ribeye sausage tongue beef ribs bacon alcatra jerky rump shankle.'
  },
  {
    id: 3,
    company: 4,
    name: '<NAME>',
    description: 'Porchetta ball tip pastrami swine cupim meatloaf chuck sirloin meatball pancetta fatback. Boudin brisket sirloin jowl strip steak fatback turkey doner.'
  },
  {
    id: 4,
    company: 18,
    name: '<NAME>',
    description: 'Deserunt eu id pork chop nisi consequat in commodo flank pork. Doner fugiat corned beef jerky, filet mignon ground round ut short ribs meatloaf nisi.'
  }
];

// Schema for validating new products
var productSchema = joi.object().unknown().keys({
  name: joi.string().regex(/^(\w|\s)*$/).min(3).max(30).required(),
  description: joi.string().min(15).required()
});

var lastId = productData.length;
var getNextId = function() {
  lastId++;
  return lastId;
};

module.exports = function(app, express) {
  var router = express.Router();

  /**
   * Fetch a product by id when :id url param is given
   */
  router.param('product_id', function(req, res, next, id) {
      var i = 0;
      var len = productData.length;
      id = Number(id); // Route params are strings

      for (; i < len; i++) {
        if (productData[i].id === id) {
          req.product = productData[i];
          return next();
        }
      }

      // No product has been found, so it must not exist
      res.status(404)
        .send('Product ' + id + ' not found');
{'fraction_non_alphanumeric': 0.11013944693925785, 'fraction_numerical': 0.008508626802174428, 'mean_word_length': 3.128780487804878, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4860605', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1363, 'n_words': 476}