From a524c0b418de29f2393aa49a9dc82f7de00ce2e7 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Wed, 16 Oct 2024 18:48:15 -0500 Subject: [PATCH] more work --- _ide_helper_actions.php | 44 ------------------- .../CreateCheckoutRequest.php | 41 +++++++++++++---- app/Http/Controllers/ViewAssetsController.php | 6 ++- 3 files changed, 37 insertions(+), 54 deletions(-) delete mode 100644 _ide_helper_actions.php diff --git a/_ide_helper_actions.php b/_ide_helper_actions.php deleted file mode 100644 index a420493954..0000000000 --- a/_ide_helper_actions.php +++ /dev/null @@ -1,44 +0,0 @@ -user(); // Check if the asset exists and is requestable if (is_null($asset = Asset::RequestableAssets()->find($assetId))) { - return redirect()->route('requestable-assets') - ->with('error', trans('admin/hardware/message.does_not_exist_or_not_requestable')); + $this->status = 'doesNotExist'; + return false; } if (!Company::isCurrentUserHasAccess($asset)) { - return redirect()->route('requestable-assets') - ->with('error', trans('general.insufficient_permissions')); + $this->status = 'accessDenied'; + return false; } $data['item'] = $asset; @@ -57,8 +61,8 @@ class CreateCheckoutRequest } catch (\Exception $e) { Log::warning($e); } - return redirect()->route('requestable-assets') - ->with('success')->with('success', trans('admin/hardware/message.requests.canceled')); + $this->status = 'cancelled'; + return true; } $logaction->logaction('requested'); @@ -67,9 +71,28 @@ class CreateCheckoutRequest try { $settings->notify(new RequestAssetNotification($data)); } catch (\Exception $e) { - Log::warning($e); + \Log::warning($e); } - return redirect()->route('requestable-assets')->with('success')->with('success', trans('admin/hardware/message.requests.success')); + return true; + } + + public function jsonResponse(): JsonResponse + { + 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 + { + return match ($this->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')), + default => redirect()->route('requestable-assets')->with('success')->with('success', trans('admin/hardware/message.requests.success')), + }; } } diff --git a/app/Http/Controllers/ViewAssetsController.php b/app/Http/Controllers/ViewAssetsController.php index d9c1f0facf..722974713f 100755 --- a/app/Http/Controllers/ViewAssetsController.php +++ b/app/Http/Controllers/ViewAssetsController.php @@ -145,7 +145,11 @@ class ViewAssetsController extends Controller */ public function getRequestAsset($assetId = null): void { - CreateCheckoutRequest::run($assetId); + $request = CreateCheckoutRequest::run($assetId); + + if (!$request) { + \Log::debug('problem'); + } } public function getRequestedAssets() : View