text: const router = require("express").Router();
  const { Tag, Product, ProductTag } = require("../../models");
  
  // The `/api/tags` endpoint
  
  router.get("/", (req, res) => {
    // find all tags
    // be sure to include its associated Product data
    Tag.findAll({
      include: [
        {
          model: Product,
        },
      ],
    }).then((data) => {
      res.status(200).json(data);
    });
  });
  
  router.get("/:id", (req, res) => {
    // find a single tag by its `id`
    // be sure to include its associated Product data
    Tag.findAll({
      where: {
        id: req.params.id,
      },
      include: [
        {
          model: Product,
        },
      ],
    })
      .then((data) => {
        res.status(200).json(data);
      })
      .catch((err) => {
        console.log(err);
        res.status(404).json(err);
      });
  });
  
  router.post("/", (req, res) => {
    // create a new tag
    Tag.create(req.body)
      .then((data) => {
        res.status(201).json("Item Created");
      })
      .catch((err) => {
        console.log(err);
        res.json(err);
      });
  });
  
  router.put("/:id", (req, res) => {
    // update a tag's name by its `id` value
    Tag.update(req.body, {
      where: {
        id: req.params.id,
      },
    })
      .then((data) => {
        res.status(200).json(`Item updated`);
      })
      .catch((err) => {
        console.log(err);
        res.status(404).json(err);
      });
  });
  
  router.delete("/:id", (req, res) => {
    // delete on tag by its `id` value
    Tag.destroy({
      where: {
        id: req.params.id,
      },
    })
      .then((data) => {
        res.status(200).json(`Item ${req.params.id} deleted.`);
      })
      .catch((err) => {
        console.log(err);
        res.status(404).json(err);
      });
  });
  
  module.exports = router;
  