Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
IndividualUsersService | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
56 | |
0.00% |
0 / 1 |
reactivateUsers | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
56 |
1 | <?php |
2 | |
3 | namespace App\Http\Services\Admin\Users; |
4 | |
5 | use App\Http\Models\Auth\User; |
6 | use Illuminate\Support\Facades\DB; |
7 | |
8 | class IndividualUsersService |
9 | { |
10 | /** |
11 | * addExistentUserByEmail. |
12 | * |
13 | * @param array $userIds |
14 | */ |
15 | public function reactivateUsers(array $userIds, $admin) |
16 | { |
17 | $users = User::withTrashed()->whereIn('_id', $userIds)->get(); |
18 | |
19 | foreach ($users as $user) { |
20 | if ($user->company_id) { |
21 | $company_id = $user->company_id; |
22 | if ($company_id) { |
23 | $company = Company::find($user->company_id); |
24 | $companyLicense = CompanyLicenses::where('company_id', $company->id)->first(); |
25 | $community = $companyLicense->business_pro_enterprise_plus ?? []; |
26 | $companyName = $company->name; |
27 | $companyEmail = $admin->email; |
28 | $isPro = in_array('yes_dedicated', $community) || in_array('yes_community', $community); |
29 | |
30 | if ($isPro) { |
31 | ReactivateUserNotification::dispatch($user->email, $companyEmail, $companyName)->delay(now()->addSeconds(2)); |
32 | } |
33 | } |
34 | |
35 | return [ |
36 | 'success' => false, |
37 | 'message' => "User with email {$user->email} is already associated with a company.", |
38 | ]; |
39 | } |
40 | } |
41 | |
42 | foreach ($users as $user) { |
43 | $user->restore(); |
44 | } |
45 | |
46 | return [ |
47 | 'success' => true, |
48 | 'message' => "Users reactivated successfully.", |
49 | ]; |
50 | } |
51 | } |