Added #6617: View licenses checked out to an asset with the hardware API (#6621)

This commit is contained in:
bricelabelle 2019-01-22 16:47:40 -06:00 committed by snipe
parent 7982b3f237
commit 5281713fd9
2 changed files with 16 additions and 2 deletions

View file

@ -5,10 +5,12 @@ use App\Helpers\Helper;
use App\Http\Controllers\Controller;
use App\Http\Requests\AssetCheckoutRequest;
use App\Http\Transformers\AssetsTransformer;
use App\Http\Transformers\LicensesTransformer;
use App\Models\Asset;
use App\Models\AssetModel;
use App\Models\Company;
use App\Models\CustomField;
use App\Models\License;
use App\Models\Location;
use App\Models\Setting;
use App\Models\User;
@ -332,7 +334,14 @@ class AssetsController extends Controller
}
public function licenses($id)
{
$this->authorize('view', Asset::class);
$this->authorize('view', License::class);
$asset = Asset::where('id', $id)->withTrashed()->first();
$licenses = $asset->licenses()->get();
return (new LicensesTransformer())->transformLicenses($licenses, $licenses->count());
}
/**
* Gets a paginated collection for the select2 menus

View file

@ -304,7 +304,12 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () {
/*--- Hardware API ---*/
Route::group(['prefix' => 'hardware'], function () {
Route::get('{asset_id}/licenses', [
'as' => 'api.assets.licenselist',
'uses' => 'AssetsController@licenses'
]);
Route::get( 'bytag/{tag}', [
'as' => 'assets.show.bytag',
'uses' => 'AssetsController@showByTag'