From d4e282ec00a0c02ea3db0350c0a75991b4f7367e Mon Sep 17 00:00:00 2001 From: OpenClaw Date: Fri, 13 Mar 2026 14:56:40 +0000 Subject: [PATCH] feat: Allow Chef/Disponent to update any assignment status - New endpoint PUT /orders/:id/assignment/:userId - Can set status to confirmed/declined/pending - For managing fixed employees and handling dropouts --- src/routes/orders.ts | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/routes/orders.ts b/src/routes/orders.ts index 29e09c3..0509e22 100644 --- a/src/routes/orders.ts +++ b/src/routes/orders.ts @@ -301,3 +301,46 @@ ordersRouter.put("/:id/assignment", authMiddleware, async (ctx) => { ctx.response.body = { message: "Assignment updated" }; }); + +// Update assignment status for any user (Chef/Disponent only) +ordersRouter.put("/:id/assignment/:userId", requireDisponentOrHigher, async (ctx) => { + const { org_id: orgId } = ctx.state.auth.user; + const orderId = ctx.params.id; + const targetUserId = ctx.params.userId; + const body = await ctx.request.body.json(); + const { status, note } = body; + + if (!status || !["confirmed", "declined", "pending"].includes(status)) { + throw new AppError("Valid status required (confirmed/declined/pending)", 400); + } + + // Verify order belongs to org + const order = await queryOne<{ id: string }>( + `SELECT id FROM orders WHERE id = $1 AND org_id = $2`, + [orderId, orgId] + ); + + if (!order) { + throw new AppError("Order not found", 404); + } + + const assignment = await queryOne<{ id: string }>( + `SELECT id FROM order_assignments WHERE order_id = $1 AND user_id = $2`, + [orderId, targetUserId] + ); + + if (!assignment) { + throw new AppError("Assignment not found", 404); + } + + const confirmedAt = status === "confirmed" ? "NOW()" : "NULL"; + + await execute( + `UPDATE order_assignments + SET status = $1, note = $2, confirmed_at = ${confirmedAt} + WHERE order_id = $3 AND user_id = $4`, + [status, note || null, orderId, targetUserId] + ); + + ctx.response.body = { message: "Assignment updated" }; +});