mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-09-30 04:33:11 +00:00
71 lines
3 KiB
TypeScript
71 lines
3 KiB
TypeScript
import type { WorkOrderBoardEditableField } from "@/domain/work-orders/types/work-order-board";
|
|
import type { WorkOrderTablePatch } from "@/domain/work-orders/types/work-order-table-row";
|
|
import type { WorkOrderAdditionalContact } from "@/domain/work-orders/types/work-order-additional-contact";
|
|
import { serializeAdditionalContactsForPatch } from "@/domain/work-orders/mappers/additional-contacts-mapper";
|
|
import { mapDocStatusToApi } from "@/domain/work-orders/mappers/doc-status-mapper";
|
|
|
|
export type BoardFieldOp = {
|
|
field: WorkOrderBoardEditableField;
|
|
value: string;
|
|
technicianAssigned?: boolean;
|
|
};
|
|
|
|
export { mapDocStatusToApi };
|
|
|
|
type ScalarBoardOpRule = {
|
|
key: keyof WorkOrderTablePatch;
|
|
field: WorkOrderBoardEditableField;
|
|
toValue: (value: unknown) => string;
|
|
};
|
|
|
|
/** One row per scalar patch field, in emission order. */
|
|
const SCALAR_BOARD_OP_RULES: ScalarBoardOpRule[] = [
|
|
{ key: "woNumber", field: "woNumber", toValue: (value) => value as string },
|
|
// Severity before type so Emergency/Reactive never land without required severity.
|
|
{
|
|
key: "severity",
|
|
field: "severity",
|
|
toValue: (value) => (value == null ? "" : String(value)),
|
|
},
|
|
{ key: "type", field: "workOrderType", toValue: (value) => value as string },
|
|
{ key: "site", field: "siteCode", toValue: (value) => value as string },
|
|
{ key: "status", field: "lifecycleStatus", toValue: (value) => value as string },
|
|
{ key: "dispatcherId", field: "assignTo", toValue: (value) => value as string },
|
|
{ key: "dueDate", field: "dueDate", toValue: (value) => value as string },
|
|
{ key: "vendorId", field: "vendorId", toValue: (value) => String(value) },
|
|
{ key: "apptTime", field: "apptTime", toValue: (value) => value as string },
|
|
{ key: "docStatus", field: "docStatus", toValue: (value) => mapDocStatusToApi(value as string) },
|
|
{ key: "completedDate", field: "completedDate", toValue: (value) => value as string },
|
|
{ key: "pm", field: "pm", toValue: (value) => value as string },
|
|
{ key: "extraServices", field: "extraServices", toValue: (value) => JSON.stringify(value) },
|
|
{ key: "serviceNotes", field: "serviceNotes", toValue: (value) => value as string },
|
|
{
|
|
key: "avetaRequired",
|
|
field: "avetaRequired",
|
|
toValue: (value) => (value ? "true" : "false"),
|
|
},
|
|
{ key: "flagColor", field: "flagColor", toValue: (value) => (value as string | null) ?? "" },
|
|
{
|
|
key: "additionalContacts",
|
|
field: "additionalContacts",
|
|
toValue: (value) => serializeAdditionalContactsForPatch(value as WorkOrderAdditionalContact[]),
|
|
},
|
|
];
|
|
|
|
export function expandScalarBoardOps(patch: WorkOrderTablePatch): BoardFieldOp[] {
|
|
const ops: BoardFieldOp[] = [];
|
|
|
|
for (const rule of SCALAR_BOARD_OP_RULES) {
|
|
const value = patch[rule.key];
|
|
if (value === undefined) continue;
|
|
ops.push({
|
|
field: rule.field,
|
|
value: rule.toValue(value),
|
|
...(rule.key === "vendorId" && patch.technicianAssigned != null
|
|
? { technicianAssigned: patch.technicianAssigned }
|
|
: {}),
|
|
});
|
|
}
|
|
|
|
return ops;
|
|
}
|