2026-09-16 13:17:02 -03:00
|
|
|
import type { VendorCompanyRoster } from "@/domain/vendors/types/vendor";
|
|
|
|
|
import type { VendorRosterAdditivePatch } from "@/domain/vendors/mappers/vendor-roster-mapper";
|
|
|
|
|
|
|
|
|
|
export type VendorCompanyNotesBaseline = Pick<
|
|
|
|
|
VendorCompanyRoster,
|
|
|
|
|
"companyId" | "rowVersion" | "notes"
|
|
|
|
|
>;
|
|
|
|
|
|
|
|
|
|
export interface VendorCompanyNotesUpdate {
|
|
|
|
|
companyId: string | number;
|
|
|
|
|
patch: VendorRosterAdditivePatch;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-09-16 15:18:06 -03:00
|
|
|
* Company-level notes edited outside the Vendors page (e.g. the Create WO wizard)
|
2026-09-16 13:17:02 -03:00
|
|
|
* are written through the additive roster PATCH, which only touches the fields sent.
|
|
|
|
|
* Returns null when nothing changed. Clearing notes is not expressible on that PATCH
|
|
|
|
|
* (blank company fields mean "unchanged"), so an emptied field is not sent.
|
|
|
|
|
*/
|
|
|
|
|
export function buildCompanyNotesUpdate(
|
|
|
|
|
baseline: VendorCompanyNotesBaseline | null | undefined,
|
|
|
|
|
editedNotes: string,
|
|
|
|
|
): VendorCompanyNotesUpdate | null {
|
|
|
|
|
if (!baseline || baseline.companyId === null || !baseline.rowVersion) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
const notes = editedNotes.trim();
|
|
|
|
|
if (!notes || notes === baseline.notes.trim()) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
companyId: baseline.companyId,
|
|
|
|
|
patch: { rowVersion: baseline.rowVersion, addTechnicians: [], companyFields: { notes } },
|
|
|
|
|
};
|
|
|
|
|
}
|