text: const router = require('express').Router();
  const { Category, Product } = require('../../models');
  
  // The `/api/categories` endpoint
  router.get('/', async (req, res) => {
    // find all categories + include its associated Products
    try {
      const categoryData = await Category.findAll({
        include: [{ model: Product }]
      });
      res.status(200).json(categoryData);
    } catch (err) {
      res.status(500).json(err);
    }
  });
  
  router.get('/:id', async (req, res) => {
    // find one category by its `id` value + include its associated Products
    try {
      const categoryData = await Category.findByPk(req.params.id, {
        include: [{ model: Product }]
      });
      if(categoryData) {
        res.status(200).json(categoryData);
      } else {
        res.status(404).json({message: 'This is not a product category.'});
        return;
      }
    } catch (err) {
      res.status(500).json(err);
    }
  });
  
  router.post('/', async (req, res) => {
    // create a new category
    try {
      const categoryData = await Category.create(req.body);
      res.status(200).json(categoryData);
    } catch (err) {
      res.status(400).json(err);
    }
  });
  
  router.put('/:id', async (req, res) => {
    // update a category by its `id` value
    try {
      const categoryData = await Category.update({
        id: req.params.id,
        category_name: req.body.category_name
      }, {
        where: {
          id: req.params.id
        }
      });
      if(!categoryData[0]) {
        res.status(404).json({message:"Category id doesn't exist!"});
      }
      res.status(200).json(categoryData);
    } catch (error) {
      res.status(500).json(error);
    }
  });
  
  // delete a category by its `id` value
  router.delete('/:id', async (req, res) => {
    try {
      const categoryData = await Category.destroy({
        where: {
          id: req.params.id
        }
      });
      if (!categoryData) {
        res.status(404).json({ message: "Category id doesn't exist!"});
        return;
      }
      res.status(200).json(categoryData);
    } catch (err) {
      res.status(500).json(err);
    }
  });
  
  module.exports = router;