@@ -28,6 +28,7 @@ export async function GET(_req: NextRequest, ctx: { params: Promise<{ id: string
|
||||
select: {
|
||||
code: true,
|
||||
name: true,
|
||||
qty: true,
|
||||
project: { select: { code: true, name: true } },
|
||||
},
|
||||
},
|
||||
@@ -39,7 +40,11 @@ export async function GET(_req: NextRequest, ctx: { params: Promise<{ id: string
|
||||
|
||||
const data: OperationCardData = {
|
||||
project: op.part.assembly.project,
|
||||
assembly: { code: op.part.assembly.code, name: op.part.assembly.name },
|
||||
assembly: {
|
||||
code: op.part.assembly.code,
|
||||
name: op.part.assembly.name,
|
||||
qty: op.part.assembly.qty,
|
||||
},
|
||||
part: {
|
||||
code: op.part.code,
|
||||
name: op.part.name,
|
||||
|
||||
@@ -37,8 +37,11 @@ export async function POST(req: NextRequest, ctx: { params: Promise<{ id: string
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
// `partial` behaves exactly like `pending` for claim purposes — it just
|
||||
// means a previous operator paused with some units done. Either is fair
|
||||
// game to resume.
|
||||
const updateResult = await prisma.operation.updateMany({
|
||||
where: { id, claimedByUserId: null, status: "pending" },
|
||||
where: { id, claimedByUserId: null, status: { in: ["pending", "partial"] } },
|
||||
data: {
|
||||
status: "in_progress",
|
||||
claimedByUserId: actor.id,
|
||||
|
||||
@@ -66,6 +66,10 @@ export async function POST(req: NextRequest, ctx: { params: Promise<{ id: string
|
||||
},
|
||||
});
|
||||
}
|
||||
// unitsCompleted is cumulative across pause/resume cycles; on close we
|
||||
// add this session's batch so the total reflects everything the step
|
||||
// actually produced.
|
||||
const units = body.unitsProcessed ?? 0;
|
||||
await tx.operation.update({
|
||||
where: { id },
|
||||
data: {
|
||||
@@ -73,6 +77,7 @@ export async function POST(req: NextRequest, ctx: { params: Promise<{ id: string
|
||||
completedAt: now,
|
||||
claimedByUserId: null,
|
||||
claimedAt: null,
|
||||
...(units > 0 ? { unitsCompleted: { increment: units } } : {}),
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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