const express = require("express")
const router = express.Router()
const Topic = require("../../models/Topic")
const requireAuth = require("../../middleware/requireAuth")

router.get("/topics/:chapterId", requireAuth, async (req, res) => {
  try {
    const topics = await Topic.find({
      chapterId: req.params.chapterId,
      isActive: true
    }).sort({ order: 1 })

    res.json(topics)
  } catch (error) {
    res.status(500).json({ message: error.message })
  }
})

module.exports = router