text: const router = require('express').Router();
  const { Category, Product } = require('../../models');
  
  // The `/api/categories` endpoint
  
  //get all categories
  router.get('/', async (req, res) => {
    try {
      const categoryData = await Category.findAll({
        include: [{model: Product}]
      });
      res.status(200).json(categoryData);
    } catch (err) {
      res.status(500).json(err);
      return;
    }
  });
  
  //get category by id
  router.get('/:id', async (req, res) => {
    try {
      const categoryData = await Category.findByPk(req.params.id, {
        include: [{model: Product}]
      });
      if (!categoryData) {
        res.status(404).json({ message: 'No category found with that ID.'});
        return;
      }
      res.status(200).json(categoryData);
    } catch (err) {
      res.status(500).json(err);
      return;
    }
  });
  
  //create category
  router.post('/', async (req, res) => {
    try {
      const categoryData = await Category.create(req.body);
      res.status(200).json(categoryData);
      } catch (err) {
        res.status(400).json(err);
        return;
      }
  });
  
  //update category by id
  router.put('/:id', async (req, res) => {
    try {
      const categoryData = await Category.update({category_name: req.body.category_name}, 
          {where: {
            id: req.params.id
          }
      });
  
      if (!categoryData) {
        res.status(404).json({message: 'No category found by that ID'});
        return;
      }
      res.status(200).json(categoryData);
    } catch (err) {
      res.status(500).json(err);
      return;
    }
  });
  
  //delete category by id
  router.delete('/:id', async (req, res) => { 
    try {
      const categoryData = await Category.destroy({
        where: {
          id: req.params.id
        }
      });
      if (!categoryData) {
        res.status(404).json({ message: 'No category found by that ID'});
        return;
      }
      res.status(200).json(categoryData);
    } catch (err) {
      res.status(500).json(err);
      return;
    }
  });
  
  module.exports = router;
  