Add application API and OpenAPI docs
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\ProjectBoard;
|
||||
|
||||
use App\Models\Project;
|
||||
use App\Models\TicketStatus;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class DeleteTicketStatus
|
||||
{
|
||||
use ManagesTicketStatusPositions;
|
||||
|
||||
/**
|
||||
* @return array{context_label: string, deleted_name: string}
|
||||
*/
|
||||
public function handle(Project $project, TicketStatus $ticketStatus): array
|
||||
{
|
||||
$ticketStatus->load('boardColumn');
|
||||
$boardColumnId = $ticketStatus->board_column_id;
|
||||
|
||||
if ($this->statusContextQuery($project, $boardColumnId)->count() <= 1) {
|
||||
throw ValidationException::withMessages([
|
||||
'ticket_status_id' => "{$this->statusContextLabel($ticketStatus)} needs at least one ticket status.",
|
||||
]);
|
||||
}
|
||||
|
||||
$deletedName = $ticketStatus->name;
|
||||
$contextLabel = $this->statusContextLabel($ticketStatus);
|
||||
|
||||
DB::transaction(function () use ($boardColumnId, $project, $ticketStatus): void {
|
||||
$replacementStatus = $this->statusContextQuery($project, $boardColumnId)
|
||||
->whereKeyNot($ticketStatus->id)
|
||||
->firstOrFail();
|
||||
|
||||
$ticketStatus->tickets()->update([
|
||||
'ticket_status_id' => $replacementStatus->id,
|
||||
]);
|
||||
|
||||
$ticketStatus->delete();
|
||||
|
||||
$this->normalizeStatusPositions($project, $boardColumnId);
|
||||
});
|
||||
|
||||
return [
|
||||
'context_label' => $contextLabel,
|
||||
'deleted_name' => $deletedName,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user