71 lines
2.3 KiB
PHP
71 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Actions\Tickets\Support\AcceptanceCriteriaChecklist;
|
|
use App\Models\Project;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class StoreProjectTicketRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return $this->user() !== null;
|
|
}
|
|
|
|
/**
|
|
* Prepare the data for validation.
|
|
*/
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$this->merge([
|
|
'acceptance_criteria' => AcceptanceCriteriaChecklist::normalize(
|
|
$this->input('acceptance_criteria'),
|
|
),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
/** @var Project $project */
|
|
$project = $this->route('project');
|
|
|
|
return [
|
|
'acceptance_criteria' => ['nullable', 'array'],
|
|
'acceptance_criteria.*' => ['array'],
|
|
'acceptance_criteria.*.text' => ['required', 'string'],
|
|
'acceptance_criteria.*.checked' => ['required', 'boolean'],
|
|
'acceptance_criteria.*.indent' => ['required', 'integer', 'min:0', 'max:'.AcceptanceCriteriaChecklist::MAX_INDENT_LEVEL],
|
|
'assignee_user_id' => ['nullable', 'integer', Rule::exists('users', 'id')],
|
|
'description' => ['nullable', 'string'],
|
|
'ticket_priority_id' => [
|
|
'required',
|
|
'integer',
|
|
Rule::exists('ticket_priorities', 'id')->where('project_id', $project->id),
|
|
],
|
|
'ticket_status_id' => [
|
|
'required',
|
|
'integer',
|
|
Rule::exists('ticket_statuses', 'id')->where('project_id', $project->id),
|
|
],
|
|
'ticket_type_id' => [
|
|
'required',
|
|
'integer',
|
|
Rule::exists('ticket_types', 'id')->where('project_id', $project->id),
|
|
],
|
|
'story_points' => ['nullable', 'integer', 'min:0'],
|
|
'title' => ['required', 'string', 'max:255'],
|
|
];
|
|
}
|
|
}
|