old_contents: 'use strict';
  
  const express = require('express');
  
  const routes = (Book) => {
    const bookRouter = express.Router();
  
    bookRouter.route('/')
      .post((req, res) => {
        const book = new Book(req.body);
  
        book.save();
        res.status(201).send(book);
      })
      .get((req, res) => {
        let query = {};
  
        if (req.query.genre) {
          query.genre = req.query.genre;
        }
  
        Book.find(query, (err, books) => {
          if (err) {
            res.status(500).send(err);
          } else {
            res.json(books);
          }
        });
      });
  
    bookRouter.route('/:bookId')
      .get((req, res) => {
        Book.findById(req.params.bookId, (err, book) => {
          if (err) {
            res.status(500).send(err);
          } else {
            res.json(book);
          }
        });
      })
      .put((req, res) => {
        Book.findById(req.params.bookId, (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);
          }
        });
      });
  
    return bookRouter;
  };
  
  module.exports = routes;
  
new_contents: 'use strict';
  
  const express = require('express');
  
  const routes = (Book) => {
    const bookRouter = express.Router();
  
    bookRouter.route('/')
      .post((req, res) => {
        const book = new Book(req.body);
  
        book.save();
        res.status(201).send(book);
      })
      .get((req, res) => {
        let query = {};
  
        if (req.query.genre) {
          query.genre = req.query.genre;
        }
  
        Book.find(query, (err, books) => {
          if (err) {
            res.status(500).send(err);
          } else {
            res.json(books);
          }
        });
      });
  
    bookRouter.use('/:bookId', (req, res, next) => {
      Book.findById(req.params.bookId, (err, book) => {
        if (err) {
          res.status(500).send(err);
        } else if (book) {
          req.book = book;
          next();
        } else {
          res.status(404).send('no book found');
        }
      });
    });
  
    bookRouter.route('/:bookId')
      .get((req, res) => {
        res.json(req.book);
      })
      .put((req, res) => {
        req.book.title  = req.body.title;
        req.book.author = req.body.author;
        req.book.genre  = req.body.genre;
        req.book.read   = req.body.read;
        req.book.save();
        res.json(req.book);
      });
  
    return bookRouter;
  };
  
  module.exports = routes;
  
subject: Add middleware for '/:bookId' routes