21 lines
698 B
PHP
21 lines
698 B
PHP
<?php
|
|
|
|
namespace App\Services\Mne;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
final class IdentityResolver
|
|
{
|
|
public function resolve(int $userId): ?string
|
|
{
|
|
$id = DB::table('mne.identity_links as l')->join('mne.parties as p', 'p.id', '=', 'l.party_id')
|
|
->join('public.users as u', 'u.id', '=', 'l.user_id')
|
|
->where('l.user_id', $userId)->where('l.status', 'active')->where('p.party_type', 'person')
|
|
->whereNull('p.deleted_at')->where('l.valid_from', '<=', now())
|
|
->where(fn ($q) => $q->whereNull('l.valid_until')->orWhere('l.valid_until', '>', now()))
|
|
->value('l.party_id');
|
|
|
|
return is_string($id) ? $id : null;
|
|
}
|
|
}
|