text: const router = require("express").Router();
  
  const Relationships = require("./relationship-models");
  const restricted = require("../auth/restricted-middleware");
  
  router.get("/", restricted, (req, res) => {
    Relationships.find()
      .then((relationships) => {
        res.status(201).json(relationships);
      })
      .catch((err) => {
        res.status(500).json({
          message: err.message,
          stack: err.stack,
        });
      });
  });
  
  router.get("/:id", restricted, (req, res) => {
    const { id } = req.params;
  
    Relationships.findById(id)
      .then((relationship) => {
        if (relationship) {
          res.status(201).json(relationship);
        } else {
          res.status(404).json({
            message: `Could not find relationship with ID #${id}`,
          });
        }
      })
      .catch((err) => {
        res.status(500).json({
          message: err.message,
          stack: err.stack,
        });
      });
  });
  
  router.post("/", restricted, (req, res) => {
    const newRelationship = req.body;
  
    Relationships.create(newRelationship)
      .then((relationship) => {
        res.status(201).json(relationship);
      })
      .catch((err) => {
        res.status(500).json({
          message: err.message,
          stack: err.stack,
        });
      });
  });
  
  router.put("/:id", restricted, (req, res) => {
    const { id } = req.params;
    const edits = req.body;
  
    Relationships.findById(id)
      .then((relationship) => {
        if (relationship) {
          Relationships.update(id, edits).then((updatedRelationship) => {
            res.status(200).json(updatedRelationship);
          });
        } else {
          res.status(404).json({
            message: `Could not find relationship with ID #${id}`,
          });
        }
      })
      .catch((err) => {
        res.status(500).json({
          message: err.message,
          stack: err.stack,
        });
      });
  });
  
  router.delete("/:id", restricted, (req, res) => {
    const { id } = req.params;
  
    Relationships.remove(id)
      .then((relationship) => {
        if (relationship) {
          res.status(204).end();
        } else {
          res.status(404).json({
            message: `Could not find relationship with ID #${id}`,
          });
        }
      })
      .catch((err) => {
        res.status(500).json({
          message: err.message,
          stack: err.stack,
        });
      });
  });
  
  module.exports = router;
  