Cross-cutting migration affecting the entire stack: - Database: 3 migrations splitting name columns with data migration - Models: first_name/last_name on User, Person; contact_first_name/contact_last_name on Company; backward-compatible name accessors - API: all resources return first_name, last_name, full_name; assignablePersons endpoint updated - Requests: validation rules updated for all person/user/company forms - Services: VolunteerRegistrationService, ShiftAssignmentService, InvitationService updated - Frontend: TypeScript types, Zod schemas, all forms split into Voornaam/Achternaam fields - Display: all person/user name references use full_name; initials use first_name[0]+last_name[0] - Tests: all 371 tests passing - Docs: SCHEMA.md and API.md updated Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
75 lines
2.8 KiB
PHP
75 lines
2.8 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,
|
|
'first_name' => $this->first_name,
|
|
'last_name' => $this->last_name,
|
|
'full_name' => $this->full_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,
|
|
'first_name' => $match->matchedUser->first_name,
|
|
'last_name' => $match->matchedUser->last_name,
|
|
'full_name' => $match->matchedUser->full_name,
|
|
'email' => $match->matchedUser->email,
|
|
],
|
|
'matched_on' => $match->matched_on->value,
|
|
'confidence' => $match->confidence->value,
|
|
];
|
|
}
|
|
),
|
|
'crowd_list_pivot' => $this->when(
|
|
$this->pivot && $this->pivot->added_at,
|
|
fn () => [
|
|
'added_at' => $this->pivot->added_at,
|
|
'added_by_user_id' => $this->pivot->added_by_user_id,
|
|
]
|
|
),
|
|
'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()
|
|
);
|
|
},
|
|
[]
|
|
),
|
|
];
|
|
}
|
|
}
|