first commit
This commit is contained in:
61
app/Http/Requests/UpsertMedicalReportFormTemplateRequest.php
Normal file
61
app/Http/Requests/UpsertMedicalReportFormTemplateRequest.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Support\MedicalReport\TemplateWorkbook;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UpsertMedicalReportFormTemplateRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
/** @var TemplateWorkbook $templateWorkbook */
|
||||
$templateWorkbook = app(TemplateWorkbook::class);
|
||||
$departmentKeys = array_map(
|
||||
fn (array $department): string => $department['key'],
|
||||
$templateWorkbook->departments(),
|
||||
);
|
||||
|
||||
return [
|
||||
'department' => ['required', 'string', Rule::in($departmentKeys)],
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'description' => ['nullable', 'string', 'max:2000'],
|
||||
'schema' => ['required', 'array:title,description,sections'],
|
||||
'schema.title' => ['required', 'string', 'max:255'],
|
||||
'schema.description' => ['nullable', 'string', 'max:2000'],
|
||||
'schema.sections' => ['required', 'array', 'min:1'],
|
||||
'schema.sections.*.key' => ['required', 'string', 'max:100'],
|
||||
'schema.sections.*.title' => ['required', 'string', 'max:255'],
|
||||
'schema.sections.*.economist_label' => ['nullable', 'string', 'max:255'],
|
||||
'schema.sections.*.fields' => ['required', 'array', 'min:1'],
|
||||
'schema.sections.*.fields.*.key' => ['required', 'string', 'max:100'],
|
||||
'schema.sections.*.fields.*.label' => ['required', 'string', 'max:255'],
|
||||
'schema.sections.*.fields.*.type' => ['required', 'string', Rule::in(['text', 'number', 'department-select'])],
|
||||
'schema.sections.*.export_metrics' => ['nullable', 'array', 'min:1'],
|
||||
'schema.sections.*.export_metrics.*.key' => ['required', 'string', 'max:100'],
|
||||
'schema.sections.*.export_metrics.*.label' => ['required', 'string', 'max:255'],
|
||||
'schema.sections.*.export_metrics.*.source_field' => ['required', 'string', 'max:100'],
|
||||
'schema.sections.*.export_metrics.*.aggregation' => ['required', 'string', Rule::in(['sum'])],
|
||||
'schema.sections.*.export_metrics.*.analysis_column' => ['nullable', 'string', 'max:100'],
|
||||
'schema.sections.*.export_metrics.*.row_mode' => ['nullable', 'string', Rule::in(['entry_department', 'fixed_unit'])],
|
||||
'schema.sections.*.export_metrics.*.target_unit_slug' => ['nullable', 'string', 'max:255'],
|
||||
'schema.sections.*.default_entries' => ['nullable', 'array'],
|
||||
'schema.sections.*.default_entries.*' => ['array'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user