text: const router = require('express').Router();
  const { Tag, Product, ProductTag } = require('../../models');
  
  // The `/api/tags` endpoint
  
  router.get('/', async (req, res) => {
    // find all tags
    // be sure to include its associated Product data
    try {
      const allTags = await Tag.findAll({
      include: [{ model: Product, through: ProductTag, as: 'tag_id'}],
      });
      res.status(200).json(allTags);
    } catch (err) {
      res.status(500).json(err);
    }
  });
  
  router.get('/:id', async (req, res) => {
    // find a single tag by its `id`
    // be sure to include its associated Product data
    try {
      const singleTag = await Tag.findByPk(req.params.id, {
        include: [{ model: Product, through: ProductTag, as: 'tag_id'}],
      })
    if (!singleTag){
      res.status(404).json({ message: 'Tag associated with this id does not exists'});
      return;
    }
    res.status(200).json(singleTag);
    } catch (err) {
      res.status(500).json(err);
    }
  });
  
  router.post('/', async (req, res) => {
    // create a new tag
    try {
      const singleTag = await Tag.create(req.body);
      res.status(200).json(singleTag);
    } catch (err) {
      res.status(500).json(err);
    }
  
  });
  
  router.put('/:id', async (req, res) => {
    // update a tag's name by its `id` value
    try {
      const singleTag = await Tag.update(req.body, {
        where: {
          id: req.params.id,
        },
      });
      if (!singleTag) {
        res.status(404).json({ message: 'No tag with this id exists.'});
        return;
      }
      res.status(200).json(singleTag);
    } catch (err) {
      res.status(500).json(err);
    }
  });
  
  router.delete('/:id', async (req, res) => {
    // delete on tag by its `id` value
    try {
      const singleTag = await Tag.destroy({
        where: {
          id: req.params.id,
        },
      });
      if (!singleTag) {
        res.status(404).json({ message: 'No tag with this id exists.'});
        return;
      }
      res.status(200).json(singleTag);
    } catch (err) {
      res.status(500).json(err);
    }
  });
  
  module.exports = router;
  