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:
36
packages/server/src/api/admin/guests/routes.ts
Normal file
36
packages/server/src/api/admin/guests/routes.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { Router } from "express";
|
||||
import { GuestService } from "../../../modules/guests/service";
|
||||
import { validateBody } from "../../../core/middleware/validate";
|
||||
import { createGuestSchema, updateRsvpSchema } from "../../../modules/guests/types";
|
||||
|
||||
const service = new GuestService();
|
||||
|
||||
export function registerGuestRoutes(router: Router) {
|
||||
const r = Router();
|
||||
|
||||
// Admin can manage guests (same endpoints, can be extended with extra checks)
|
||||
|
||||
r.post("/guest", validateBody(createGuestSchema), async (req, res) => {
|
||||
const guest = await service.createGuest(req.body);
|
||||
res.json(guest);
|
||||
});
|
||||
|
||||
r.get("/guest", async (_req, res) => {
|
||||
const guests = await service.listGuests();
|
||||
res.json(guests);
|
||||
});
|
||||
|
||||
r.patch(
|
||||
"/guest/:id/rsvp",
|
||||
validateBody(updateRsvpSchema),
|
||||
async (req, res) => {
|
||||
const updated = await service.updateRsvp(req.params.id, req.body);
|
||||
if (!updated) {
|
||||
return res.status(404).json({ error: "Guest not found" });
|
||||
}
|
||||
res.json(updated);
|
||||
},
|
||||
);
|
||||
|
||||
router.use(r);
|
||||
}
|
||||
Reference in New Issue
Block a user