<commit_before>var assert = require("assert");
var handle = require("../lib/db.js");

// JSON RPC library
var rpc = require('rpc.js');

// rpc.server('http', {
//   port: process.env.RPC_PORT || 8000,
//   address: process.env.RPC_HOST || "localhost",

//   // NOTE(jeff): API Schema for our HTTP-RPC server
//   gateway: rpc.gateway({
//     schema: require('./lib/api.js')
//   })
// });

// static
var create_update_query = function(db, fields, values) {
  var query = new String('');
  var pair_size = fields.length;

  assert(pair_size == values.length);

  for(var idx = 0; idx != pair_size; ++idx) {

    if(idx == 0) {
      query += 'SET ';
    }

    if(idx != (pair_size-1) ) {
      query += fields[idx] + ' = ' + db.escape(values[idx]) + ",";
    } else {
      query += fields[idx] + ' = ' + db.escape([idx]);
    }
  }

  return query;
};

// JSON RPC API schema
// TODO(jeff): documentation!
module.exports = {

  // API methods
  methods: {
    list_pr: {
      params: {
        pid: { required: false, type: 'number', info: 'ID of the property' },
        jobnum: { required: false, type: 'number', info: 'Drawing number'},
        status: { required: false, type: 'number', info: 'status of job' },
        order: { required: false, type: 'string', info: 'ORDER BY [field] SQL clause'},
        sort: { required: false, type: 'string', info: 'ASC or DESC SQL clause'},
        limit: { required: false, type: 'number', info: 'LIMIT [num] SQL clause'}
      },

      action: function(params, output) {

        handle.create_connection();

        if(params.order == null) {
          params.order = "JobContact";
        }

        if(params.sort == null) {
          params.sort = "ASC";
        }

        // TODO(jeff): Impose minimum and maximum limits here!
        // TODO(jefff): Implement pagination!
        if(params.limit == null) {
          params.limit = "50";
        }

        var opts = {
          order: params.order,
          sort: params.sort,
          limit: params.limit
        };

        if(params.pid) {
          handle.find_property_by_job_id(params.pid, function(err, result, fields) {<commit_msg>lib/api.js: Sort jobs by their last edited date, descending<commit_after>var assert = require("assert");
var handle = require("../lib/db.js");

// JSON RPC library
var rpc = require('rpc.js');

// rpc.server('http', {
//   port: process.env.RPC_PORT || 8000,
//   address: process.env.RPC_HOST || "localhost",

//   // NOTE(jeff): API Schema for our HTTP-RPC server
//   gateway: rpc.gateway({
//     schema: require('./lib/api.js')
//   })
// });

// static
var create_update_query = function(db, fields, values) {
  var query = new String('');
  var pair_size = fields.length;

  assert(pair_size == values.length);

  for(var idx = 0; idx != pair_size; ++idx) {

    if(idx == 0) {
      query += 'SET ';
    }

    if(idx != (pair_size-1) ) {
      query += fields[idx] + ' = ' + db.escape(values[idx]) + ",";
    } else {
      query += fields[idx] + ' = ' + db.escape([idx]);
    }
  }

  return query;
};

// JSON RPC API schema
// TODO(jeff): documentation!
module.exports = {

  // API methods
  methods: {
    list_pr: {
      params: {
        pid: { required: false, type: 'number', info: 'ID of the property' },
        jobnum: { required: false, type: 'number', info: 'Drawing number'},
        status: { required: false, type: 'number', info: 'status of job' },
        order: { required: false, type: 'string', info: 'ORDER BY [field] SQL clause'},
        sort: { required: false, type: 'string', info: 'ASC or DESC SQL clause'},
        limit: { required: false, type: 'number', info: 'LIMIT [num] SQL clause'}
      },

      action: function(params, output) {

        handle.create_connection();

        if(params.order == null) {
          params.order = "DateEdited";
        }

        if(params.sort == null) {
          params.sort = "DESC";
        }

        // TODO(jeff): Impose minimum and maximum limits here!
        // TODO(jefff): Implement pagination!
        if(params.limit == null) {
          params.limit = "50";
        }

        var opts = {
          order: params.order,
          sort: params.sort,
          limit: params.limit
        };

        if(params.pid) {
          handle.find_property_by_job_id(params.pid, function(err, result, fields) {
{'fraction_non_alphanumeric': 0.16923430673718096, 'fraction_numerical': 0.004138882501724534, 'mean_word_length': 2.2879818594104306, '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': '5025810', 'n_tokens_mistral': 1413, 'n_tokens_neox': 1375, 'n_words': 360}