shoc-frontend-new/src/domain/work-orders/mappers/expand-schedule-board-ops.ts
Arthur Bassi 6e99dc0af2 refactor(work-orders): pass board-api governance maintainability gate
Split oversized API/mapper/UI modules and extract focused helpers so the
exact head satisfies godfile and complexity ratchets without relaxing thresholds.
2026-07-28 09:56:27 -03:00

42 lines
1.3 KiB
TypeScript

import type { BoardFieldOp } from "@/domain/work-orders/mappers/expand-scalar-board-ops";
import type { WorkOrderTablePatch } from "@/domain/work-orders/types/work-order-table-row";
function hasScheduleRelatedPatch(patch: WorkOrderTablePatch): boolean {
return (
patch.scheduledOn !== undefined ||
patch.targetWeek !== undefined ||
patch.scheduleWeekOnly !== undefined
);
}
/** Schedule/week-only ops in the stable order the board API expects. */
export function expandScheduleBoardOps(patch: WorkOrderTablePatch): BoardFieldOp[] {
if (!hasScheduleRelatedPatch(patch)) {
return [];
}
const ops: BoardFieldOp[] = [];
if (patch.scheduleWeekOnly === true) {
ops.push({ field: "scheduleWeekOnly", value: "true" });
if (patch.targetWeek !== undefined) {
ops.push({ field: "targetWeek", value: patch.targetWeek });
}
if (patch.scheduledOn !== undefined) {
ops.push({ field: "scheduledDate", value: patch.scheduledOn });
}
return ops;
}
if (patch.scheduleWeekOnly === false) {
ops.push({ field: "scheduleWeekOnly", value: "false" });
}
if (patch.scheduledOn !== undefined) {
ops.push({ field: "scheduledDate", value: patch.scheduledOn });
}
if (patch.targetWeek !== undefined) {
ops.push({ field: "targetWeek", value: patch.targetWeek });
}
return ops;
}