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:
11
packages/server/src/api/gifts/dto/create-contribution.dto.ts
Normal file
11
packages/server/src/api/gifts/dto/create-contribution.dto.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const createContributionSchema = z.object({
|
||||
giftId: z.string().uuid(),
|
||||
contributorName: z.string().min(1),
|
||||
contributorEmail: z.string().email().optional(),
|
||||
amount: z.number().min(0),
|
||||
type: z.enum(["individual", "group"]).optional(),
|
||||
});
|
||||
|
||||
export type CreateContributionDto = z.infer<typeof createContributionSchema>;
|
||||
11
packages/server/src/api/gifts/dto/create-gift.dto.ts
Normal file
11
packages/server/src/api/gifts/dto/create-gift.dto.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const createGiftSchema = z.object({
|
||||
name: z.string().min(1),
|
||||
description: z.string().optional(),
|
||||
imageUrl: z.string().optional(),
|
||||
price: z.number().optional(),
|
||||
experience: z.boolean().optional(),
|
||||
});
|
||||
|
||||
export type CreateGiftDto = z.infer<typeof createGiftSchema>;
|
||||
51
packages/server/src/api/gifts/routes.ts
Normal file
51
packages/server/src/api/gifts/routes.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { Router } from "express";
|
||||
import { GiftService } from "../../modules/gifts/service";
|
||||
import { validateBody } from "../../core/middleware/validate";
|
||||
import { createGiftSchema, createContributionSchema } from "../../modules/gifts/types";
|
||||
import { requireAuth } from "../../core/middleware/auth";
|
||||
|
||||
const service = new GiftService();
|
||||
|
||||
export function registerGiftRoutes(router: Router) {
|
||||
const r = Router();
|
||||
|
||||
// Protected routes
|
||||
r.use(requireAuth);
|
||||
|
||||
r.post("/gift", validateBody(createGiftSchema), async (req, res) => {
|
||||
const ownerId = (req as any).user?.id;
|
||||
const gift = await service.createGift({ ...req.body, ownerId });
|
||||
res.json(gift);
|
||||
});
|
||||
|
||||
r.get("/gift", async (_req, res) => {
|
||||
const gifts = await service.listGifts();
|
||||
res.json(gifts);
|
||||
});
|
||||
|
||||
r.get("/gift/:id", async (req, res) => {
|
||||
const requesterId = (req as any).user?.id;
|
||||
const gift = await service.getGiftById(req.params.id, requesterId);
|
||||
if (!gift) {
|
||||
return res.status(404).json({ error: "Gift not found" });
|
||||
}
|
||||
res.json(gift);
|
||||
});
|
||||
|
||||
r.post(
|
||||
"/gift/contribution",
|
||||
validateBody(createContributionSchema),
|
||||
async (req, res) => {
|
||||
const contribution = await service.createContribution(req.body);
|
||||
res.json(contribution);
|
||||
},
|
||||
);
|
||||
|
||||
r.get("/gift/:id/contributions", async (req, res) => {
|
||||
const requesterId = (req as any).user?.id;
|
||||
const contributions = await service.listContributions(req.params.id, requesterId);
|
||||
res.json(contributions);
|
||||
});
|
||||
|
||||
router.use(r);
|
||||
}
|
||||
Reference in New Issue
Block a user