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
This commit is contained in:
2026-03-13 14:56:40 +00:00
parent e2dfbaeffb
commit d4e282ec00

View File

@@ -301,3 +301,46 @@ ordersRouter.put("/:id/assignment", authMiddleware, async (ctx) => {
ctx.response.body = { message: "Assignment updated" }; 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" };
});