@@ -29,6 +29,12 @@ export async function POST(req: NextRequest, ctx: { params: Promise<{ id: string
|
||||
throw new ApiError(409, "op_not_active", "Step is not active");
|
||||
}
|
||||
|
||||
// If the operator logged any units during this session we flip status to
|
||||
// `partial` (instead of `pending`) so the scan card can say "Resume this
|
||||
// step" and the counter survives across pauses.
|
||||
const units = body.unitsProcessed ?? 0;
|
||||
const nextStatus: "pending" | "partial" = units > 0 ? "partial" : "pending";
|
||||
|
||||
const now = new Date();
|
||||
await prisma.$transaction(async (tx) => {
|
||||
// Close the most recent open TimeLog for (op, operator). We accept that
|
||||
@@ -50,7 +56,12 @@ export async function POST(req: NextRequest, ctx: { params: Promise<{ id: string
|
||||
}
|
||||
await tx.operation.update({
|
||||
where: { id },
|
||||
data: { status: "pending", claimedByUserId: null, claimedAt: null },
|
||||
data: {
|
||||
status: nextStatus,
|
||||
claimedByUserId: null,
|
||||
claimedAt: null,
|
||||
...(units > 0 ? { unitsCompleted: { increment: units } } : {}),
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -60,7 +71,7 @@ export async function POST(req: NextRequest, ctx: { params: Promise<{ id: string
|
||||
action: "release_op",
|
||||
entity: "Operation",
|
||||
entityId: id,
|
||||
after: { status: "pending", unitsProcessed: body.unitsProcessed ?? null },
|
||||
after: { status: nextStatus, unitsProcessed: body.unitsProcessed ?? null },
|
||||
ipAddress: clientIp(req),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user