mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-07 16:19:01 +00:00
Late roster data no longer overwrites notes typed for the current selection. The notes baseline is keyed by vendor, so a save never patches a previous company. Changing the primary service clears leftover notes, and a save with a missing baseline reads the current roster first. Also drops ticket keys from shipped comments. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
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;
|
|
}
|
|
|
|
/**
|
|
* Company-level notes edited outside the Vendors page (e.g. the Create WO wizard)
|
|
* 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 } },
|
|
};
|
|
}
|