fix: complete InvesteMoz validation and error corrections
This commit is contained in:
@@ -1,15 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Opportunity;
|
||||
use App\Models\Sector;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
/** Tempo, 18/10/2026: existing masters, one specialization, historical combined bridge. */
|
||||
final class SectorOrganization
|
||||
{
|
||||
public const LEGACY_COMBINED = 'energia';
|
||||
|
||||
public const FINTECH = 'fintech';
|
||||
|
||||
public const LEGACY_ACTIVITY_ID = 'a2000000-0000-4000-8000-000000000002';
|
||||
|
||||
public static function href(string $slug): string
|
||||
@@ -21,7 +25,9 @@ final class SectorOrganization
|
||||
};
|
||||
}
|
||||
|
||||
/** A historical combined filter remains a union, never an arbitrary reassignment. */
|
||||
/** A historical combined filter remains a union, never an arbitrary reassignment.
|
||||
* @return list<string>
|
||||
*/
|
||||
public static function slugs(string $slug): array
|
||||
{
|
||||
return match ($slug) {
|
||||
@@ -32,17 +38,27 @@ final class SectorOrganization
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<Opportunity> $query
|
||||
* @return Builder<Opportunity>
|
||||
*/
|
||||
public static function constrain(Builder $query, string $slug): Builder
|
||||
{
|
||||
return $query->whereHas('sector', fn ($s) => $s->whereIn('slug', self::slugs($slug)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Builder<Opportunity>
|
||||
*/
|
||||
public static function opportunities(Sector $sector): Builder
|
||||
{
|
||||
return self::constrain(Opportunity::published(), $sector->slug);
|
||||
}
|
||||
|
||||
public static function catalog()
|
||||
/**
|
||||
* @return Collection<int, Sector>
|
||||
*/
|
||||
public static function catalog(): Collection
|
||||
{
|
||||
return Sector::catalog()->orderBy('sort_order')->get()->each(function ($sector) {
|
||||
$sector->setAttribute('opportunities_count', self::opportunities($sector)->count());
|
||||
|
||||
Reference in New Issue
Block a user