improvement: Some improvements done. some bugs fixed.
This commit is contained in:
@@ -1,33 +1,57 @@
|
||||
import type { Prisma } from '@prisma/client';
|
||||
|
||||
/** Union several workflows: scan/design first, packing/shipping last, other steps first-seen. */
|
||||
export function unionWorkflowStepCodes(lists: readonly (readonly string[])[]): string[] {
|
||||
const middle: string[] = [];
|
||||
const seenMiddle = new Set<string>();
|
||||
let hasScan = false;
|
||||
let hasDesign = false;
|
||||
let hasPacking = false;
|
||||
let hasShipping = false;
|
||||
const UNION_PINNED_PREFIX = [
|
||||
'intraoral_scan',
|
||||
'choosing_abutment',
|
||||
'design',
|
||||
'model_create',
|
||||
] as const;
|
||||
|
||||
const UNION_SUFFIX = ['packing', 'shipping'] as const;
|
||||
|
||||
const UNION_PINNED = new Set<string>(UNION_PINNED_PREFIX);
|
||||
const UNION_TAIL = new Set<string>(UNION_SUFFIX);
|
||||
|
||||
/** Remaining manufacturing steps — matches catalog LAB_WORKFLOW_STEPS order. */
|
||||
const UNION_MIDDLE_ORDER: Record<string, number> = {
|
||||
milling_dry: 1,
|
||||
milling_wet: 2,
|
||||
printer_resin: 3,
|
||||
printer_metal: 4,
|
||||
pressing: 5,
|
||||
sinter: 6,
|
||||
build_up: 7,
|
||||
stain: 8,
|
||||
glaze: 9,
|
||||
polish_prep: 10,
|
||||
};
|
||||
|
||||
/** Union stacked workflows: pin scan → abutment → design → model, then catalog order, pack/ship last. */
|
||||
export function unionWorkflowStepCodes(lists: readonly (readonly string[])[]): string[] {
|
||||
const present = new Set<string>();
|
||||
for (const list of lists) {
|
||||
for (const code of list) {
|
||||
if (code === 'intraoral_scan') hasScan = true;
|
||||
else if (code === 'design') hasDesign = true;
|
||||
else if (code === 'packing') hasPacking = true;
|
||||
else if (code === 'shipping') hasShipping = true;
|
||||
else if (!seenMiddle.has(code)) {
|
||||
seenMiddle.add(code);
|
||||
middle.push(code);
|
||||
}
|
||||
if (code) present.add(code);
|
||||
}
|
||||
}
|
||||
|
||||
const out: string[] = [];
|
||||
if (hasScan) out.push('intraoral_scan');
|
||||
if (hasDesign) out.push('design');
|
||||
for (const code of UNION_PINNED_PREFIX) {
|
||||
if (present.has(code)) out.push(code);
|
||||
}
|
||||
|
||||
const middle = [...present].filter((code) => !UNION_PINNED.has(code) && !UNION_TAIL.has(code));
|
||||
middle.sort((a, b) => {
|
||||
const da = UNION_MIDDLE_ORDER[a] ?? 100;
|
||||
const db = UNION_MIDDLE_ORDER[b] ?? 100;
|
||||
if (da !== db) return da - db;
|
||||
return a.localeCompare(b);
|
||||
});
|
||||
out.push(...middle);
|
||||
if (hasPacking) out.push('packing');
|
||||
if (hasShipping) out.push('shipping');
|
||||
|
||||
for (const code of UNION_SUFFIX) {
|
||||
if (present.has(code)) out.push(code);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user