shoc-frontend-new/src/domain/work-orders/mappers/doc-status-mapper.ts
Arthur Bassi 2d64c34898 fix(work-orders): extract docStatus mapper for governance ratchet
Keep work-order-mapper under the frozen line cap and cap addDispatchSignoff params.
2026-07-29 09:31:15 -03:00

28 lines
872 B
TypeScript

import type { CompletionDocStatus } from "@/domain/work-orders/types/work-order-table-row";
/** UI uses `NN`; board/API enum uses `NotNeeded` (also numeric 3). */
export function mapDocStatusToApi(value: string): string {
if (value === "NN") {
return "NotNeeded";
}
return value;
}
export function readDocStatusFromRecord(record: Record<string, unknown>): CompletionDocStatus {
const rawValue =
record.docStatus ?? record.DocStatus ?? record.completionDoc ?? record.CompletionDoc;
if (typeof rawValue === "number") {
if (rawValue === 1) return "Yes";
if (rawValue === 2) return "No";
if (rawValue === 3) return "NN";
}
if (typeof rawValue === "string") {
if (rawValue === "Yes" || rawValue === "No" || rawValue === "NN") {
return rawValue;
}
if (rawValue === "NotNeeded") {
return "NN";
}
}
return "";
}