From 04d9940317641b1f9a45a6095350b3075710fe2e Mon Sep 17 00:00:00 2001 From: Francisco Solla Date: Tue, 11 Aug 2026 14:01:01 -0300 Subject: [PATCH] fix(C116): editor de Contato convive com o shape phones do C112 (primary phone via reorderWithPrimaryPhone) --- src/app/(campaign)/campanha/actions/person.ts | 24 +++++++++++++++++-- .../int/campaignPersonCellEditing.int.spec.ts | 4 +++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/app/(campaign)/campanha/actions/person.ts b/src/app/(campaign)/campanha/actions/person.ts index 89d79498..a2a6283a 100644 --- a/src/app/(campaign)/campanha/actions/person.ts +++ b/src/app/(campaign)/campanha/actions/person.ts @@ -4,6 +4,7 @@ import { revalidatePath } from 'next/cache' import { toggleMunicipalityAdvisorMembership } from '@/app/(campaign)/campanha/actions/municipality' import { nextLeadershipAdvisorIdsAfterMembership } from '@/lib/leadershipAdvisorMembership' +import { reorderWithPrimaryPhone } from '@/lib/phone' import { uniqueRelationshipIds } from '@/lib/relationship' import { contactFieldUpdateSchema, type ContactFieldUpdateInput } from '@/lib/schemas/contact' import { @@ -123,13 +124,32 @@ export const updatePersonContactRecord = async ( await assertPersonContactEditable(payload, currentActor, data.id, req) - const contactData: Partial> = {} + const contactData: Partial> & { + phones?: { value: string }[] + } = {} if (data.field === 'name') { contactData.name = data.name } else if (data.field === 'email') { contactData.email = data.email ?? null } else if (data.field === 'phone') { - contactData.phone = data.phone + // Inline cell edit = set the PRIMARY phone, keeping the rest of the + // list untouched (C112 shape — same contract as the leadership and + // dobradinha siblings): the new number goes first, clearing removes + // the primary and the rest shifts up. + const current = await payload.findByID({ + collection: 'contact', + id: data.id, + depth: 0, + select: { phones: true }, + // Intentional bypass: the scope check above established the actor's + // right over the person's ficha; this read only resolves the current + // primary-phone list to reorder. + overrideAccess: true, + req, + }) + contactData.phones = reorderWithPrimaryPhone(current.phones, data.phone).map((value) => ({ + value, + })) } else if (data.field === 'city') { contactData.city = data.city } diff --git a/tests/int/campaignPersonCellEditing.int.spec.ts b/tests/int/campaignPersonCellEditing.int.spec.ts index 406a4130..f8a1dfda 100644 --- a/tests/int/campaignPersonCellEditing.int.spec.ts +++ b/tests/int/campaignPersonCellEditing.int.spec.ts @@ -9,6 +9,7 @@ import { setPersonAssessoraMembershipRecord, updatePersonContactRecord, } from '@/app/(campaign)/campanha/actions/person' +import { primaryPhoneOf } from '@/lib/phone' import { uniqueRelationshipIds } from '@/lib/relationship' import { PERSON_ADVISORS_UNRESTRICTED_MESSAGE, @@ -67,7 +68,8 @@ describe('C116 — cell edits of the people list', () => { }) expect(updated.name).toBe('Maria Nova da Silva') expect(updated.city).toBe('Salvador') - expect(updated.phone).toBe('71999998888') + // C112 shape: the cell edit set the PRIMARY phone, the ficha list carries it first. + expect(primaryPhoneOf(updated.phones)).toBe('71999998888') }) it('lets an advisor edit a person anchored in his carteira', async () => {