<commit_before>// Taxa query:

// This returns an empty object in the case of error.  I might propagate this to other
// endpoints.

var empty = {
  "query":{   'taxonid':null,
                   'name':null,
              'ecolgroup':null,
                  'lower':null
            },
  "response":{
              "taxonid": null,
            "taxoncode": null,
            "taxonname": null,
               "author": null,
                "valid": null,
        "highertaxonid": null,
              "extinct": null,
          "taxagroupid": null,
        "publicationid": null,
          "validatorid": null,
         "validatedate": null,
                "notes": null
    }};
// Sites query:

const path = require('path');
const bib   = require('./../bib_format');

//get global database object
var db = require('../../database/pgp_db');
var pgp = db.$config.pgp;

// Helper for linking to external query files:
function sql(file) {
    const fullPath = path.join(__dirname, file);
    return new pgp.QueryFile(fullPath, {minify: true});
}

// Create a QueryFile globally, once per file:
const taxonquerylower  = sql('./taxonquerylower.sql');
const taxonquerystatic = sql('./taxonquerystatic.sql');
const taxonbyds = sql('./taxonquerydsid.sql');

// Actual functions:
// 
function taxonbyid(req, res, next) {
  
  var taxonid = String(req.params.taxonid).split(',').map(function(item) {
    return parseInt(item, 10);
  });

  if (!!taxonid) {
    query = 'SELECT * FROM ndb.taxa WHERE taxa.taxonid IN ($1:csv)';
  } else {

      res.status(500)
        .json({
          status: 'failure',
          data: empty,
          message: 'Must pass either queries or an integer sequence.'
        });
  }

  db.any(query, [taxonid])
    .then(function (data) {
      res.status(200)
        .json({
          status: 'success',
          data: data,
          message: 'Retrieved all tables'
        });
    })
    .catch(function (err) {
        return next(err);
    });
}

function taxonbydsid(req, res, next) {


  if (!!req.params.datasetid) {
    var datasetid = String(req.params.datasetid).split(',').map(function(item) {
      return parseInt(item, 10);
    });
  } else {
    
    res.status(500)
        .json({
          status: 'failure',
          data: null,
          message: 'Must pass either queries or an integer sequence.'
        });
  }

  db.any(taxonbyds, [datasetid])
    .then(function (data) {
      res.status(200)
        .json({
          status: 'success',
          data: data,
          message: 'Retrieved all tables'
        });
    })
    .catch(function (err) {
        return next(err);
    });
}



function gettaxonquery(req, res, next) {

  if (!!req.query.taxonid) {
    var taxonid = String(req.query.taxonid).split(',').map(function(item) {
      return parseInt(item, 10);
    });
  } else {
    var taxonid = null;
  }

  var outobj = {'taxonid':taxonid,
              'taxonname':req.query.taxonname,
                 'status':req.query.status,
              'taxagroup':req.query.taxagroup,   
              'ecolgroup':req.query.ecolgroup,
                  'lower':req.query.lower,
                  'limit':req.query.limit,
                  'offset':req.query.offset
               };

  if (typeof outobj.taxonid === 'undefined') {
    outobj.taxonid = null;
  };

  if(!(typeof outobj.taxonname === 'undefined')) {
    outobj.taxonname = outobj.taxonname.replace(/\*/g, "\%");
  }

  var novalues = Object.keys(outobj).every(function(x) { 
    return typeof outobj[x]==='undefined' || !outobj[x];
  });

  if(novalues == true) {
    if(!!req.accepts('json') & !req.accepts('html')) {
      res.redirect('/swagger.json');
    } else {
      res.redirect('/api-docs');
    };
  } else {

    if(outobj.lower === 'true') {
      db.any(taxonquerylower, outobj)
        .then(function (data) {

          res.status(200)
            .json({
              status: 'success',
              data: data,
              message: 'Retrieved all tables'
            });
        })
        .catch(function (err) {
            return next(err);
        });
    };

    if(typeof outobj.lower === 'undefined') {
      db.any(taxonquerystatic, outobj)
        .then(function (data) {

          res.status(200)
            .json({
              status: 'success',
              data: data,
              message: 'Retrieved all tables'
            });
        })
        .catch(function (err) {
            return next(err);
        });
    };
  };
}

module.exports.taxonbyid = taxonbyid;
module.exports.gettaxonquery = gettaxonquery;<commit_msg>Small change to taxa.js<commit_after>// Taxa query:

// This returns an empty object in the case of error.  I might propagate this to other
// endpoints.

var empty = {
  "query":{   'taxonid':null,
                   'name':null,
              'ecolgroup':null,
                  'lower':null
            },
  "response":{
              "taxonid": null,
            "taxoncode": null,
            "taxonname": null,
               "author": null,
                "valid": null,
        "highertaxonid": null,
              "extinct": null,
          "taxagroupid": null,
        "publicationid": null,
          "validatorid": null,
         "validatedate": null,
                "notes": null
    }};
// Sites query:

const path = require('path');
const bib   = require('./../bib_format');

//get global database object
var db = require('../../database/pgp_db');
var pgp = db.$config.pgp;

// Helper for linking to external query files:
function sql(file) {
    const fullPath = path.join(__dirname, file);
    return new pgp.QueryFile(fullPath, {minify: true});
}

// Create a QueryFile globally, once per file:
const taxonquerylower  = sql('./taxonquerylower.sql');
const taxonquerystatic = sql('./taxonquerystatic.sql');
const taxonbyds = sql('./taxonquerydsid.sql');

// Actual functions:
// 
function taxonbyid(req, res, next) {
  
  var taxonid = String(req.params.taxonid).split(',').map(function(item) {
    return parseInt(item, 10);
  });

  if (!!taxonid) {
    query = 'SELECT * FROM ndb.taxa WHERE taxa.taxonid IN ($1:csv)';
  } else {

      res.status(500)
        .json({
          status: 'failure',
          data: empty,
          message: 'Must pass either queries or an integer sequence.'
        });
  }

  db.any(query, [taxonid])
    .then(function (data) {
      res.status(200)
        .json({
          status: 'success',
          data: data,
          message: 'Retrieved all tables'
        });
    })
    .catch(function (err) {
        return next(err);
    });
}

function taxonbydsid(req, res, next) {


  if (!!req.params.datasetid) {
    var datasetid = String(req.params.datasetid).split(',').map(function(item) {
      return parseInt(item, 10);
    });
  } else {
    
    res.status(500)
        .json({
          status: 'failure',
          data: null,
          message: 'Must pass either queries or an integer sequence.'
        });
  }

  db.any(taxonbyds, [datasetid])
    .then(function (data) {
      res.status(200)
        .json({
          status: 'success',
          data: data,
          message: 'Retrieved all tables'
        });
    })
    .catch(function (err) {
        return next(err);
    });
}



function gettaxonquery(req, res, next) {

  if (!!req.query.taxonid) {
    var taxonid = String(req.query.taxonid).split(',').map(function(item) {
      return parseInt(item, 10);
    });
  } else {
    var taxonid = null;
  }

  var outobj = {'taxonid':taxonid,
              'taxonname':req.query.taxonname,
                 'status':req.query.status,
              'taxagroup':req.query.taxagroup,   
              'ecolgroup':req.query.ecolgroup,
                  'lower':req.query.lower,
                  'limit':req.query.limit,
                  'offset':req.query.offset
               };

  if (typeof outobj.taxonid === 'undefined') {
    outobj.taxonid = null;
  };

  if(!(typeof outobj.taxonname === 'undefined')) {
    outobj.taxonname = outobj.taxonname.replace(/\*/g, "\%");
  }

  var novalues = Object.keys(outobj).every(function(x) { 
    return typeof outobj[x]==='undefined' || !outobj[x];
  });

  if(novalues == true) {
    if(!!req.accepts('json') & !req.accepts('html')) {
      res.redirect('/swagger.json');
    } else {
      res.redirect('/api-docs');
    };
  } else {

    if(outobj.lower === 'true') {
      db.any(taxonquerylower, outobj)
        .then(function (data) {

          res.status(200)
            .json({
              status: 'success',
              data: data,
              message: 'Retrieved all tables'
            });
        })
        .catch(function (err) {
            return next(err);
        });
    };

    if(typeof outobj.lower === 'undefined') {
      db.any(taxonquerystatic, outobj)
        .then(function (data) {

          res.status(200)
            .json({
              status: 'success',
              data: data,
              message: 'Retrieved all tables'
            });
        })
        .catch(function (err) {
            return next(err);
        });
    };
  };
}

module.exports.taxonbyid = taxonbyid;
module.exports.gettaxonquery = gettaxonquery;
module.exports.taxonbydsid = taxonbydsid;
{'fraction_non_alphanumeric': 0.15423802297853892, 'fraction_numerical': 0.005419466724474312, 'mean_word_length': 1.9125631313131313, 'pattern_counts': {'":': 28, '<': 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': '2183925', 'n_tokens_mistral': 3024, 'n_tokens_neox': 2899, 'n_words': 610}