From 0bfdfc9b4ec954131d37daa781663bf1259086ef Mon Sep 17 00:00:00 2001 From: b1ek Date: Fri, 30 Aug 2024 17:32:26 +1000 Subject: [PATCH] fix: do the validation via JsonMapper instead --- app/Facade/Filters/Filters.php | 26 +++++++------------ .../Requests/AuthorizedFilterListRequest.php | 12 --------- 2 files changed, 9 insertions(+), 29 deletions(-) delete mode 100644 app/Http/Requests/AuthorizedFilterListRequest.php diff --git a/app/Facade/Filters/Filters.php b/app/Facade/Filters/Filters.php index 4810dbb..af03239 100644 --- a/app/Facade/Filters/Filters.php +++ b/app/Facade/Filters/Filters.php @@ -1,29 +1,17 @@ [ 'required', 'string' ], - 'filters.*.type' => [ 'required', Rule::enum(FilterTypeEnum::class) ], - 'filters.*.filter' => [ 'required', 'nullable', 'string' ], - - 'orders.*.by' => [ 'required', 'string' ], - 'orders.*.sort' => [ 'required', Rule::enum(OrderTypeEnum::class) ], - - 'pagination.size' => 'number', - 'pagination.page' => 'number', - ]; - } - /** * @var Filter[] */ @@ -47,7 +35,11 @@ class Filters $data->orders ??= []; $data->pagination ??= null; - return $mapper->map($data, \App\Facade\Filters\Filters::class); + try { + return $mapper->map($data, \App\Facade\Filters\Filters::class); + } catch (Error $err) { + throw new HttpResponseException(response()->json([ 'unknown' => $err->getMessage() ], 422)); + } } public function apply(Builder $builder) diff --git a/app/Http/Requests/AuthorizedFilterListRequest.php b/app/Http/Requests/AuthorizedFilterListRequest.php deleted file mode 100644 index 6542749..0000000 --- a/app/Http/Requests/AuthorizedFilterListRequest.php +++ /dev/null @@ -1,12 +0,0 @@ -