Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { NextRequest } from "next/server";

import { proxyToBackend } from "@/lib/server/proxy";

export async function PATCH(request: NextRequest, { params }: { params: Promise<{ family_id: string }> }) {
const { family_id } = await params;
// Slug `[id]` (no `[family_id]`): Next.js exige un único nombre de slug por
// posición; tener `defects/[id]` y `defects/[family_id]` a la vez crashea el
// runtime entero ("cannot use different slug names for the same dynamic path").
export async function PATCH(request: NextRequest, { params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
const body = await request.text();
return proxyToBackend(request, `/v2/defects/${encodeURIComponent(family_id)}/label`,
return proxyToBackend(request, `/v2/defects/${encodeURIComponent(id)}/label`,
{ method: "PATCH", body, contentType: "application/json" });
}

Expand Down
21 changes: 21 additions & 0 deletions frontend/src/lib/api/__tests__/route-parity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,25 @@ describe("paridad endpoints.ts ↔ route handlers", () => {
const missing = requiredPaths().filter((p) => !existing.has(p));
expect(missing, `Faltan route handlers para: ${missing.join(", ")}`).toEqual([]);
});

it("no hay slugs dinámicos hermanos con nombres distintos (crashea el runtime de Next)", () => {
// `next build` NO detecta esto; el runtime lanza "You cannot use different
// slug names for the same dynamic path" y TODA función serverless 504ea.
const appRoot = path.join(process.cwd(), "src/app");
const conflicts: string[] = [];

function walk(dir: string) {
const dirs = fs
.readdirSync(dir, { withFileTypes: true })
.filter((e) => e.isDirectory());
const slugs = dirs.map((e) => e.name).filter((n) => n.startsWith("[") && n.endsWith("]"));
if (new Set(slugs).size > 1) {
conflicts.push(`${path.relative(appRoot, dir) || "."} → ${slugs.join(", ")}`);
}
for (const e of dirs) walk(path.join(dir, e.name));
}

walk(appRoot);
expect(conflicts, `Slugs dinámicos en conflicto: ${conflicts.join(" | ")}`).toEqual([]);
});
});
Loading