Mass changes

This commit is contained in:
Simon Pocrnjič
2025-10-04 23:36:18 +02:00
parent ab50336e97
commit fe91c7e4bc
46 changed files with 5738 additions and 1873 deletions
@@ -18,6 +18,7 @@ public function rules(): array
'segment_id' => ['required', 'integer', 'exists:segments,id'],
'initial_decision_id' => ['required', 'integer', 'exists:decisions,id'],
'assign_decision_id' => ['required', 'integer', 'exists:decisions,id'],
'action_id' => ['nullable', 'integer', 'exists:actions,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'],
@@ -42,14 +43,26 @@ public function withValidator($validator): void
{
$validator->after(function ($validator): void {
// Validate that the assign_decision_id has a mapped action
$actionId = $this->input('action_id');
if (! empty($actionId)) {
$mapped = \App\Models\Action::query()
->where('id', $actionId)
->exists();
if (! $mapped) {
$validator->errors()->add('action_id', 'The selected action does not exist. Please select a valid action.');
}
}
$assignDecisionId = $this->input('assign_decision_id');
if (! empty($assignDecisionId)) {
$mapped = DB::table('action_decision')
->where('decision_id', $assignDecisionId)
->where('action_id', $actionId)
->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.');
$validator->errors()->add('assign_decision_id', 'The selected assign decision must have a mapped action. Please map the correct action to this decision first.');
}
}
@@ -58,10 +71,11 @@ public function withValidator($validator): void
if (! empty($completeDecisionId)) {
$mapped = DB::table('action_decision')
->where('decision_id', $completeDecisionId)
->where('action_id', $actionId)
->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.');
$validator->errors()->add('complete_decision_id', 'The selected complete decision must have a mapped action. Please map the correct action to this decision first.');
}
}
@@ -69,6 +83,7 @@ public function withValidator($validator): void
if (! empty($cancelDecisionId)) {
$mapped = DB::table('action_decision')
->where('decision_id', $cancelDecisionId)
->where('action_id', $actionId)
->exists();
if (! $mapped) {
@@ -22,6 +22,7 @@ public function rules(): array
'cancel_decision_id' => ['nullable', 'integer', 'exists:decisions,id'],
'return_segment_id' => ['nullable', 'integer', 'exists:segments,id'],
'queue_segment_id' => ['nullable', 'integer', 'exists:segments,id'],
'action_id' => ['nullable', 'integer', 'exists:actions,id'],
];
}
@@ -38,13 +39,25 @@ public function messages(): array
public function withValidator($validator): void
{
$validator->after(function ($validator): void {
$actionId = $this->input('action_id');
if (! empty($actionId)) {
$mapped = \App\Models\Action::query()
->where('id', $actionId)
->exists();
if (! $mapped) {
$validator->errors()->add('action_id', 'The selected action does not exist. Please select a valid action.');
}
}
$assignDecisionId = $this->input('assign_decision_id');
if (! empty($assignDecisionId)) {
$mapped = DB::table('action_decision')
->where('decision_id', $assignDecisionId)
->where('action_id', $actionId)
->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.');
$validator->errors()->add('assign_decision_id', 'The selected assign decision must have a mapped action. Please map the correct action to this decision first.');
}
}
@@ -52,9 +65,10 @@ public function withValidator($validator): void
if (! empty($completeDecisionId)) {
$mapped = DB::table('action_decision')
->where('decision_id', $completeDecisionId)
->where('action_id', $actionId)
->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.');
$validator->errors()->add('complete_decision_id', 'The selected complete decision must have a mapped action. Please map the correct action to this decision first.');
}
}
@@ -62,9 +76,10 @@ public function withValidator($validator): void
if (! empty($cancelDecisionId)) {
$mapped = DB::table('action_decision')
->where('decision_id', $cancelDecisionId)
->where('action_id', $actionId)
->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.');
$validator->errors()->add('cancel_decision_id', 'The selected cancel decision must have a mapped action. Please map the correct action to this decision first.');
}
}
});