L2 Aufträge & Backoffice: Server Actions und /api/v1/work-orders
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { NextResponse, type NextRequest } from "next/server";
|
||||
import type { UpdateWorkOrderInput } from "@/lib/work-orders/schemas";
|
||||
import { computeCompletionBlockers } from "@/server/services/work-orders/completion";
|
||||
import { availableTransitions, getWorkOrderDetail } from "@/server/services/work-orders/detail";
|
||||
import { updateWorkOrder } from "@/server/services/work-orders/update";
|
||||
import { apiContext, apiError, optionalVersion, readJson } from "../_http";
|
||||
|
||||
type Params = { params: Promise<{ id: string }> };
|
||||
|
||||
/** GET /api/v1/work-orders/[id] — detail incl. transitions available to the caller and completion blockers. */
|
||||
export async function GET(_req: NextRequest, { params }: Params) {
|
||||
try {
|
||||
const { id } = await params;
|
||||
const ctx = await apiContext();
|
||||
const wo = await getWorkOrderDetail(ctx, id);
|
||||
const [blockers] = await Promise.all([computeCompletionBlockers(ctx, id)]);
|
||||
return NextResponse.json({ workOrder: wo, availableTransitions: availableTransitions(ctx, wo.status), completionBlockers: blockers });
|
||||
} catch (err) {
|
||||
return apiError(err);
|
||||
}
|
||||
}
|
||||
|
||||
/** PATCH /api/v1/work-orders/[id] — body: partial master data + optional baseVersion (409 on mismatch). */
|
||||
export async function PATCH(req: NextRequest, { params }: Params) {
|
||||
try {
|
||||
const { id } = await params;
|
||||
const ctx = await apiContext();
|
||||
const { baseVersion, ...patch } = await readJson(req);
|
||||
const res = await updateWorkOrder(ctx, id, patch as UpdateWorkOrderInput, optionalVersion(baseVersion));
|
||||
return NextResponse.json(res);
|
||||
} catch (err) {
|
||||
return apiError(err);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user