Implement ticket details and worklog editing
This commit is contained in:
@@ -4,10 +4,15 @@ namespace App\Actions\Tickets;
|
||||
|
||||
use App\Models\Project;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CreateProjectTicket
|
||||
{
|
||||
public function __construct(
|
||||
private readonly CreateTicketWorklogEntry $createTicketWorklogEntry,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @param array{
|
||||
* acceptance_criteria: string|null,
|
||||
@@ -17,14 +22,14 @@ class CreateProjectTicket
|
||||
* title: string
|
||||
* } $attributes
|
||||
*/
|
||||
public function handle(Project $project, array $attributes): Ticket
|
||||
public function handle(Project $project, array $attributes, ?User $actor = null): Ticket
|
||||
{
|
||||
return DB::transaction(function () use ($attributes, $project): Ticket {
|
||||
return DB::transaction(function () use ($actor, $attributes, $project): Ticket {
|
||||
$nextSequenceNumber = (int) Ticket::query()
|
||||
->where('project_id', $project->id)
|
||||
->max('sequence_number') + 1;
|
||||
|
||||
return Ticket::query()->create([
|
||||
$ticket = Ticket::query()->create([
|
||||
'acceptance_criteria' => $attributes['acceptance_criteria'],
|
||||
'board_column_id' => null,
|
||||
'description' => $attributes['description'],
|
||||
@@ -35,6 +40,23 @@ class CreateProjectTicket
|
||||
'ticket_type_id' => $attributes['ticket_type_id'],
|
||||
'title' => $attributes['title'],
|
||||
]);
|
||||
|
||||
if ($actor !== null) {
|
||||
$this->createTicketWorklogEntry->handle(
|
||||
$ticket,
|
||||
$actor,
|
||||
'created',
|
||||
'Ticket was created in Backlog.',
|
||||
[
|
||||
'from' => null,
|
||||
'to' => [
|
||||
'label' => 'Backlog',
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
return $ticket;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user