diff --git a/app/Actions/CheckoutRequests/CreateCheckoutRequest.php b/app/Actions/CheckoutRequests/CreateCheckoutRequest.php index 5cfcecc785..e0caafa278 100644 --- a/app/Actions/CheckoutRequests/CreateCheckoutRequest.php +++ b/app/Actions/CheckoutRequests/CreateCheckoutRequest.php @@ -30,12 +30,10 @@ class CreateCheckoutRequest // Check if the asset exists and is requestable if (is_null($asset = Asset::RequestableAssets()->find($assetId))) { - $this->status = 'doesNotExist'; - return false; + return $this->status = 'doesNotExist'; } if (!Company::isCurrentUserHasAccess($asset)) { - $this->status = 'accessDenied'; - return false; + return $this->status = 'accessDenied'; } $data['item'] = $asset; @@ -65,8 +63,7 @@ class CreateCheckoutRequest } catch (\Exception $e) { \Log::warning($e); } - $this->status = 'cancelled'; - return true; + return $this->status = 'cancelled'; } $logaction->logaction('requested'); @@ -78,6 +75,8 @@ class CreateCheckoutRequest \Log::warning($e); } dump('handle end'); + + return $this->status = 'success'; } public function asController($assetId) @@ -87,25 +86,25 @@ class CreateCheckoutRequest //return $asset; } - public function jsonResponse(): JsonResponse - { - dump('json'); - return match ($this->status) { - 'doesNotExist' => response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.does_not_exist_or_not_requestable'))), - 'accessDenied' => response()->json(Helper::formatStandardApiResponse('error', null, trans('general.insufficient_permissions'))), - default => response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.request_successfully_created'))), - }; - } + //public function jsonResponse(): JsonResponse + //{ + // dump('json'); + // return match ($this->status) { + // 'doesNotExist' => response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.does_not_exist_or_not_requestable'))), + // 'accessDenied' => response()->json(Helper::formatStandardApiResponse('error', null, trans('general.insufficient_permissions'))), + // default => response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.request_successfully_created'))), + // }; + //} - public function htmlResponse(): RedirectResponse - { - dump('redirects'); - return match ($this->status) { - dump('redirects'), - 'doesNotExist' => redirect()->route('requestable-assets')->with('error', trans('admin/hardware/message.does_not_exist_or_not_requestable')), - 'accessDenied' => redirect()->route('requestable-assets')->with('error', trans('general.insufficient_permissions')), - 'cancelled' => redirect()->route('requestable-assets')->with('success')->with('success', trans('admin/hardware/message.requests.canceled')), - default => redirect()->route('requestable-assets')->with('success')->with('success', trans('admin/hardware/message.requests.success')), - }; - } + //public function htmlResponse(): RedirectResponse + //{ + // dump('redirects'); + // return match ($this->status) { + // dump('redirects'), + // 'doesNotExist' => redirect()->route('requestable-assets')->with('error', trans('admin/hardware/message.does_not_exist_or_not_requestable')), + // 'accessDenied' => redirect()->route('requestable-assets')->with('error', trans('general.insufficient_permissions')), + // 'cancelled' => redirect()->route('requestable-assets')->with('success')->with('success', trans('admin/hardware/message.requests.canceled')), + // default => redirect()->route('requestable-assets')->with('success')->with('success', trans('admin/hardware/message.requests.success')), + // }; + //} } diff --git a/app/Http/Controllers/Api/CheckoutRequest.php b/app/Http/Controllers/Api/CheckoutRequest.php new file mode 100644 index 0000000000..bbf7cd3587 --- /dev/null +++ b/app/Http/Controllers/Api/CheckoutRequest.php @@ -0,0 +1,23 @@ + response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.does_not_exist_or_not_requestable'))), + 'accessDenied' => response()->json(Helper::formatStandardApiResponse('error', null, trans('general.insufficient_permissions'))), + default => response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.request_successfully_created'))), + }; + } +} diff --git a/app/Http/Controllers/ViewAssetsController.php b/app/Http/Controllers/ViewAssetsController.php index d9c1f0facf..6772a57620 100755 --- a/app/Http/Controllers/ViewAssetsController.php +++ b/app/Http/Controllers/ViewAssetsController.php @@ -143,9 +143,17 @@ class ViewAssetsController extends Controller * Process a specific requested asset * @param null $assetId */ - public function getRequestAsset($assetId = null): void + public function getRequestAsset($assetId = null): RedirectResponse { - CreateCheckoutRequest::run($assetId); + $status = CreateCheckoutRequest::run($assetId); + + return match ($status) { + 'doesNotExist' => redirect()->route('requestable-assets')->with('error', trans('admin/hardware/message.does_not_exist_or_not_requestable')), + 'accessDenied' => redirect()->route('requestable-assets')->with('error', trans('general.insufficient_permissions')), + 'cancelled' => redirect()->route('requestable-assets')->with('success')->with('success', trans('admin/hardware/message.requests.canceled')), + 'success' => redirect()->route('requestable-assets')->with('success')->with('success', trans('admin/hardware/message.requests.success')), + default => redirect()->route('requestable-assets')->with('success')->with('success', trans('admin/hardware/message.requests.success')), + }; } public function getRequestedAssets() : View