<commit_before>'use strict';

var router = require('express').Router();
var Product = require('glut-models').models.Product;
var cors = require('cors');
var security = require('../security');

router.get('/', cors(), function(req, res) {
  Product.find({}).lean().exec()
  .then(function(docs) {
    res.json(docs);
  })
  .catch(function(err) {
    res.status(500).send('server error');
  });
});

router.post('/', cors(), security.auth(), security.authAdmin(), function(req, res) {
  var product = new Product(req.body);
  product.save()
  .then(function(doc, numAffected) {
    res.json({ product: doc, numAffected: numAffected });
  })
  .catch(function(err) {
    res.status(500).send('server error');
  });
});

router.put('/:id', cors(), security.auth(), security.authAdmin(), function(req, res) {
  Product.findOneAndUpdate({
    $or: [
      { _id: req.params.id },
      { upc: req.params.id }
    ]
  }, req.body).exec()
  .then(function(doc) {
    res.json({ product: doc });
  })
  .catch(function(err) {
    res.status(500).send('server error');
  });
});

router.delete('/:id', cors(), security.auth(), security.authAdmin(), function(req, res) {
  Product.findOneAndRemove({
    $or: [
      { _id: req.params.id },
      { upc: req.params.id }
    ]
  }, req.body).exec()
  .then(function(doc) {
    res.json({ product: doc });
  })
  .catch(function(err) {
    res.status(500).send('server error');
  });
});

module.exports = router;<commit_msg>fixed delete<commit_after>'use strict';

var router = require('express').Router();
var Product = require('glut-models').models.Product;
var cors = require('cors');
var security = require('../security');

router.get('/', cors(), function(req, res) {
  Product.find({}).lean().exec()
  .then(function(docs) {
    res.json(docs);
  })
  .catch(function(err) {
    res.status(500).send('server error');
  });
});

router.post('/', cors(), security.auth(), security.authAdmin(), function(req, res) {
  var product = new Product(req.body);
  product.save()
  .then(function(doc, numAffected) {
    res.json({ product: doc, numAffected: numAffected });
  })
  .catch(function(err) {
    res.status(500).send('server error');
  });
});

router.put('/:id', cors(), security.auth(), security.authAdmin(), function(req, res) {
  Product.findOneAndUpdate({
    $or: [
      { _id: req.params.id },
      { upc: req.params.id }
    ]
  }, req.body).exec()
  .then(function(doc) {
    res.json({ product: doc });
  })
  .catch(function(err) {
    res.status(500).send('server error');
  });
});

router.delete('/:id', cors(), security.auth(), security.authAdmin(), function(req, res) {
  Product.findOneAndRemove({
    $or: [
      { _id: req.params.id },
      { upc: req.params.id }
    ]
  }).exec()
  .then(function(doc) {
    res.json({ product: doc });
  })
  .catch(function(err) {
    res.status(500).send('server error');
  });
});

module.exports = router;
{'fraction_non_alphanumeric': 0.22229845626072042, 'fraction_numerical': 0.00823327615780446, 'mean_word_length': 3.5849056603773586, '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': '3995049', 'n_tokens_mistral': 1036, 'n_tokens_neox': 1012, 'n_words': 174}