Fix parent ticket assignment and display
This commit is contained in:
@@ -4,9 +4,12 @@ namespace App\Http\Requests;
|
||||
|
||||
use App\Actions\Tickets\Support\AcceptanceCriteriaChecklistMapper;
|
||||
use App\Models\Project;
|
||||
use App\Models\Ticket;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
class StoreProjectTicketRequest extends FormRequest
|
||||
{
|
||||
@@ -55,6 +58,11 @@ class StoreProjectTicketRequest extends FormRequest
|
||||
'acceptance_criteria.*.indent' => ['required', 'integer', 'min:0', 'max:'.AcceptanceCriteriaChecklistMapper::MAX_INDENT_LEVEL],
|
||||
'assignee_user_id' => ['nullable', 'integer', Rule::exists('users', 'id')],
|
||||
'description' => ['nullable', 'string'],
|
||||
'parent_ticket_id' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
Rule::exists('tickets', 'id')->where('project_id', $project->id),
|
||||
],
|
||||
'ticket_priority_id' => [
|
||||
'required',
|
||||
'integer',
|
||||
@@ -74,4 +82,35 @@ class StoreProjectTicketRequest extends FormRequest
|
||||
'title' => ['required', 'string', 'max:255'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, callable(Validator): void>
|
||||
*/
|
||||
public function after(): array
|
||||
{
|
||||
return [
|
||||
function (Validator $validator): void {
|
||||
/** @var array<string, mixed> $validated */
|
||||
$validated = $this->safe()->all();
|
||||
|
||||
/** @var Project $project */
|
||||
$project = $this->route('project');
|
||||
|
||||
$parentTicketId = Arr::get($validated, 'parent_ticket_id');
|
||||
|
||||
if ($parentTicketId === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$parentTicket = Ticket::query()
|
||||
->where('project_id', $project->id)
|
||||
->with('ticketType')
|
||||
->find($parentTicketId);
|
||||
|
||||
if ($parentTicket !== null && ! $parentTicket->ticketType?->is_parent) {
|
||||
$validator->errors()->add('parent_ticket_id', 'Only tickets with a parent-enabled type can be selected as a parent.');
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,12 @@ class TicketResource extends JsonResource
|
||||
fn (): array => TicketFieldValueResource::collection($this->fieldValues)->resolve(),
|
||||
),
|
||||
'is_blocked' => $this->is_blocked,
|
||||
'parent_ticket' => $this->whenLoaded(
|
||||
'parentTicket',
|
||||
fn (): ?array => $this->parentTicket === null
|
||||
? null
|
||||
: TicketReferenceResource::make($this->parentTicket)->resolve(),
|
||||
),
|
||||
'parent_ticket_id' => $this->parent_ticket_id,
|
||||
'project_id' => $this->project_id,
|
||||
'sequence_number' => $this->sequence_number,
|
||||
|
||||
Reference in New Issue
Block a user