Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 46 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| CMCEditUserResource | |
0.00% |
0 / 46 |
|
0.00% |
0 / 3 |
110 | |
0.00% |
0 / 1 |
| toArray | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| buildUser | |
0.00% |
0 / 44 |
|
0.00% |
0 / 1 |
72 | |||
| getInvitationLinkForAdminPortal | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Resources; |
| 4 | |
| 5 | use App\Http\Models\Admin\AdminUserInvitation; |
| 6 | use App\Http\Models\HubspotProperties; |
| 7 | use Illuminate\Http\Request; |
| 8 | use Illuminate\Support\Carbon; |
| 9 | use App\Traits\SubscriptionTrait; |
| 10 | use Illuminate\Http\Resources\Json\JsonResource; |
| 11 | |
| 12 | class CMCEditUserResource extends JsonResource |
| 13 | { |
| 14 | use SubscriptionTrait; |
| 15 | |
| 16 | /** |
| 17 | * Transform the resource into an array. |
| 18 | * |
| 19 | * @return array<string, mixed> |
| 20 | */ |
| 21 | public function toArray(Request $request): array |
| 22 | { |
| 23 | return $this->buildUser($this); |
| 24 | } |
| 25 | |
| 26 | private function buildUser($model) |
| 27 | { |
| 28 | $group_name = $model->company_group?->name ?? "Not Assigned"; |
| 29 | $subgroup_name = $model->company_group?->name ?? "Not Assigned"; |
| 30 | |
| 31 | $statusDate = match (true) { |
| 32 | !is_null($model->deactivated_at ?? null) => $model->deactivated_at->toFormattedDateString(), |
| 33 | !is_null($model->activation_date ?? null) => Carbon::parse($model->activation_date)->toFormattedDateString(), |
| 34 | !is_null($model->created_at) => $model->created_at->toFormattedDateString(), |
| 35 | default => null, |
| 36 | }; |
| 37 | |
| 38 | $status = match (true) { |
| 39 | filled($model->deactivated_at ?? null) || filled($model->deleted_at ?? null) => "Deactivated", |
| 40 | filled($model->status ?? null) && $model->status == 'Invited' => "Invited", |
| 41 | default => "Active", |
| 42 | }; |
| 43 | |
| 44 | $roles = $model->role; |
| 45 | $role = role($roles); |
| 46 | $extension = "No"; |
| 47 | $plan_name = $this->getCurrentPlan($this)->title; |
| 48 | |
| 49 | if ($status == "Active") { |
| 50 | $hubspot = HubspotProperties::firstWhere("flymsg_id", $this->id); |
| 51 | $extension = ($hubspot?->flymsg_chrome_extension_installed == "Yes" || $hubspot?->flymsg_edge_extension_installed == "Yes") ? "Yes" : "No"; |
| 52 | } |
| 53 | |
| 54 | if ($model->company->deactivated_at ?? null) { |
| 55 | $status = "Deactivated"; |
| 56 | } |
| 57 | |
| 58 | return [ |
| 59 | 'id' => $model->id, |
| 60 | 'first_name' => $model->first_name, |
| 61 | 'last_name' => $model->last_name, |
| 62 | 'name' => $model->first_name . " " . $model->last_name, |
| 63 | 'email' => $model->email, |
| 64 | 'company' => $model->company?->name ?? "Individuals", |
| 65 | 'company_id' => $model->company_id ?? null, |
| 66 | 'company_slug' => $model->company?->slug ?? null, |
| 67 | 'company_has_groups' => count($model->company?->groupsAndSubgroups ?? []) > 0, |
| 68 | 'groups_admin' => $model->sales_pro_team_manager?->company_group_ids ?? null, |
| 69 | 'extension' => $extension, |
| 70 | 'role' => $role, |
| 71 | 'group' => $group_name, |
| 72 | 'subgroup' => $subgroup_name, |
| 73 | 'licenseType' => $plan_name, |
| 74 | 'status' => $status, |
| 75 | 'is_invite' => $model instanceof AdminUserInvitation ? true : false, |
| 76 | 'invitation_link' => $this->getInvitationLinkForAdminPortal($model), |
| 77 | 'created_at' => $model->created_at ?? $model->updated_at ?? Carbon::now(), |
| 78 | 'statusDate' => $statusDate, |
| 79 | ]; |
| 80 | } |
| 81 | |
| 82 | private function getInvitationLinkForAdminPortal($model) |
| 83 | { |
| 84 | return config('romeo.frontend-base-url') . "/session/signup?email=" . $model['email']; |
| 85 | } |
| 86 | } |