diff --git a/src/Bundle/ChillPersonBundle/Resources/public/types.ts b/src/Bundle/ChillPersonBundle/Resources/public/types.ts index cdd48e76d..7e9836f66 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/types.ts +++ b/src/Bundle/ChillPersonBundle/Resources/public/types.ts @@ -50,6 +50,10 @@ export interface Person { civility: Civility | null; current_household_id: number; current_residential_addresses: Address[]; + /** + * The person id as configured by the user + */ + personId: string; } export interface PersonIdentifierWrite { diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php index 1867b16ad..2661b1f25 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php @@ -35,6 +35,7 @@ class PersonJsonNormalizer implements NormalizerAwareInterface, NormalizerInterf private readonly CenterResolverManagerInterface $centerResolverManager, private readonly ResidentialAddressRepository $residentialAddressRepository, private readonly PhoneNumberHelperInterface $phoneNumberHelper, + private readonly \Chill\PersonBundle\PersonIdentifier\Rendering\PersonIdRenderingInterface $personIdRendering, ) {} /** @@ -67,6 +68,7 @@ class PersonJsonNormalizer implements NormalizerAwareInterface, NormalizerInterf 'email' => $person->getEmail(), 'gender' => $this->normalizer->normalize($person->getGender(), $format, $context), 'civility' => $this->normalizer->normalize($person->getCivility(), $format, $context), + 'personId' => $this->personIdRendering->renderPersonId($person), ]; if (\in_array('minimal', $groups, true) && 1 === \count($groups)) { diff --git a/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/PersonJsonNormalizerTest.php b/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/PersonJsonNormalizerTest.php index 501b42507..41aadf4fb 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/PersonJsonNormalizerTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/PersonJsonNormalizerTest.php @@ -19,6 +19,7 @@ use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\PersonAltName; use Chill\PersonBundle\Repository\ResidentialAddressRepository; use Chill\PersonBundle\Serializer\Normalizer\PersonJsonNormalizer; +use Chill\PersonBundle\PersonIdentifier\Rendering\PersonIdRenderingInterface; use Doctrine\Common\Collections\ArrayCollection; use PHPUnit\Framework\TestCase; use Prophecy\Argument; @@ -68,11 +69,13 @@ final class PersonJsonNormalizerTest extends TestCase 'email', 'gender', 'civility', + 'personId', ]; foreach ($expectedKeys as $key) { self::assertArrayHasKey($key, $data, sprintf('Key %s should be present', $key)); } + self::assertSame('PERSON-ID-RENDER', $data['personId']); // Ensure extended keys are not present in minimal mode foreach (['centers', 'altNames', 'current_household_id', 'current_residential_addresses'] as $key) { @@ -97,7 +100,7 @@ final class PersonJsonNormalizerTest extends TestCase // Base keys $baseKeys = [ - 'type', 'id', 'text', 'textAge', 'firstName', 'lastName', 'current_household_address', 'birthdate', 'deathdate', 'age', 'phonenumber', 'mobilenumber', 'email', 'gender', 'civility', + 'type', 'id', 'text', 'textAge', 'firstName', 'lastName', 'current_household_address', 'birthdate', 'deathdate', 'age', 'phonenumber', 'mobilenumber', 'email', 'gender', 'civility', 'personId', ]; foreach ($baseKeys as $key) { self::assertArrayHasKey($key, $data, sprintf('Key %s should be present', $key)); @@ -129,11 +132,15 @@ final class PersonJsonNormalizerTest extends TestCase $phoneHelper = $this->prophesize(PhoneNumberHelperInterface::class); + $personIdRendering = $this->prophesize(PersonIdRenderingInterface::class); + $personIdRendering->renderPersonId(Argument::type(Person::class))->willReturn('PERSON-ID-RENDER'); + $normalizer = new PersonJsonNormalizer( $render->reveal(), $centerResolver->reveal(), $raRepo->reveal(), $phoneHelper->reveal(), + $personIdRendering->reveal(), ); // Inner normalizer that echoes values or simple conversions