<commit_before>var util = require('../util'),
    db = require('../db');


/**
 * URL: /users/
 *
 * Method: POST
 *
 * Status codes:
 *
 *  * `201` if user was created successfully
 *  * `409` if a user with the same `username` already exists
 *
 */

function create(req, res, next) {
  var body = req.body;

  db.users.create(body, function(err, user) {
    if(err) return next(err);
    res.json(201, user);
  });
}
exports.create = util.loginRequired(create);

/**
 * URL: /users/:user
 *
 * Method: PUT
 *
 * Status codes:
 *
 *  * `201` if the user was updated successfully
 *
 */

function update(req, res, next) {
  var body = req.body;
  delete body.username;

  db.users.update(req.params.user, body, function(err, user) {
    if(err) return next(err);
    res.json(201, user);
  });
}
exports.update = util.loginRequired(update);

/**
 * URL: /users/
 *
 * Method: GET
 *
 * Status codes:
 *
 *  * `200` ok
 *
 */

function index(req, res) {
  db.users.all(function(err, users) {
    if(err) return next(err);
    res.json(users);
  });
}
exports.index = util.loginRequired(index);

/**
 * URL: /users/:user
 *
 * Method: GET
 *
 * Status codes:
 *
 *  * `200` ok
 *  * `404` not found
 *<commit_msg>Fixed next call<commit_after>var util = require('../util'),
    db = require('../db');


/**
 * URL: /users/
 *
 * Method: POST
 *
 * Status codes:
 *
 *  * `201` if user was created successfully
 *  * `409` if a user with the same `username` already exists
 *
 */

function create(req, res, next) {
  var body = req.body;

  db.users.create(body, function(err, user) {
    if(err) return next(err);
    res.json(201, user);
  });
}
exports.create = util.loginRequired(create);

/**
 * URL: /users/:user
 *
 * Method: PUT
 *
 * Status codes:
 *
 *  * `201` if the user was updated successfully
 *
 */

function update(req, res, next) {
  var body = req.body;
  delete body.username;

  db.users.update(req.params.user, body, function(err, user) {
    if(err) return next(err);
    res.json(201, user);
  });
}
exports.update = util.loginRequired(update);

/**
 * URL: /users/
 *
 * Method: GET
 *
 * Status codes:
 *
 *  * `200` ok
 *
 */

function index(req, res, next) {
  db.users.all(function(err, users) {
    if(err) return next(err);
    res.json(users);
  });
}
exports.index = util.loginRequired(index);

/**
 * URL: /users/:user
 *
 * Method: GET
 *
 * Status codes:
 *
 *  * `200` ok
 *  * `404` not found
 *
{'fraction_non_alphanumeric': 0.1831275720164609, 'fraction_numerical': 0.019753086419753086, 'mean_word_length': 2.871019108280255, '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': '5179717', 'n_tokens_mistral': 925, 'n_tokens_neox': 888, 'n_words': 217}