mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-28 13:06:13 +00:00
Fix validation of household address history
This commit is contained in:
parent
9a010f76cc
commit
0c75514ec4
@ -40,7 +40,7 @@ class Household implements HasCentersInterface
|
|||||||
#[Serializer\Groups(['write'])]
|
#[Serializer\Groups(['write'])]
|
||||||
#[ORM\ManyToMany(targetEntity: Address::class, cascade: ['persist', 'remove', 'merge', 'detach'])]
|
#[ORM\ManyToMany(targetEntity: Address::class, cascade: ['persist', 'remove', 'merge', 'detach'])]
|
||||||
#[ORM\JoinTable(name: 'chill_person_household_to_addresses')]
|
#[ORM\JoinTable(name: 'chill_person_household_to_addresses')]
|
||||||
#[ORM\OrderBy(['validFrom' => Criteria::DESC, 'id' => 'DESC'])]
|
#[ORM\OrderBy(['validFrom' => 'DESC', 'id' => 'DESC'])]
|
||||||
private Collection $addresses;
|
private Collection $addresses;
|
||||||
|
|
||||||
#[ORM\Embedded(class: CommentEmbeddable::class, columnPrefix: 'comment_members_')]
|
#[ORM\Embedded(class: CommentEmbeddable::class, columnPrefix: 'comment_members_')]
|
||||||
@ -592,14 +592,15 @@ class Household implements HasCentersInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[Assert\Callback]
|
#[Assert\Callback]
|
||||||
public function validate(ExecutionContextInterface $context, $payload)
|
public function validate(ExecutionContextInterface $context, $payload): void
|
||||||
{
|
{
|
||||||
$addresses = $this->getAddresses();
|
$addresses = $this->getAddressesOrdered();
|
||||||
$cond = true;
|
|
||||||
|
|
||||||
for ($i = 0; \count($addresses) - 1 > $i; ++$i) {
|
for ($i = 0; \count($addresses) - 1 > $i; ++$i) {
|
||||||
if ($addresses[$i]->getValidFrom() !== $addresses[$i + 1]->getValidTo()) {
|
if ($i === 0) {
|
||||||
$cond = false;
|
continue;
|
||||||
|
}
|
||||||
|
if ($addresses[$i - 1]->getValidTo() !== $addresses[$i]->getValidFrom()) {
|
||||||
$context->buildViolation('The address are not sequentials. The validFrom date of one address should be equal to the validTo date of the previous address.')
|
$context->buildViolation('The address are not sequentials. The validFrom date of one address should be equal to the validTo date of the previous address.')
|
||||||
->atPath('addresses')
|
->atPath('addresses')
|
||||||
->addViolation();
|
->addViolation();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user