Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ActivateWorkflowAction | |
0.00% |
0 / 12 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace ImovelZapAi\Automation\Application\Actions; |
| 6 | |
| 7 | use ImovelZapAi\Automation\Domain\Enums\WorkflowStatus; |
| 8 | use ImovelZapAi\Automation\Domain\Exceptions\AutomationException; |
| 9 | use ImovelZapAi\Automation\Infrastructure\Persistence\Eloquent\AutomationWorkflowModel; |
| 10 | use ImovelZapAi\Organizations\Application\Services\PlanLimitGuard; |
| 11 | use ImovelZapAi\Organizations\Domain\Exceptions\PlanLimitExceededException; |
| 12 | |
| 13 | final class ActivateWorkflowAction |
| 14 | { |
| 15 | public function __construct( |
| 16 | private readonly PlanLimitGuard $planLimitGuard, |
| 17 | ) {} |
| 18 | |
| 19 | public function execute(string $tenantId, string $workflowId): AutomationWorkflowModel |
| 20 | { |
| 21 | try { |
| 22 | $this->planLimitGuard->assertFeatureEnabled($tenantId, 'automations'); |
| 23 | } catch (PlanLimitExceededException $exception) { |
| 24 | throw AutomationException::invalidState($exception->getMessage()); |
| 25 | } |
| 26 | |
| 27 | $workflow = AutomationWorkflowModel::query() |
| 28 | ->where('tenant_id', $tenantId) |
| 29 | ->where('id', $workflowId) |
| 30 | ->first(); |
| 31 | |
| 32 | if ($workflow === null) { |
| 33 | throw AutomationException::notFound('Automação'); |
| 34 | } |
| 35 | |
| 36 | $workflow->forceFill(['status' => WorkflowStatus::Active])->save(); |
| 37 | |
| 38 | return $workflow->fresh(); |
| 39 | } |
| 40 | } |