text: const Workout = require("../models/workout.js");
  const express = require("express")
  const router = express.Router()
  
  
  router.get("/api/workouts", function (req, res) {
      Workout.find({})
          .then(dbWorkout => {
              res.json(dbWorkout);
          })
          .catch(err => {
              res.status(400).json(err);
          });
  });
  router.post("/api/workouts", function (req, res) {
      Workout.create({})
          .then(dbWorkout => {
              res.json(dbWorkout);
          })
          .catch(err => {
              res.status(400).json(err);
          });
  });
  router.get("/api/workouts/range", function (req, res) {
      Workout.find({})
          .then(dbWorkout => {
              res.json(dbWorkout);
          })
          .catch(err => {
              res.status(400).json(err);
          });
  });
  router.put("/api/workouts/:id", function ({ body, params }, res) {
      Workout.findByIdAndUpdate(
          params.id,
          { $push: { exercises: body } },
          { new: true }
      )
          .then(dbWorkout => {
              res.json(dbWorkout);
          })
          .catch(err => {
              res.status(400).json(err);
          });
  });
  
  module.exports = router;