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