From fe0d1a25712e80e2a48a7e6c79ac182154486acb Mon Sep 17 00:00:00 2001 From: Alexandre Brandizzi Date: Fri, 25 Sep 2026 12:23:18 -0300 Subject: [PATCH] fix(sites): keep the legacy contact name when an update sends no contacts --- src/domain/locations/mappers/location-mapper.ts | 3 ++- .../locations/mappers/location-mapper.test.ts | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/domain/locations/mappers/location-mapper.ts b/src/domain/locations/mappers/location-mapper.ts index be3364e7..99241eb0 100644 --- a/src/domain/locations/mappers/location-mapper.ts +++ b/src/domain/locations/mappers/location-mapper.ts @@ -235,7 +235,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 4547267b..62ce35d1 100644 --- a/src/test/domain/locations/mappers/location-mapper.test.ts +++ b/src/test/domain/locations/mappers/location-mapper.test.ts @@ -107,6 +107,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", () => {