<commit_before>var express = require('express'),
    errors  = require('./errors');

function loader(Model, id) {
  return function(req, res, next) {
    var param = req.params[id];
    if (!('string' === typeof param && 24 === param.length)) {
      return next(new errors.BadRequest());
    }
    Model.findById(param, function(err, model) {
      if (err) return next(err);
      if (!model) return next(new errors.NotFound('wrong id'));
      req[Model.modelName] = model;
      next();
    });
  };
}

module.exports = function(app, db) {
  var models = require('./models')(db),

      Board  = models.Board,
      Postit = models.Postit,
      Lines  = models.Lines;

  app.get('/', function(req, res) {
    res.render('index');
  });

  app.get('/boards', function(req, res, next) {
    var boards = Board.find({}, function(err, boards) {
      if(err) return next(err);
      res.send(boards);
    });
  });

  // Create Board
  app.post('/boards', function(req, res, next) {
    var board = new Board(req.body);
    board.save(function(err) {
      if (err) return next(err);
      res.send(201, board);
    });
  });

  // Get Board
  app.get('/boards/:bid', loader(Board, 'bid'), function(req, res) {
    res.send(req.board);
  });

  // Update Board
  app.put('/boards/:bid', function(req, res, next) {
    delete req.body._id;
    Board.findByIdAndUpdate(req.params.bid, req.body, function(err) {
      if (err) return next(err);
      res.send(204);
    });
  });

  // Create Postit
  app.post('/boards/:bid/postits', function(req, res, next) {
    req.body.board_id = req.params.bid;
    var postit = new Postit(req.body);
    postit.save(function(err) {
      if (err) return next(err);
      res.send(201, postit);
    });
  });

  // Get postits
  app.get('/boards/:bid/postits', function(req, res, next) {
    var bid = req.params.bid;
    Postit.find({ board_id : bid }, function(err, postits) {
      if (err) return next(new Error());
      res.send(postits);
    });
  });

  // Get postit
  app.get('/boards/:bid/postits/:pid', loader(Postit, 'pid'), function(req, res) {
    res.send(req.postit);
  });

  // Update postit
  app.put('/boards/:bid/postits/:pid', function(req, res, next) {
    delete req.body._id;
    Postit.findByIdAndUpdate(req.params.pid, req.body, function(err) {
      if (err) return next(err);
      res.send(204);
    });
  });
};<commit_msg>Return 200 OK for update<commit_after>var express = require('express'),
    errors  = require('./errors');

function loader(Model, id) {
  return function(req, res, next) {
    var param = req.params[id];
    if (!('string' === typeof param && 24 === param.length)) {
      return next(new errors.BadRequest());
    }
    Model.findById(param, function(err, model) {
      if (err) return next(err);
      if (!model) return next(new errors.NotFound('wrong id'));
      req[Model.modelName] = model;
      next();
    });
  };
}

module.exports = function(app, db) {
  var models = require('./models')(db),

      Board  = models.Board,
      Postit = models.Postit,
      Lines  = models.Lines;

  app.get('/', function(req, res) {
    res.render('index');
  });

  app.get('/boards', function(req, res, next) {
    var boards = Board.find({}, function(err, boards) {
      if(err) return next(err);
      res.send(boards);
    });
  });

  // Create Board
  app.post('/boards', function(req, res, next) {
    var board = new Board(req.body);
    board.save(function(err) {
      if (err) return next(err);
      res.send(201, board);
    });
  });

  // Get Board
  app.get('/boards/:bid', loader(Board, 'bid'), function(req, res) {
    res.send(req.board);
  });

  // Update Board
  app.put('/boards/:bid', function(req, res, next) {
    delete req.body._id;
    Board.findByIdAndUpdate(req.params.bid, req.body, function(err, board) {
      if (err) return next(err);
      res.send(200, board);
    });
  });

  // Create Postit
  app.post('/boards/:bid/postits', function(req, res, next) {
    req.body.board_id = req.params.bid;
    var postit = new Postit(req.body);
    postit.save(function(err) {
      if (err) return next(err);
      res.send(201, postit);
    });
  });

  // Get postits
  app.get('/boards/:bid/postits', function(req, res, next) {
    var bid = req.params.bid;
    Postit.find({ board_id : bid }, function(err, postits) {
      if (err) return next(new Error());
      res.send(postits);
    });
  });

  // Get postit
  app.get('/boards/:bid/postits/:pid', loader(Postit, 'pid'), function(req, res) {
    res.send(req.postit);
  });

  // Update postit
  app.put('/boards/:bid/postits/:pid', function(req, res, next) {
    delete req.body._id;
    Postit.findByIdAndUpdate(req.params.pid, req.body, function(err, postit) {
      if (err) return next(err);
      res.send(200, postit);
    });
  });
};
{'fraction_non_alphanumeric': 0.1897659001450176, 'fraction_numerical': 0.006422208411021338, 'mean_word_length': 2.8045705279747835, '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': '3679412', 'n_tokens_mistral': 1694, 'n_tokens_neox': 1662, 'n_words': 354}