Files
crewli/api/app/Http/Resources/Api/V1/PersonResource.php
bert.hausmans 4b182b449a feat: person identity matching with detection, confirmation and audit trail
Implements enterprise-grade identity resolution (detect → suggest → confirm)
for Person ↔ User linking. Matches are detected automatically on person
creation and user account creation, then surfaced to organisers for explicit
confirmation or dismissal. No silent auto-linking.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 12:50:25 +02:00

64 lines
2.3 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Resources\Api\V1;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
final class PersonResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'event_id' => $this->event_id,
'name' => $this->name,
'email' => $this->email,
'phone' => $this->phone,
'status' => $this->status,
'is_blacklisted' => $this->is_blacklisted,
'admin_notes' => $this->admin_notes,
'custom_fields' => $this->custom_fields,
'created_at' => $this->created_at->toIso8601String(),
'crowd_type' => new CrowdTypeResource($this->whenLoaded('crowdType')),
'company' => new CompanyResource($this->whenLoaded('company')),
'pending_identity_match' => $this->when(
$this->relationLoaded('pendingIdentityMatch') && $this->pendingIdentityMatch,
function () {
$match = $this->pendingIdentityMatch;
return [
'match_id' => $match->id,
'matched_user' => [
'id' => $match->matchedUser->id,
'name' => $match->matchedUser->name,
'email' => $match->matchedUser->email,
],
'matched_on' => $match->matched_on->value,
'confidence' => $match->confidence->value,
];
}
),
'tags' => $this->when(
$this->user_id && $this->relationLoaded('user'),
function () {
$orgId = $this->event?->organisation_id;
if (!$orgId || !$this->user) {
return [];
}
return UserOrganisationTagResource::collection(
$this->user->organisationTags()
->where('organisation_id', $orgId)
->with('personTag')
->get()
);
},
[]
),
];
}
}