text: 'use strict';
  
  const db = require(`../models`);
  
  // Defining methods for the booksController
  module.exports = {
    findAll: (req, res) => {
      db.Book.find(req.query)
        .sort({ date: -1 })
        .then(dbModel => res.json(dbModel))
        .catch(err => res.status(442).json(err));
    },
    findById: (req, res) => {
      db.Book.findById(req.params.id)
        .then(dbModel => res.json(dbModel))
        .catch(err => res.status(442).json(err));
    },
    create: (req, res) => {
      db.Book.create(req.body)
        .then(dbModel => res.json(dbModel))
        .catch(err => res.status(442).json(err));
    },
    update: (req, res) => {
      db.Book.findOneAndUpdate({ _id: req.params.id }, req.body)
        .then(dbModel => res.json(dbModel))
        .catch(err => res.status(442).json(err));
    },
    remove: (req, res) => {
      db.Book.findById({ _id: req.params.id })
        .then(dbModel => dbModel.remove())
        .then(dbModel => res.json(dbModel))
        .catch(err => res.status(442).json(err));
    }
  };
  