<commit_before>var express = require('express');
var bodyParser = require('body-parser');
var Chance = require('chance');
var chance = new Chance();
var moment = require('moment');

var fs = require('fs');
var _ = require('lodash');

var app = express();

app.use(bodyParser.json());

// extended: true allows rich query string to be parsed
app.use(bodyParser.urlencoded({ extended: true }));

var jobs = [];

fs.readFile('jobs.json', { encoding: 'utf8' }, function (err, data) {
  if (err) throw err;
  JSON.parse(data).forEach(function (job) {
    jobs.push(job);
  });
});

app.get('/', function (req, res) {
  res.send('Hello from express api server');
});

app.get('/api/v1/jobs', function (req, res) {
  res.send(JSON.stringify(jobs));
});

app.get('/api/v1/jobs/:jobId', function (req, res) {
  var jobId = req.params.jobId;
  var result = _.find(jobs, { _id: jobId }) || [];
  var status = result.length > 0 ? 200 : 404;
  res.status(status).send(JSON.stringify(result));
});

function validateJob(job) {
  var result = { errors: [] };
  if (_.isUndefined(job.name)) {
    result.errors.push({ code: '1001', description: 'Job name not specified' });
  }

  return result;
}

function saveJob(job) {
  var newJob = {};
  newJob._id = chance.guid();
  newJob.name = job.name;
  newJob.createdAt = moment().unix();
  newJob.params = job.params || {};
  newJob.status = 'created';
  jobs.push(newJob);
  return newJob;
}

app.post('/api/v1/jobs', function (req, res) {
  var payload = req.body;
  var result = validateJob(payload);

  if (result.errors.length > 0) {
    return res.status(400).send(JSON.stringify(result));
  }

  var savedJob = saveJob(payload);
  return res.status(201).send(JSON.stringify(savedJob));
});


function updateJob(job) {
  var currentJob = _.find(jobs, { _id: job._id });
  var updatedJob = Object.assign({}, currentJob);
  updatedJob.when = job.when || updatedJob.when;
  updatedJob.params = job.params || updateJob.params;
  updatedJob.updatedAt = moment().unix();
  // Find item index using indexOf+find
  var index = _.indexOf(jobs, currentJob);

  // Replace item at index using native splice

  arr.splice(index, 1, updatedJob);
  return updatedJob;

}

app.put('/api/v1/jobs/:jobId', function (req, res) {
  var jobId = req.params.jobId;<commit_msg>update job issue fix<commit_after>var express = require('express');
var bodyParser = require('body-parser');
var Chance = require('chance');
var chance = new Chance();
var moment = require('moment');

var fs = require('fs');
var _ = require('lodash');

var app = express();

app.use(bodyParser.json());

// extended: true allows rich query string to be parsed
app.use(bodyParser.urlencoded({ extended: true }));

var jobs = [];

fs.readFile('jobs.json', { encoding: 'utf8' }, function (err, data) {
  if (err) throw err;
  JSON.parse(data).forEach(function (job) {
    jobs.push(job);
  });
});

app.get('/', function (req, res) {
  res.send('Hello from express api server');
});

app.get('/api/v1/jobs', function (req, res) {
  res.send(JSON.stringify(jobs));
});

app.get('/api/v1/jobs/:jobId', function (req, res) {
  var jobId = req.params.jobId;
  var result = _.find(jobs, { _id: jobId }) || [];
  var status = result.length > 0 ? 200 : 404;
  res.status(status).send(JSON.stringify(result));
});

function validateJob(job) {
  var result = { errors: [] };
  if (_.isUndefined(job.name)) {
    result.errors.push({ code: '1001', description: 'Job name not specified' });
  }

  return result;
}

function saveJob(job) {
  var newJob = {};
  newJob._id = chance.guid();
  newJob.name = job.name;
  newJob.createdAt = moment().unix();
  newJob.params = job.params || {};
  newJob.status = 'created';
  jobs.push(newJob);
  return newJob;
}

app.post('/api/v1/jobs', function (req, res) {
  var payload = req.body;
  var result = validateJob(payload);

  if (result.errors.length > 0) {
    return res.status(400).send(JSON.stringify(result));
  }

  var savedJob = saveJob(payload);
  return res.status(201).send(JSON.stringify(savedJob));
});


function updateJob(job) {
  var currentJob = _.find(jobs, { _id: job._id });
  var updatedJob = Object.assign({}, currentJob);
  updatedJob.when = job.when || updatedJob.when;
  updatedJob.params = job.params || updateJob.params;
  updatedJob.updatedAt = moment().unix();
  // Find item index using indexOf+find
  var index = _.indexOf(jobs, currentJob);

  // Replace item at index using native splice

  jobs.splice(index, 1, updatedJob);
  return updatedJob;

}

app.put('/api/v1/jobs/:jobId', function (req, res) {
  var jobId = req.params.jobId;
{'fraction_non_alphanumeric': 0.17900696864111498, 'fraction_numerical': 0.010452961672473868, 'mean_word_length': 4.003267973856209, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6655503', 'n_tokens_mistral': 1618, 'n_tokens_neox': 1550, 'n_words': 374}