Skip to content

A free open source IT asset/license management system

Added asset checkoutByTag API endpoint

Nathan Butler67e9b7795a92
diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php
index d4e7a7a8b2..1f3a7a56d7 100644
--- a/app/Http/Controllers/Api/AssetsController.php
+++ b/app/Http/Controllers/Api/AssetsController.php
@@ -746,7 +746,21 @@ class AssetsController extends Controller
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.does_not_exist')), 200);
}
-
+ /**
+ * Checkout an asset by its tag.
+ *
+ * @author [N. Butler]
+ * @param string $tag
+ * @since [v6.0.5]
+ * @return JsonResponse
+ */
+ public function checkoutByTag(AssetCheckoutRequest $request, $tag)
+ {
+ if ($asset = Asset::with('assetstatus')->with('assignedTo')->where('asset_tag', $tag)->first()) {
+ return $this->checkout($request, $asset->id);
+ }
+ return response()->json(Helper::formatStandardApiResponse('error', null, 'Asset not found'), 200);
+ }
/**
* Checkout an asset
diff --git a/routes/api.php b/routes/api.php
index 29af435687..faabaa28e4 100644
--- a/routes/api.php
+++ b/routes/api.php
@@ -441,6 +441,13 @@ Route::group(['prefix' => 'v1', 'middleware' => ['api', 'throttle:api']], functi
)->name('api.assets.show.bytag')
->where('any', '.*');
+ Route::post('bytag/{any}/checkout',
+ [
+ Api\AssetsController::class,
+ 'checkoutByTag'
+ ]
+ )->name('api.assets.checkout.bytag');
+
Route::get('byserial/{any}',
[
Api\AssetsController::class,