// src/controllers/categoriesController.ts

// ...

  },

	// GET /categories/:id
  show: async (req: Request, res: Response) => {
    const { id } = req.params

  }
}
// src/services/categoryService.ts

// ...

      total
    }
  },

  findByIdWithCourses: async (id: string) => {
    const categoryWithCourses = await Category.findByPk(id, {
      attributes: ['id', 'name'],
      include: {
        association: 'courses',
        attributes: ['id', 'name', 'synopsis', ['thumbnail_url', 'thumbnailUrl']],
      }
    })

    return categoryWithCourses
  }
}
// src/models/index.ts

// ...

Category.hasMany(Course, { as: 'courses' })

// ...
// src/controllers/categoriesController.ts

// ...

  },

	// GET /categories/:id
  show: async (req: Request, res: Response) => {
    const { id } = req.params

    try {
      const category = await categoryService.findByIdWithCourses(id)
      return res.json(category)
    } catch (err) {
      if (err instanceof Error) {
        return res.status(400).json({ message: err.message })
      }
    }
  }
}
// src/routes.ts

import express from 'express'
import { categoriesController } from './controllers/categoriesController'

const router = express.Router()

router.get('/categories', categoriesController.index)
router.get('/categories/:id', categoriesController.show)

export { router }