QoL changes and additions
Build and Push Docker Image / build (push) Successful in 45s

This commit is contained in:
jason
2026-04-22 13:16:42 -05:00
parent a165428f14
commit 04ae88ca0d
14 changed files with 1424 additions and 29 deletions
@@ -0,0 +1,46 @@
import { type NextRequest } from "next/server";
import { ok, errorResponse, requireRole, parseJson } from "@/lib/api";
import { DuplicateAssemblySchema } from "@/lib/schemas";
import { audit } from "@/lib/audit";
import { clientIp } from "@/lib/request";
import { duplicateAssembly } from "@/lib/duplicate";
/**
* Admin-only. Clone an Assembly (plus every child Part, plus every
* Operation when includeOperations is true) into the same project under a
* new `code`. Useful when a new project needs the same assembly with minor
* tweaks — duplicate then edit rather than rebuilding from scratch.
*/
export async function POST(req: NextRequest, ctx: { params: Promise<{ id: string }> }) {
try {
const actor = await requireRole("admin");
const { id } = await ctx.params;
const body = await parseJson(req, DuplicateAssemblySchema);
const result = await duplicateAssembly({
sourceAssemblyId: id,
code: body.code,
name: body.name,
includeOperations: body.includeOperations ?? true,
});
await audit({
actorId: actor.id,
action: "duplicate",
entity: "Assembly",
entityId: result.id,
after: { sourceAssemblyId: id, ...result },
ipAddress: clientIp(req),
});
return ok(
{
assembly: { id: result.id },
partsCopied: result.partsCopied,
operationsCopied: result.operationsCopied,
},
{ status: 201 },
);
} catch (err) {
return errorResponse(err);
}
}