feat: consolidar desenvolvimentos do portal InvestMoz
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Opportunity;
|
||||
use App\Models\User;
|
||||
|
||||
/** Observe technical failures without changing the approved transition engine. */
|
||||
final class OpportunityWorkflowExecution
|
||||
{
|
||||
public function __construct(private OpportunityProfileWorkflow $workflow, private OpportunityTechnicalExecution $execution) {}
|
||||
|
||||
/** @param array<string,mixed> $input */
|
||||
public function transition(User $actor, int $id, array $input): Opportunity
|
||||
{
|
||||
$action = $input['action'] ?? null;
|
||||
if (! in_array($action, ['submit', 'publish'], true)) {
|
||||
return $this->workflow->transition($actor, $id, $input);
|
||||
}
|
||||
$record = Opportunity::withTrashed()->findOrFail($id);
|
||||
app(PortalProfileAccess::class)->authorize($actor, 'view', $record);
|
||||
if (! in_array($action, $this->workflow->actions($actor, $record), true)) {
|
||||
return $this->workflow->transition($actor, $id, $input);
|
||||
}
|
||||
|
||||
return $this->execution->run($actor, $record, $action, $input, fn () => $this->workflow->transition($actor, $id, $input));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user