text: const { CategoryService } = require('../models/categoryService');
  const express = require('express');
   const { Options } = require('../models/options');
   const router = express.Router();
  
  
  
  
   //Display to all services 
   //http://localhost:3000/api/v1/categoryService/service/categories/All
   router.get(`/service/categories/All`, async (req, res) => {
      let filter = {};
      // if (req.query.options) {
      //     filter = { option: req.query.option.split(',') };
      // }
  
      const categoryServiceList = await CategoryService.find();
  
      if (!categoryServiceList) {
          res.status(500).json({ success: false });
      }
      res.send(categoryServiceList);
  });
   // Display to all services 
  
  
  
  // display a specific service based on its id 
   router.get(`/:id`, async (req, res) => {
      const categoryService = await CategoryService.findById(req.params.id).populate('categoryService');//refer to model option  
  
      if (!categoryService) {
          res.status(500).json({ success: false });
      }
      res.send(categoryService);
  });
  //END TO DISPLAY specific service
  
  
  //TO ADD NEW SERVICES
  router.post(`/insertCategoryService`, async (req, res) => {
  
  
  
      let categoryService = new CategoryService({
  
          name: req.body.name,
          description: req.body.description,
  
      });
  
      categoryService = await categoryService.save();
  
      if (!categoryService) return res.status(500).send('The service cannot be created');
  
      res.send(categoryService);
  });
  // END TO ADD NEW SERVICES
  
  
  //to modify an existing CategoryService
  
  router.put('/:id', async (req, res) => {
  
      const updatedCategoryService = await CategoryService.findByIdAndUpdate(
          req.params.id,
          {
              name: req.body.name,
              description: req.body.description,
          },
  
          { new: true }
      );
  
      if (!updatedCategoryService) return res.status(500).send('the Category service cannot be updated!');
  
      res.send(updatedCategoryService);
  });
  // end to modify an existing CategoryService
  
  
  
  
  
              //to delete an existing product
  
              router.delete('/:id', (req, res) => {
                  CategoryService.findByIdAndRemove(req.params.id)
                      .then((categoryService) => {
                          if (categoryService) {
                              return res.status(200).json({
                                  success: true,
                                  message: 'the categoryService is deleted!'
                              });
                          } else {
                              return res.status(404).json({ success: false, message: 'categoryService not found!' });
                          }
                      })
                      .catch((err) => {
                          return res.status(500).json({ success: false, error: err });
                      });
              });
  
              //end to delete an existing product
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  module.exports = router;
  