fix: complete InvesteMoz validation and error corrections

This commit is contained in:
2026-10-29 21:47:33 +02:00
parent 63147312e2
commit daf8623441
718 changed files with 127308 additions and 20959 deletions
+25 -3
View File
@@ -23,17 +23,26 @@ final class ClusterCompetitiveness
->where('entity_type', 'economic_clusters')->where('entity_id', $cluster);
}
private function decode(?object $event): array
/**
* @return array<array-key, mixed>
*/
private function decode(?\stdClass $event): array
{
return $event ? json_decode(Crypt::decryptString(json_decode($event->after_data, true, 512, JSON_THROW_ON_ERROR)['snapshot']), true, 512, JSON_THROW_ON_ERROR)
: ['version' => 0, 'draft' => null, 'approved' => null];
}
/**
* @return array<array-key, mixed>
*/
public function current(string $cluster): array
{
return $this->decode($this->events($cluster)->orderByRaw("(after_data->>'version')::integer DESC")->first());
}
/**
* @return array<array-key, mixed>
*/
public function management(string $cluster): array
{
$state = $this->current($cluster);
@@ -44,6 +53,10 @@ final class ClusterCompetitiveness
return $state;
}
/**
* @param array<array-key, mixed> $draft
* @return array<array-key, mixed>
*/
public function validateDraft(array $draft, string $cluster): array
{
$rules = ['version' => 'required|integer|in:1', 'clusterId' => 'required|string|in:'.$cluster,
@@ -69,6 +82,9 @@ final class ClusterCompetitiveness
return $clean;
}
/**
* @param array<array-key, mixed>|null $draft
*/
private function assertComplete(?array $draft): void
{
$missing = ! $draft || ! $draft['sector'] || ! $draft['region'];
@@ -84,7 +100,10 @@ final class ClusterCompetitiveness
}
}
/** Reuse the portal's encrypted, append-only audit snapshots; no new schema or mutable publication fields. */
/** Reuse the portal's encrypted, append-only audit snapshots; no new schema or mutable publication fields.
* @param array<array-key, mixed> $input
* @return array<array-key, mixed>
*/
public function change(EconomicCluster $cluster, int $actor, int $expected, string $action, array $input = []): array
{
return DB::transaction(function () use ($cluster, $actor, $expected, $action, $input) {
@@ -96,7 +115,7 @@ final class ClusterCompetitiveness
$state['draft'] = $this->validateDraft($input['draft'], $cluster->id);
} elseif ($action === 'restored') {
$event = $this->events($cluster->id)->where('after_data->version', $input['revision'])->first();
abort_unless($event, 404);
abort_unless($event !== null, 404);
$state['draft'] = $this->decode($event)['draft'];
} elseif ($action === 'approved') {
$this->assertComplete($state['draft']);
@@ -120,6 +139,9 @@ final class ClusterCompetitiveness
});
}
/**
* @return array<array-key, mixed>|null
*/
public function publicData(string $cluster): ?array
{
$approved = $this->current($cluster)['approved'];