diff --git a/src/domain/locations/mappers/location-mapper.ts b/src/domain/locations/mappers/location-mapper.ts index dcb5bf2f..dfb0a25f 100644 --- a/src/domain/locations/mappers/location-mapper.ts +++ b/src/domain/locations/mappers/location-mapper.ts @@ -236,7 +236,8 @@ export function mapLocationToBackend(location: unknown): Record state: item.state ?? "", zipCode: item.zipCode ?? "", phone: typeof item.sitePhone === "string" ? item.sitePhone.trim() : "", - contact: mainContact ? mainContact.name : "", + // A caller without a contacts list (e.g. address-only sync) keeps the stored legacy name. + contact: mainContact ? mainContact.name : readString(item, "contact").trim(), contactEmail: typeof item.contactEmail === "string" ? item.contactEmail.trim() : "", accountId: item.accountId ?? "", contacts, diff --git a/src/test/domain/locations/mappers/location-mapper.test.ts b/src/test/domain/locations/mappers/location-mapper.test.ts index 82a0865e..cd8734ce 100644 --- a/src/test/domain/locations/mappers/location-mapper.test.ts +++ b/src/test/domain/locations/mappers/location-mapper.test.ts @@ -108,6 +108,21 @@ describe("mapLocationToBackend site payload", () => { expect(bare).not.toHaveProperty("notes"); expect(full).toMatchObject({ status: "Active", title: "Dallas DC", notes: "Gate code 1234" }); }); + + it("keeps the legacy contact name when the caller sends no contacts list", () => { + const addressOnly = mapLocationToBackend({ + name: "DAL1", + address: "3811 Distribution Dr", + contact: "Jane Doe", + }); + const withContacts = mapLocationToBackend({ + contact: "Jane Doe", + contacts: [{ name: "Bob", phone: "(421) 433-0033" }], + }); + + expect(addressOnly.contact).toBe("Jane Doe"); + expect(withContacts.contact).toBe("Bob"); + }); }); describe("mapLocation site fields", () => {