mirror of
https://github.com/snipe/snipe-it.git
synced 2026-02-05 08:25:42 +00:00
stuff
This commit is contained in:
@ -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 :)'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user