<commit_before>var express = require('express');
var routes = function(Book) {
  var bookRouter = express.Router();
  bookRouter.route('/')
    .post(function(req, res) {
      var book = new Book(req.body);

      book.save();
      res.status(201).send(book);
    })
    .get(function(req, res) {
      var query = {};
      if (req.query.genre) {
        query.genre = req.query.genre;
      }
      Book.find(query, function(err, books) {
        if(err)
          res.status(500).send(err);
        else
          res.json(books);
    });
  });

  bookRouter.route(' /:bookId')
    .get(function(req, res) {
      Book.findById(req.params.bookId, function(err, book) {
        if(err)
          res.status(500).send(err);
        else
          res.json(book);
    });
  });

  return bookRouter;
};

module.exports = routes;<commit_msg>Create PUT and PATCH requests to handle updating a book<commit_after>var express = require('express');
var routes = function(Book) {
  var bookRouter = express.Router();
  bookRouter.route('/')
    .post(function(req, res) {
      var book = new Book(req.body);

      book.save();
      res.status(201).send(book);
    })
    .get(function(req, res) {
      var query = {};
      if (req.query.genre) {
        query.genre = req.query.genre;
      }
      Book.find(query, function(err, books) {
        if(err)
          res.status(500).send(err);
        else
          res.json(books);
      });
    });

  bookRouter.route('/:bookId')
    .get(function(req, res) {
      Book.findById(req.params.bookId, function(err, book) {
        if(err)
          res.status(500).send(err);
        else
          res.json(book);
      });
    })
    .put(function(req, res) {
      Book.findById(req.params.bookId, function(err, book) {
        if(err) {
          res.status(500).send(err);
        } else {
          book.title = req.body.title;
          book.author = req.body.author;
          book.genre = req.body.genre;
          book.read = req.body.read;
          book.save();
          res.json(book);
        }
      });
    })
    .patch(function(req, res) {
      Book.findById(req.params.bookId, function(err, book) {
        if(err) {
          res.status(500).send(err);
        } else {
          if(req.body.title != undefined)
            book.title = req.body.title;
          if(req.body.author != undefined)
            book.author = req.body.author;
          if(req.body.genre != undefined)
            book.genre = req.body.genre;
          if(req.body.read != undefined)
            book.read = req.body.read;
          book.save();
          res.json(book);
        }
      });
    });

  return bookRouter;
};

module.exports = routes;
{'fraction_non_alphanumeric': 0.15920029618659756, 'fraction_numerical': 0.008885597926693817, 'mean_word_length': 1.8653234358430542, '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': '471147', 'n_tokens_mistral': 902, 'n_tokens_neox': 878, 'n_words': 147}