phase 2 and 3
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import PartDetailClient from "./PartDetailClient";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function AdminPartDetailPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ id: string; assemblyId: string; partId: string }>;
|
||||
}) {
|
||||
const { id, assemblyId, partId } = await params;
|
||||
const [part, machines, templates] = await Promise.all([
|
||||
prisma.part.findFirst({
|
||||
where: { id: partId, assemblyId, assembly: { projectId: id } },
|
||||
include: {
|
||||
assembly: {
|
||||
select: {
|
||||
id: true,
|
||||
code: true,
|
||||
name: true,
|
||||
project: { select: { id: true, code: true, name: true } },
|
||||
},
|
||||
},
|
||||
stepFile: true,
|
||||
drawingFile: true,
|
||||
cutFile: true,
|
||||
operations: {
|
||||
orderBy: { sequence: "asc" },
|
||||
include: {
|
||||
machine: { select: { id: true, name: true } },
|
||||
template: { select: { id: true, name: true } },
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
prisma.machine.findMany({
|
||||
where: { active: true },
|
||||
orderBy: { name: "asc" },
|
||||
select: { id: true, name: true },
|
||||
}),
|
||||
prisma.operationTemplate.findMany({
|
||||
where: { active: true },
|
||||
orderBy: { name: "asc" },
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
machineId: true,
|
||||
defaultSettings: true,
|
||||
defaultInstructions: true,
|
||||
qcRequired: true,
|
||||
},
|
||||
}),
|
||||
]);
|
||||
if (!part) notFound();
|
||||
|
||||
const fileView = (f: typeof part.stepFile) =>
|
||||
f
|
||||
? {
|
||||
id: f.id,
|
||||
originalName: f.originalName,
|
||||
sizeBytes: f.sizeBytes,
|
||||
kind: f.kind,
|
||||
mimeType: f.mimeType,
|
||||
}
|
||||
: null;
|
||||
|
||||
return (
|
||||
<PartDetailClient
|
||||
project={part.assembly.project}
|
||||
assembly={{ id: part.assembly.id, code: part.assembly.code, name: part.assembly.name }}
|
||||
part={{
|
||||
id: part.id,
|
||||
code: part.code,
|
||||
name: part.name,
|
||||
material: part.material,
|
||||
qty: part.qty,
|
||||
notes: part.notes,
|
||||
stepFile: fileView(part.stepFile),
|
||||
drawingFile: fileView(part.drawingFile),
|
||||
cutFile: fileView(part.cutFile),
|
||||
}}
|
||||
operations={part.operations.map((op) => ({
|
||||
id: op.id,
|
||||
sequence: op.sequence,
|
||||
name: op.name,
|
||||
machineId: op.machineId,
|
||||
machineName: op.machine?.name ?? null,
|
||||
templateId: op.templateId,
|
||||
templateName: op.template?.name ?? null,
|
||||
settings: op.settings,
|
||||
materialNotes: op.materialNotes,
|
||||
instructions: op.instructions,
|
||||
qcRequired: op.qcRequired,
|
||||
plannedMinutes: op.plannedMinutes,
|
||||
plannedUnits: op.plannedUnits,
|
||||
status: op.status,
|
||||
qrToken: op.qrToken,
|
||||
}))}
|
||||
machines={machines}
|
||||
templates={templates.map((t) => ({
|
||||
id: t.id,
|
||||
name: t.name,
|
||||
machineId: t.machineId,
|
||||
defaultSettings: t.defaultSettings,
|
||||
defaultInstructions: t.defaultInstructions,
|
||||
qcRequired: t.qcRequired,
|
||||
}))}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user