text: const db = require("../models");
  
  // Defining methods for the eventsController
  module.exports = {
    findAll: (_req, res) => {
      db.Event.find({})
        .then((dbModel) => res.json(dbModel))
        .catch((err) => res.status(422).json(err));
    },
    findById: (req, res) => {
      db.Event
        .findById(req.params.id)
        .then(dbModel => res.json(dbModel))
        .catch(err => res.status(422).json(err));
    },
    create: (req, res) => {
      db.Event
        .create(req.body)
        .then(dbModel => res.json(dbModel))
        .catch(err => res.status(422).json(err));
    },
    update: (req, res) => {
      db.Event
        .findOneAndUpdate({ _id: req.params.id }, req.body)
        .then(dbModel => res.json(dbModel))
        .catch(err => res.status(422).json(err));
    },
    remove: (req, res) => {
      db.Event
        .findOneAndDelete({ title: req.params.title })
        .then(dbModel => dbModel.remove())
        .then(dbModel => res.json(dbModel))
        .catch(err => console.log(err));
    }
  };
  