UNPKG

@defikitdotnet/education-module-ai

Version:
36 lines (35 loc) 1.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createCategoryRoutes = createCategoryRoutes; var express_1 = require("express"); var CategoryController_1 = require("../controllers/CategoryController"); var CategoryService_1 = require("../services/CategoryService"); var CategoryRepository_1 = require("../repositories/CategoryRepository"); /** * Create and configure category routes */ function createCategoryRoutes(dbAdapter) { var router = (0, express_1.Router)(); // Create repository var categoryRepository = new CategoryRepository_1.CategoryRepository(dbAdapter); // Create service var categoryService = new CategoryService_1.CategoryService(categoryRepository); // Create controller var categoryController = new CategoryController_1.CategoryController(categoryService); // Define helper for casting to RequestHandler if needed, or just wrap var handle = function (action) { return function (req, res, next) { action(req, res).catch(next); // Ensure errors are passed to error handlers }; }; // Public routes - anyone can get categories router.get("/", handle(categoryController.getAllCategories)); router.get("/:categoryId", handle(categoryController.getCategoryById)); router.get("/agent/:agentId", handle(categoryController.getCategoriesByTeacherId)); // Teacher routes (protected) - only teachers can create/update/delete categories // Wrap the controller methods router.post("/", handle(categoryController.createCategory)); router.put("/:categoryId", handle(categoryController.updateCategory)); router.delete("/:categoryId", handle(categoryController.deleteCategory)); return router; }