Added ability to include deleted items in tag search endpoint

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2022-11-15 17:18:09 +00:00
parent 2166fcec41
commit bcbe517446

View file

@ -371,13 +371,27 @@ class AssetsController extends Controller
*/ */
public function showByTag(Request $request, $tag) public function showByTag(Request $request, $tag)
{ {
if ($asset = Asset::with('assetstatus')->with('assignedTo')->where('asset_tag', $tag)->first()) { $this->authorize('index', Asset::class);
$this->authorize('view', $asset); if ($assets = Asset::with('assetstatus')->with('assignedTo')
->withTrashed()->where('asset_tag', $tag)->get()) {
return (new AssetsTransformer)->transformAsset($asset, $request); return (new AssetsTransformer)->transformAssets($assets, $assets->count());
} }
return response()->json(Helper::formatStandardApiResponse('error', null, 'Asset not found'), 200); return response()->json(Helper::formatStandardApiResponse('error', null, 'Asset not found'), 200);
$assets = Asset::with('assetstatus')->with('assignedTo');
if ($request->input('deleted', 'false') === 'true') {
$assets = $assets->withTrashed();
}
$assets = $assets->where('asset_tag', $tag)->get();
if ($assets) {
return (new AssetsTransformer)->transformAssets($assets, $assets->count());
} else {
return response()->json(Helper::formatStandardApiResponse('error', null, 'Asset not found'), 200);
}
} }
/** /**
@ -401,7 +415,7 @@ class AssetsController extends Controller
if ($request->input('deleted', 'false') === 'true') { if ($request->input('deleted', 'false') === 'true') {
$assets = $assets->withTrashed(); $assets = $assets->withTrashed();
} }
$assets = $assets->where('serial', $serial)->get(); $assets = $assets->where('serial', $serial)->get();
if ($assets) { if ($assets) {