Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ResendAllInvitationsController
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 resendAll
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\Http\Controllers\v2\Company;
4
5use App\Http\Controllers\Controller;
6use App\Http\Requests\v2\Company\ResendAllInvitationsRequest;
7use App\Http\Resources\v2\Company\ResendAllInvitationsResource;
8use App\Http\Services\Company\ResendAllInvitationsService;
9
10/**
11 * Controller for resending all pending invitations for a company.
12 *
13 * Endpoint: POST /romeo/api/v2/admin/company/{slug}/users/resend-all-invitations
14 *
15 * Authorization (enforced in layers):
16 * - check.company.admin middleware: blocks users not belonging to the company (unless Vengreso Admin)
17 * - ResendAllInvitationsRequest::authorize(): further restricts to Global Admin or Vengreso Admin
18 *
19 * The company model is injected into the request by the check.company.admin middleware.
20 * Each invitation email is queued asynchronously — the response returns immediately.
21 */
22class ResendAllInvitationsController extends Controller
23{
24    /**
25     * Create a new controller instance.
26     *
27     * @param  ResendAllInvitationsService  $service  Business logic handler
28     */
29    public function __construct(
30        private readonly ResendAllInvitationsService $service,
31    ) {}
32
33    /**
34     * Queue resend jobs for all pending invitations belonging to the company.
35     *
36     * @param  ResendAllInvitationsRequest  $request  Validated and authorized request
37     *
38     * @response 200 {
39     *   "result": {
40     *     "queued": 5,
41     *     "message": "5 invitation(s) queued for resend."
42     *   }
43     * }
44     */
45    public function resendAll(ResendAllInvitationsRequest $request): ResendAllInvitationsResource
46    {
47        $queued = $this->service->resendAll($request->company, auth()->user());
48
49        return new ResendAllInvitationsResource(['queued' => $queued]);
50    }
51}