Files
Investidor-V2/app/Services/Mne/SectorResolver.php
T
nala 3dc7c5c649
tests / ci (push) Canceled after 0s
commit 30/9
2026-09-30 09:05:43 +02:00

23 lines
772 B
PHP

<?php
namespace App\Services\Mne;
use Illuminate\Support\Facades\DB;
final class SectorResolver
{
public const VERSION = 1;
public function resolve(int $legacyId): ?string
{
$id = DB::table('mne.sector_links as l')->join('public.sectors as s', 's.id', '=', 'l.sector_id')
->where('l.sector_id', $legacyId)->where('l.resolver_version', self::VERSION)
->where('l.status', 'active')->where('s.is_active', true)->whereNull('s.deleted_at')
->whereColumn('l.source_code', 's.slug')->where('l.valid_from', '<=', now())
->where(fn ($q) => $q->whereNull('l.valid_until')->orWhere('l.valid_until', '>', now()))
->value('l.canonical_sector_id');
return is_string($id) ? $id : null;
}
}