Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
ReportingUserDetailsRequest | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 1 |
execute | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace App\Actions; |
4 | |
5 | use App\DTO\ReportingUserDetailsRequestDTO; |
6 | use App\Http\Models\Auth\User; |
7 | use App\Http\Models\HubspotProperties; |
8 | use App\Http\Resources\UserDetailsReportResource; |
9 | use Carbon\Carbon; |
10 | use MongoDB\BSON\UTCDateTime; |
11 | |
12 | class ReportingUserDetailsRequest |
13 | { |
14 | /** |
15 | * Execute the action to get user details. |
16 | * |
17 | * @param ReportingUserDetailsRequestDTO $filter |
18 | * @return array |
19 | */ |
20 | public function execute(ReportingUserDetailsRequestDTO $filter) |
21 | { |
22 | $start_date = $filter->fromDate; |
23 | $end_date = $filter->toDate; |
24 | |
25 | // Parse dates or set defaults |
26 | if ($start_date && $end_date) { |
27 | $start_date = Carbon::parse($start_date); |
28 | $end_date = Carbon::parse($end_date); |
29 | } else { |
30 | $start_date = Carbon::now()->subMonths(12)->startOfMonth(); |
31 | $end_date = Carbon::now()->endOfMonth(); |
32 | } |
33 | |
34 | $start_date = Carbon::now()->subMonths(12)->startOfMonth(); |
35 | $end_date = Carbon::now()->endOfMonth(); |
36 | |
37 | // Convert start_date and end_date to UTCDateTime once to reuse |
38 | $start = new UTCDateTime($start_date->getTimestamp() * 1000); |
39 | $end = new UTCDateTime($end_date->getTimestamp() * 1000); |
40 | |
41 | // Fetch users with trashed records included |
42 | $users = User::withTrashed() |
43 | ->select([ |
44 | "id", |
45 | "first_name", |
46 | "last_name", |
47 | "company_group_id", |
48 | "company_id", |
49 | "deleted_at", |
50 | ]) |
51 | ->whereBetween("created_at", [$start, $end]) |
52 | ->get(); |
53 | |
54 | $ids = $users->pluck("id")->toArray(); |
55 | |
56 | // Fetch properties within the date range using the previously fetched IDs |
57 | $properties = HubspotProperties::whereIn("flymsg_id", $ids) |
58 | ->whereBetween("created_at", [$start, $end]) |
59 | ->get(); |
60 | |
61 | // Convert to resource collection |
62 | return UserDetailsReportResource::collection($properties); |
63 | } |
64 | } |