Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ResendAllInvitationsService | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| resendAll | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Services\Company; |
| 4 | |
| 5 | use App\Http\Models\Admin\Company; |
| 6 | use App\Http\Models\Auth\User; |
| 7 | use App\Http\Repositories\AdminUserInvitationRepository; |
| 8 | use App\Jobs\ResendCompanyInvitationJob; |
| 9 | |
| 10 | /** |
| 11 | * Service for bulk-resending company invitations. |
| 12 | * |
| 13 | * Orchestrates fetching all pending invitations for a company and |
| 14 | * dispatching an async job for each one. The HTTP response is returned |
| 15 | * immediately after all jobs are queued — email delivery is non-blocking. |
| 16 | */ |
| 17 | class ResendAllInvitationsService |
| 18 | { |
| 19 | /** |
| 20 | * Create a new service instance. |
| 21 | * |
| 22 | * @param AdminUserInvitationRepository $invitationRepository Data access for invitations |
| 23 | */ |
| 24 | public function __construct( |
| 25 | private readonly AdminUserInvitationRepository $invitationRepository, |
| 26 | ) {} |
| 27 | |
| 28 | /** |
| 29 | * Queue a resend job for every pending invitation belonging to the company. |
| 30 | * |
| 31 | * Each invitation is dispatched as an independent queue job so that |
| 32 | * a failure for one invitee does not block others from being resent. |
| 33 | * |
| 34 | * @param Company $company The company whose invitations will be resent |
| 35 | * @param User $admin The admin user triggering the resend (used as inviter in emails) |
| 36 | * @return int Number of jobs queued |
| 37 | */ |
| 38 | public function resendAll(Company $company, User $admin): int |
| 39 | { |
| 40 | $invitations = $this->invitationRepository->getPendingByCompanyId((string) $company->_id); |
| 41 | |
| 42 | foreach ($invitations as $invitation) { |
| 43 | ResendCompanyInvitationJob::dispatch( |
| 44 | $invitation->email, |
| 45 | $admin->email, |
| 46 | $company, |
| 47 | )->onQueue('high'); |
| 48 | } |
| 49 | |
| 50 | return $invitations->count(); |
| 51 | } |
| 52 | } |