shoc-frontend-new/src/domain/work-orders/utils/service-identity-patch.ts
2026-09-30 17:01:38 -03:00

19 lines
722 B
TypeScript

import type { WorkOrderTablePatch } from "@/domain/work-orders/types/work-order-table-row";
export function serviceIdentityPatch(
currentServiceId: string | number | null | undefined,
currentName: string,
nextName: string,
nextServiceId: string | number | null | undefined,
): Pick<WorkOrderTablePatch, "pm" | "serviceId"> {
const sameIdentity =
currentServiceId != null &&
nextServiceId != null &&
String(currentServiceId) === String(nextServiceId);
if (sameIdentity) return {};
if (nextServiceId != null) return { pm: nextName, serviceId: nextServiceId };
if (currentServiceId != null) return { pm: nextName, serviceId: null };
return nextName === currentName ? {} : { pm: nextName };
}