Restructure backend into modular API layers with admin/organizador/invitados routes, add role-based middleware, flatten module models, and update build scripts
This commit is contained in:
33
packages/server/src/api/todos/routes.ts
Normal file
33
packages/server/src/api/todos/routes.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { Router } from "express";
|
||||
import { TodoService } from "../../modules/todos/service";
|
||||
import { validateBody } from "../../core/middleware/validate";
|
||||
import { createTodoSchema } from "../../modules/todos/types";
|
||||
import { requireAuth } from "../../core/middleware/auth";
|
||||
|
||||
const service = new TodoService();
|
||||
|
||||
export function registerTodoRoutes(router: Router) {
|
||||
const r = Router();
|
||||
|
||||
r.use(requireAuth);
|
||||
|
||||
r.post("/todo", validateBody(createTodoSchema), async (req, res) => {
|
||||
const todo = await service.createTodo(req.body);
|
||||
res.json(todo);
|
||||
});
|
||||
|
||||
r.get("/todo", async (_req, res) => {
|
||||
const todos = await service.listTodos();
|
||||
res.json(todos);
|
||||
});
|
||||
|
||||
r.patch("/todo/:id/complete", async (req, res) => {
|
||||
const updated = await service.markComplete(req.params.id);
|
||||
if (!updated) {
|
||||
return res.status(404).json({ error: "Todo not found" });
|
||||
}
|
||||
res.json(updated);
|
||||
});
|
||||
|
||||
router.use(r);
|
||||
}
|
||||
Reference in New Issue
Block a user