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'])]
|
||||
#[ORM\ManyToMany(targetEntity: Address::class, cascade: ['persist', 'remove', 'merge', 'detach'])]
|
||||
#[ORM\JoinTable(name: 'chill_person_household_to_addresses')]
|
||||
#[ORM\OrderBy(['validFrom' => Criteria::DESC, 'id' => 'DESC'])]
|
||||
#[ORM\OrderBy(['validFrom' => 'DESC', 'id' => 'DESC'])]
|
||||
private Collection $addresses;
|
||||
|
||||
#[ORM\Embedded(class: CommentEmbeddable::class, columnPrefix: 'comment_members_')]
|
||||
@ -592,14 +592,15 @@ class Household implements HasCentersInterface
|
||||
}
|
||||
|
||||
#[Assert\Callback]
|
||||
public function validate(ExecutionContextInterface $context, $payload)
|
||||
public function validate(ExecutionContextInterface $context, $payload): void
|
||||
{
|
||||
$addresses = $this->getAddresses();
|
||||
$cond = true;
|
||||
$addresses = $this->getAddressesOrdered();
|
||||
|
||||
for ($i = 0; \count($addresses) - 1 > $i; ++$i) {
|
||||
if ($addresses[$i]->getValidFrom() !== $addresses[$i + 1]->getValidTo()) {
|
||||
$cond = false;
|
||||
if ($i === 0) {
|
||||
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.')
|
||||
->atPath('addresses')
|
||||
->addViolation();
|
||||
|
Loading…
x
Reference in New Issue
Block a user