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>
89 lines
2.6 KiB
PHP
89 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Api\V1;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Api\V1\AcceptInvitationRequest;
|
|
use App\Http\Requests\Api\V1\StoreInvitationRequest;
|
|
use App\Http\Resources\Api\V1\InvitationResource;
|
|
use App\Models\Organisation;
|
|
use App\Models\UserInvitation;
|
|
use App\Services\InvitationService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
final class InvitationController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly InvitationService $invitationService,
|
|
) {}
|
|
|
|
public function invite(StoreInvitationRequest $request, Organisation $organisation): JsonResponse
|
|
{
|
|
Gate::authorize('invite', $organisation);
|
|
|
|
$invitation = $this->invitationService->invite(
|
|
$organisation,
|
|
$request->validated('email'),
|
|
$request->validated('role'),
|
|
$request->user(),
|
|
);
|
|
|
|
return $this->created(
|
|
new InvitationResource($invitation->load(['organisation', 'invitedBy'])),
|
|
'Uitnodiging verstuurd',
|
|
);
|
|
}
|
|
|
|
public function show(string $token): JsonResponse
|
|
{
|
|
$invitation = UserInvitation::where('token', $token)
|
|
->with(['organisation', 'invitedBy'])
|
|
->first();
|
|
|
|
if (! $invitation) {
|
|
return $this->notFound('Uitnodiging niet gevonden');
|
|
}
|
|
|
|
return $this->success(new InvitationResource($invitation));
|
|
}
|
|
|
|
public function accept(AcceptInvitationRequest $request, string $token): JsonResponse
|
|
{
|
|
$invitation = UserInvitation::where('token', $token)->firstOrFail();
|
|
|
|
$user = $this->invitationService->accept(
|
|
$invitation,
|
|
$request->validated('password'),
|
|
);
|
|
|
|
$sanctumToken = $user->createToken('auth-token')->plainTextToken;
|
|
|
|
return $this->success([
|
|
'user' => [
|
|
'id' => $user->id,
|
|
'first_name' => $user->first_name,
|
|
'last_name' => $user->last_name,
|
|
'full_name' => $user->full_name,
|
|
'email' => $user->email,
|
|
],
|
|
'token' => $sanctumToken,
|
|
], 'Uitnodiging geaccepteerd');
|
|
}
|
|
|
|
public function revoke(Organisation $organisation, UserInvitation $invitation): JsonResponse
|
|
{
|
|
Gate::authorize('invite', $organisation);
|
|
|
|
if (! $invitation->isPending()) {
|
|
return $this->error('Alleen openstaande uitnodigingen kunnen worden ingetrokken.', 422);
|
|
}
|
|
|
|
$invitation->markAsExpired();
|
|
|
|
return response()->json(null, 204);
|
|
}
|
|
}
|