mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-10-10 14:53:17 +01:00
fix scramble diagnostics in goal resource and requests
This commit is contained in:
@@ -19,6 +19,7 @@ use Illuminate\Contracts\Validation\Rule as LegacyValidationRule;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\Rules\ProhibitedIf;
|
||||
use Korridor\LaravelModelValidationRules\Rules\ExistsEloquent;
|
||||
|
||||
/**
|
||||
@@ -29,10 +30,10 @@ use Korridor\LaravelModelValidationRules\Rules\ExistsEloquent;
|
||||
trait GoalFilterRules
|
||||
{
|
||||
/**
|
||||
* @param bool $forEveryMember Whether the goal counts every member instead of one member
|
||||
* @return array<string, array<string|ValidationRule|LegacyValidationRule|\Closure>>
|
||||
* @param \Closure(): bool $forEveryMember Whether the goal counts every member instead of one member, evaluated during validation
|
||||
* @return array<string, array<string|ValidationRule|LegacyValidationRule|\Closure|ProhibitedIf>>
|
||||
*/
|
||||
protected function filterRules(bool $forEveryMember): array
|
||||
protected function filterRules(\Closure $forEveryMember): array
|
||||
{
|
||||
return [
|
||||
'filters' => [
|
||||
@@ -44,7 +45,7 @@ trait GoalFilterRules
|
||||
'nullable',
|
||||
'array',
|
||||
// "prohibited" still lets null and an empty array through, both mean "no restriction"
|
||||
...($forEveryMember ? [] : ['prohibited']),
|
||||
Rule::prohibitedIf(fn (): bool => ! $forEveryMember()),
|
||||
],
|
||||
'filters.member_ids.*' => [
|
||||
'string',
|
||||
|
||||
@@ -17,6 +17,7 @@ use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\Rules\In;
|
||||
use Illuminate\Validation\Rules\ProhibitedIf;
|
||||
use Korridor\LaravelModelValidationRules\Rules\ExistsEloquent;
|
||||
|
||||
/**
|
||||
@@ -29,7 +30,7 @@ class GoalStoreRequest extends BaseFormRequest
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, array<string|ValidationRule|LegacyValidationRule|In|\Closure>>
|
||||
* @return array<string, array<string|ValidationRule|LegacyValidationRule|In|ProhibitedIf|\Closure>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
@@ -97,7 +98,7 @@ class GoalStoreRequest extends BaseFormRequest
|
||||
],
|
||||
], $this->filterRules(
|
||||
// Without a member_id the goal is for the current member
|
||||
$this->has('member_id') && $this->input('member_id') === null,
|
||||
fn (): bool => $this->has('member_id') && $this->input('member_id') === null,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ use App\Models\Organization;
|
||||
use Illuminate\Contracts\Validation\Rule as LegacyValidationRule;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\Rules\ProhibitedIf;
|
||||
|
||||
/**
|
||||
* @property Organization $organization Organization from model binding
|
||||
@@ -25,7 +26,7 @@ class GoalUpdateRequest extends BaseFormRequest
|
||||
* Get the validation rules that apply to the request.
|
||||
* The type of a goal and the member it is for can not be changed after creation.
|
||||
*
|
||||
* @return array<string, array<string|ValidationRule|LegacyValidationRule|\Closure>>
|
||||
* @return array<string, array<string|ValidationRule|LegacyValidationRule|ProhibitedIf|\Closure>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
@@ -89,7 +90,7 @@ class GoalUpdateRequest extends BaseFormRequest
|
||||
}
|
||||
},
|
||||
],
|
||||
], $this->filterRules($goal->member_id === null));
|
||||
], $this->filterRules(fn (): bool => $goal->member_id === null));
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
|
||||
Reference in New Issue
Block a user