<commit_before>'use strict';

var conn = require('../dal/pgConnection.js');
var dal = require('../dal/watzdprice.js');
var elasticsearch = require('../dal/elasticsearch.js');

module.exports.getproductGET = function getproductGET (req, res, next) {
  if (req.swagger.params.apikey.value !== 'andre') {
    res.statusCode = 403;
    return res.end();
  } else {
    conn.execute(function (err, client, done) {
      if (err) {
        console.error('getproductGET - ' + JSON.stringify(req.swagger.params) + err.print());
        return next(err);
      }
      dal.getProduct(client, req.swagger.params.id.value, function (err, product) {
        if (err) {
          log.error('getproductGET - ' + JSON.stringify(req.swagger.params) + err.print());
          conn.rollback(client, done);
          return next(err);
        }

        conn.commit(client, done);
        res.statusCode = 200;
        return res.end(JSON.stringify({product: product}));
      });
    });
  }
};

module.exports.searchproductsGET = function searchproductsGET (req, res, next) {
  if (req.swagger.params.apikey.value !== 'andre') {
    res.statusCode = 403;
    return res.end();
  } else {
    var client = elasticsearch.startSession();
    elasticsearch.searchProducts(client, req.swagger.params.q.value, function (err, products) {
      if (err) {
        log.error('searchproductsGET - ' + JSON.stringify(req.swagger.params) + err.print());
        conn.rollback(client, done);
        return next(err);
      }

      res.statusCode = 200;
      return res.end(JSON.stringify({products: products}));
    });
  }
};<commit_msg>rework<commit_after>'use strict';

var conn = require('../dal/pgConnection.js');
var dal = require('../dal/watzdprice.js');
var elasticsearch = require('../dal/elasticsearch.js');

module.exports.getproductGET = function getproductGET (req, res, next) {
  if (req.swagger.params.apikey.value !== 'andre') {
    res.statusCode = 403;
    return res.end();
  } else {
    conn.execute(function (err, client, done) {
      if (err) {
        console.error('getproductGET - ' + JSON.stringify(req.swagger.params) + err.print());
        return next(err);
      }
      dal.getProduct(client, req.swagger.params.id.value, function (err, product) {
        if (err) {
          console.error('getproductGET - ' + JSON.stringify(req.swagger.params) + err.print());
          conn.rollback(client, done);
          return next(err);
        }

        conn.commit(client, done);
        res.statusCode = 200;
        return res.end(JSON.stringify({product: product}));
      });
    });
  }
};

module.exports.searchproductsGET = function searchproductsGET (req, res, next) {
  if (req.swagger.params.apikey.value !== 'andre') {
    res.statusCode = 403;
    return res.end();
  } else {
    var client = elasticsearch.startSession();
    elasticsearch.searchProducts(client, req.swagger.params.q.value, function (err, products) {
      if (err) {
        console.error('searchproductsGET - ' + JSON.stringify(req.swagger.params) + err.print());
        conn.rollback(client, done);
        return next(err);
      }

      res.statusCode = 200;
      return res.end(JSON.stringify({products: products}));
    });
  }
};
{'fraction_non_alphanumeric': 0.16196090598820975, 'fraction_numerical': 0.007446478436239528, 'mean_word_length': 2.8244365361803085, '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': '1045650', 'n_tokens_mistral': 1034, 'n_tokens_neox': 1003, 'n_words': 186}