41 lines
1.3 KiB
PHP
41 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Actions\Tickets;
|
|
|
|
use App\Models\Project;
|
|
use App\Models\Ticket;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class CreateProjectTicket
|
|
{
|
|
/**
|
|
* @param array{
|
|
* acceptance_criteria: string|null,
|
|
* description: string|null,
|
|
* ticket_priority_id: int,
|
|
* ticket_type_id: int,
|
|
* title: string
|
|
* } $attributes
|
|
*/
|
|
public function handle(Project $project, array $attributes): Ticket
|
|
{
|
|
return DB::transaction(function () use ($attributes, $project): Ticket {
|
|
$nextSequenceNumber = (int) Ticket::query()
|
|
->where('project_id', $project->id)
|
|
->max('sequence_number') + 1;
|
|
|
|
return Ticket::query()->create([
|
|
'acceptance_criteria' => $attributes['acceptance_criteria'],
|
|
'board_column_id' => null,
|
|
'description' => $attributes['description'],
|
|
'project_id' => $project->id,
|
|
'sequence_number' => $nextSequenceNumber,
|
|
'ticket_key' => "{$project->key}-{$nextSequenceNumber}",
|
|
'ticket_priority_id' => $attributes['ticket_priority_id'],
|
|
'ticket_type_id' => $attributes['ticket_type_id'],
|
|
'title' => $attributes['title'],
|
|
]);
|
|
});
|
|
}
|
|
}
|