mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-28 15:43:10 +00:00
fix(C116): editor de Contato convive com o shape phones do C112 (primary phone via reorderWithPrimaryPhone)
This commit is contained in:
parent
a83bedd7a8
commit
04d9940317
2 changed files with 25 additions and 3 deletions
|
|
@ -4,6 +4,7 @@ import { revalidatePath } from 'next/cache'
|
||||||
|
|
||||||
import { toggleMunicipalityAdvisorMembership } from '@/app/(campaign)/campanha/actions/municipality'
|
import { toggleMunicipalityAdvisorMembership } from '@/app/(campaign)/campanha/actions/municipality'
|
||||||
import { nextLeadershipAdvisorIdsAfterMembership } from '@/lib/leadershipAdvisorMembership'
|
import { nextLeadershipAdvisorIdsAfterMembership } from '@/lib/leadershipAdvisorMembership'
|
||||||
|
import { reorderWithPrimaryPhone } from '@/lib/phone'
|
||||||
import { uniqueRelationshipIds } from '@/lib/relationship'
|
import { uniqueRelationshipIds } from '@/lib/relationship'
|
||||||
import { contactFieldUpdateSchema, type ContactFieldUpdateInput } from '@/lib/schemas/contact'
|
import { contactFieldUpdateSchema, type ContactFieldUpdateInput } from '@/lib/schemas/contact'
|
||||||
import {
|
import {
|
||||||
|
|
@ -123,13 +124,32 @@ export const updatePersonContactRecord = async (
|
||||||
|
|
||||||
await assertPersonContactEditable(payload, currentActor, data.id, req)
|
await assertPersonContactEditable(payload, currentActor, data.id, req)
|
||||||
|
|
||||||
const contactData: Partial<Pick<Contact, 'name' | 'phone' | 'email' | 'city'>> = {}
|
const contactData: Partial<Pick<Contact, 'name' | 'email' | 'city'>> & {
|
||||||
|
phones?: { value: string }[]
|
||||||
|
} = {}
|
||||||
if (data.field === 'name') {
|
if (data.field === 'name') {
|
||||||
contactData.name = data.name
|
contactData.name = data.name
|
||||||
} else if (data.field === 'email') {
|
} else if (data.field === 'email') {
|
||||||
contactData.email = data.email ?? null
|
contactData.email = data.email ?? null
|
||||||
} else if (data.field === 'phone') {
|
} 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') {
|
} else if (data.field === 'city') {
|
||||||
contactData.city = data.city
|
contactData.city = data.city
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import {
|
||||||
setPersonAssessoraMembershipRecord,
|
setPersonAssessoraMembershipRecord,
|
||||||
updatePersonContactRecord,
|
updatePersonContactRecord,
|
||||||
} from '@/app/(campaign)/campanha/actions/person'
|
} from '@/app/(campaign)/campanha/actions/person'
|
||||||
|
import { primaryPhoneOf } from '@/lib/phone'
|
||||||
import { uniqueRelationshipIds } from '@/lib/relationship'
|
import { uniqueRelationshipIds } from '@/lib/relationship'
|
||||||
import {
|
import {
|
||||||
PERSON_ADVISORS_UNRESTRICTED_MESSAGE,
|
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.name).toBe('Maria Nova da Silva')
|
||||||
expect(updated.city).toBe('Salvador')
|
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 () => {
|
it('lets an advisor edit a person anchored in his carteira', async () => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue