81 lines
3.1 KiB
PHP
81 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class StoreFieldJobSettingRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'segment_id' => ['required', 'integer', 'exists:segments,id'],
|
|
'initial_decision_id' => ['required', 'integer', 'exists:decisions,id'],
|
|
'assign_decision_id' => ['required', 'integer', 'exists:decisions,id'],
|
|
'complete_decision_id' => ['required', 'integer', 'exists:decisions,id'],
|
|
'cancel_decision_id' => ['nullable', 'integer', 'exists:decisions,id'],
|
|
'return_segment_id' => ['nullable', 'integer', 'exists:segments,id'],
|
|
'queue_segment_id' => ['nullable', 'integer', 'exists:segments,id'],
|
|
];
|
|
}
|
|
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'segment_id.required' => 'Segment is required.',
|
|
'initial_decision_id.required' => 'Initial decision is required.',
|
|
'assign_decision_id.required' => 'Assign decision is required.',
|
|
'complete_decision_id.required' => 'Complete decision is required.',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Configure the validator instance.
|
|
*/
|
|
public function withValidator($validator): void
|
|
{
|
|
$validator->after(function ($validator): void {
|
|
// Validate that the assign_decision_id has a mapped action
|
|
$assignDecisionId = $this->input('assign_decision_id');
|
|
if (! empty($assignDecisionId)) {
|
|
$mapped = DB::table('action_decision')
|
|
->where('decision_id', $assignDecisionId)
|
|
->exists();
|
|
|
|
if (! $mapped) {
|
|
$validator->errors()->add('assign_decision_id', 'The selected assign decision must have a mapped action. Please map an action to this decision first.');
|
|
}
|
|
}
|
|
|
|
// Validate that the complete_decision_id has a mapped action
|
|
$completeDecisionId = $this->input('complete_decision_id');
|
|
if (! empty($completeDecisionId)) {
|
|
$mapped = DB::table('action_decision')
|
|
->where('decision_id', $completeDecisionId)
|
|
->exists();
|
|
|
|
if (! $mapped) {
|
|
$validator->errors()->add('complete_decision_id', 'The selected complete decision must have a mapped action. Please map an action to this decision first.');
|
|
}
|
|
}
|
|
|
|
$cancelDecisionId = $this->input('cancel_decision_id');
|
|
if (! empty($cancelDecisionId)) {
|
|
$mapped = DB::table('action_decision')
|
|
->where('decision_id', $cancelDecisionId)
|
|
->exists();
|
|
|
|
if (! $mapped) {
|
|
$validator->errors()->add('cancel_decision_id', 'The selected cancel decision must have a mapped action. Please map an action to this decision first.');
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|