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