mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-09-02 05:10:59 +00:00
* refactor: stabilize model identities for domain migration * refactor: extract module platform context * refactor: assign models to domain contexts * refactor: extract ai platform context * refactor: extract storage platform context * refactor: extract mail platform context * refactor: extract pdf platform context * refactor: extract operations platform context * refactor: move installation into operations platform * refactor: extract money domain context * refactor: extract taxation domain context * refactor: extract catalog domain context * refactor: extract metadata domain context * refactor: extract reporting domain context * refactor: extract purchases domain context * refactor: extract receivables domain context * refactor: extract accounts domain context * refactor: complete reporting statement boundary * refactor: extract contacts domain context * refactor: extract sales domain context * refactor: remove legacy application layers * fix: migrate legacy bouncer role identities
70 lines
2.0 KiB
PHP
70 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Accounts\Http\Controllers\Company;
|
|
|
|
use App\Domains\Accounts\Application\InvitationService;
|
|
use App\Domains\Accounts\Http\Resources\CompanyInvitationResource;
|
|
use App\Domains\Accounts\Models\Company;
|
|
use App\Domains\Accounts\Models\CompanyInvitation;
|
|
use App\Platform\Http\Controller;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class InvitationController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly InvitationService $invitationService,
|
|
) {}
|
|
|
|
public function index(Request $request): JsonResponse
|
|
{
|
|
$company = Company::find($request->header('company'));
|
|
|
|
$invitations = CompanyInvitation::where('company_id', $company->id)
|
|
->pending()
|
|
->with(['role', 'invitedBy'])
|
|
->latest()
|
|
->get();
|
|
|
|
return response()->json([
|
|
'invitations' => CompanyInvitationResource::collection($invitations),
|
|
]);
|
|
}
|
|
|
|
public function store(Request $request): JsonResponse
|
|
{
|
|
$request->validate([
|
|
'email' => 'required|email',
|
|
'role_id' => 'required|exists:roles,id',
|
|
]);
|
|
|
|
$company = Company::find($request->header('company'));
|
|
|
|
$invitation = $this->invitationService->invite(
|
|
$company,
|
|
$request->email,
|
|
$request->role_id,
|
|
$request->user()
|
|
);
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'invitation' => new CompanyInvitationResource($invitation->load(['company', 'role', 'invitedBy'])),
|
|
]);
|
|
}
|
|
|
|
public function destroy(CompanyInvitation $companyInvitation): JsonResponse
|
|
{
|
|
if ($companyInvitation->status !== CompanyInvitation::STATUS_PENDING) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => 'Only pending invitations can be cancelled.',
|
|
], 422);
|
|
}
|
|
|
|
$companyInvitation->delete();
|
|
|
|
return response()->json(['success' => true]);
|
|
}
|
|
}
|