Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
GetAutomationDashboardQuery
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 execute
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace ImovelZapAi\Automation\Application\Queries;
6
7use ImovelZapAi\Automation\Domain\Enums\ExecutionStatus;
8use ImovelZapAi\Automation\Domain\Enums\WorkflowStatus;
9use ImovelZapAi\Automation\Infrastructure\Persistence\Eloquent\AutomationExecutionModel;
10use ImovelZapAi\Automation\Infrastructure\Persistence\Eloquent\AutomationWorkflowModel;
11
12final class GetAutomationDashboardQuery
13{
14    /** @return array<string, int|float> */
15    public function execute(string $tenantId): array
16    {
17        $workflows = AutomationWorkflowModel::query()->where('tenant_id', $tenantId);
18        $executions = AutomationExecutionModel::query()->where('tenant_id', $tenantId);
19
20        return [
21            'workflows_total' => (int) (clone $workflows)->count(),
22            'workflows_active' => (int) (clone $workflows)->where('status', WorkflowStatus::Active)->count(),
23            'workflows_paused' => (int) (clone $workflows)->where('status', WorkflowStatus::Paused)->count(),
24            'executions_total' => (int) (clone $executions)->count(),
25            'executions_succeeded' => (int) (clone $executions)->where('status', ExecutionStatus::Succeeded)->count(),
26            'executions_failed' => (int) (clone $executions)->where('status', ExecutionStatus::Failed)->count(),
27            'executions_skipped' => (int) (clone $executions)->where('status', ExecutionStatus::Skipped)->count(),
28            'executions_last_24h' => (int) (clone $executions)->where('created_at', '>=', now()->subDay())->count(),
29        ];
30    }
31}