text: const router = require('express').Router();
  const { Category, Product } = require('../../models');
  
  // The `/api/categories` endpoint
  
  router.get('/', async (req, res) => {
    try {
      const allData = await Category.findAll({ include:[{model: Product}]
    });
      res.status(200).json(allData);
    } catch (err) {
      res.status(500).json(err)}
  });
  
  router.get('/:id', async (req, res) => {
    try {
      const findOne = await Category.findByPk(req.params.id, {
        include: [{ model: Product }]
      });
      if (!findOne) {
        res.status(404).json({ message: 'No category found with that id '});
        return;
      }
      res.status(200).json(findOne);
    } catch (err) {
      res.status(500).json(err);
    }
  });
  
  router.post('/', async (req, res) => {
    try {
      const newCat = await Category.create(req.body);
      res.status(200).json(newCat);
    } catch (err) {
      res.status(400).json(err);
    }
  });
  
  //  update a category by id
  router.put('/:id', async (req, res) => {
    try {
      const updateCat = await Category.update(req.body, {
        where: {
          id: req.params.id
        }
      });
      if(!updateCat) {
        res.status(404).json({ message: "there is no category with this ID"})
        return;
      }
      res.status(200).json(updateCat);
    } catch (err) {
      res.status(500).json(err)
    }
  });
  
  // user can delete a category
  router.delete('/:id', async (req, res) => {
    try {
      const delCat = await Category.destroy({
        where: {
          id: req.params.id,
        },
      });
  
      if (!delCat) {
        res.status(404).json({ message: 'No Category found with that id'})
        return;
      }
      res.status(200).json( {category_deleted: delCat, message: "Category Successfully Deleted"});
    } catch (err) {
      res.status(500).json(err);
    }
  });
  
  module.exports = router;