this works
This commit is contained in:
parent
b2ff34260a
commit
1fd945c2d8
3 changed files with 58 additions and 28 deletions
|
@ -30,12 +30,10 @@ class CreateCheckoutRequest
|
||||||
|
|
||||||
// Check if the asset exists and is requestable
|
// Check if the asset exists and is requestable
|
||||||
if (is_null($asset = Asset::RequestableAssets()->find($assetId))) {
|
if (is_null($asset = Asset::RequestableAssets()->find($assetId))) {
|
||||||
$this->status = 'doesNotExist';
|
return $this->status = 'doesNotExist';
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
if (!Company::isCurrentUserHasAccess($asset)) {
|
if (!Company::isCurrentUserHasAccess($asset)) {
|
||||||
$this->status = 'accessDenied';
|
return $this->status = 'accessDenied';
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$data['item'] = $asset;
|
$data['item'] = $asset;
|
||||||
|
@ -65,8 +63,7 @@ class CreateCheckoutRequest
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
\Log::warning($e);
|
\Log::warning($e);
|
||||||
}
|
}
|
||||||
$this->status = 'cancelled';
|
return $this->status = 'cancelled';
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$logaction->logaction('requested');
|
$logaction->logaction('requested');
|
||||||
|
@ -78,6 +75,8 @@ class CreateCheckoutRequest
|
||||||
\Log::warning($e);
|
\Log::warning($e);
|
||||||
}
|
}
|
||||||
dump('handle end');
|
dump('handle end');
|
||||||
|
|
||||||
|
return $this->status = 'success';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function asController($assetId)
|
public function asController($assetId)
|
||||||
|
@ -87,25 +86,25 @@ class CreateCheckoutRequest
|
||||||
//return $asset;
|
//return $asset;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function jsonResponse(): JsonResponse
|
//public function jsonResponse(): JsonResponse
|
||||||
{
|
//{
|
||||||
dump('json');
|
// dump('json');
|
||||||
return match ($this->status) {
|
// return match ($this->status) {
|
||||||
'doesNotExist' => response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.does_not_exist_or_not_requestable'))),
|
// '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'))),
|
// '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'))),
|
// default => response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.request_successfully_created'))),
|
||||||
};
|
// };
|
||||||
}
|
//}
|
||||||
|
|
||||||
public function htmlResponse(): RedirectResponse
|
//public function htmlResponse(): RedirectResponse
|
||||||
{
|
//{
|
||||||
dump('redirects');
|
// dump('redirects');
|
||||||
return match ($this->status) {
|
// return match ($this->status) {
|
||||||
dump('redirects'),
|
// dump('redirects'),
|
||||||
'doesNotExist' => redirect()->route('requestable-assets')->with('error', trans('admin/hardware/message.does_not_exist_or_not_requestable')),
|
// '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')),
|
// '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')),
|
// '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')),
|
// default => redirect()->route('requestable-assets')->with('success')->with('success', trans('admin/hardware/message.requests.success')),
|
||||||
};
|
// };
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
23
app/Http/Controllers/Api/CheckoutRequest.php
Normal file
23
app/Http/Controllers/Api/CheckoutRequest.php
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Actions\CheckoutRequests\CreateCheckoutRequest;
|
||||||
|
use App\Helpers\Helper;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class CheckoutRequest extends Controller
|
||||||
|
{
|
||||||
|
public function store($assetId): JsonResponse
|
||||||
|
{
|
||||||
|
$status = CreateCheckoutRequest::run($assetId);
|
||||||
|
|
||||||
|
return match ($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'))),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -143,9 +143,17 @@ class ViewAssetsController extends Controller
|
||||||
* Process a specific requested asset
|
* Process a specific requested asset
|
||||||
* @param null $assetId
|
* @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
|
public function getRequestedAssets() : View
|
||||||
|
|
Loading…
Add table
Reference in a new issue