text: const router = require('express').Router();
  const { Tag, Product, ProductTag } = require('../../models');
  
  // The `/api/tags` endpoint
  router.get('/', async (req, res) => {
  // find all tags + include associated Product data
    try {
      const tagData = await Tag.findAll( {
        include: [{ model: Product }]
      });
      res.status(200).json(tagData);
    } catch (err) {
      res.status(500).json(err);
    }
  });
  
  router.get('/:id', async (req, res) => {
    // find a single tag by its `id` + include its associated Product data
    try {
      const tagData = await Tag.findByPk(req.params.id, {
        include: [{ model: Product }]
      });
      if(tagData) {
        res.status(200).json(tagData);
      } else {
        res.status(404).json({message: 'No tag found with this id!'});
        return;
      }
    } catch (err) {
      res.status(500).json(err);
    }
  });
  
  router.post('/', async (req, res) => {
  // create a new tag
    try {
      const tagData = await Tag.create(req.body);
      res.status(200).json(tagData);
    } catch (err) {
      res.status(400).json(err);
    }
  });
  
  router.put('/:id', async (req, res) => {
  // update a tag's name by its `id` value
    try {
      const tagData = await Tag.update(req.body, {
        where: {
          id: req.params.id,
        }
      });
      if(!updatedTag[0]) {
        res.status(404).json({message: "No tag with that id is found"});
      }
      res.status(200).json(tagData);
    } catch (err) {
      res.status(400).json(err);
    }
  });
  
  router.delete('/:id', async (req, res) => {
    // delete on tag by its `id` value
    try {
      const tagData = await Tag.destroy({
          where: {
            id: req.params.id
          }
        });
      if(!tagData) {
        res.status(404).json({message: "No tag with that id is found"})
      }
      res.status(200).json(tagData);
    } catch (error) {
      res.status(500).json(error)
    }
  });
  
  module.exports = router;
  