3
0
mirror of https://github.com/snipe/snipe-it.git synced 2026-02-05 08:25:42 +00:00
This commit is contained in:
spencerrlongg
2024-10-22 15:09:35 -05:00
parent e40849c910
commit b59bf495e1
6 changed files with 39 additions and 19 deletions

View File

@ -3,14 +3,27 @@
namespace App\Http\Controllers\Api;
use App\Actions\CheckoutRequests\CreateCheckoutRequest;
use App\Exceptions\AssetNotRequestable;
use App\Helpers\Helper;
use App\Http\Controllers\Controller;
use App\Models\Asset;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Http\JsonResponse;
class CheckoutRequest extends Controller
{
public function store($assetId): JsonResponse
public function store(CheckoutRequestRequest $request, Asset $asset): JsonResponse
{
CreateCheckoutRequest::run($assetId);
try {
CreateCheckoutRequest::run($asset, $request->validated()['user_id']);
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/hardware/message.requests.success')));
} catch (AssetNotRequestable $e) {
return response()->json(Helper::formatStandardApiResponse('error', 'Asset is not requestable'));
} catch (AuthorizationException $e) {
return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.insufficient_permissions')));
} catch (\Exception $e) {
report($e);
return response()->json(Helper::formatStandardApiResponse('error', null, 'Something terrible has gone wrong and we\'re not sure if we can help - may god have mercy on your soul. Contact your admin :)'));
}
}
}