Do not include deleted assets by default when doing lookup by serial

This commit introduces a new query parameter `deleted`, which can be set to `true` to include deleted assets in the response.
This commit is contained in:
FliegenKLATSCH 2021-09-28 13:53:59 +02:00 committed by FliegenKLATSCH
parent 5d94b99035
commit 24c484303e

View file

@ -370,15 +370,21 @@ class AssetsController extends Controller
public function showBySerial(Request $request, $serial) public function showBySerial(Request $request, $serial)
{ {
$this->authorize('index', Asset::class); $this->authorize('index', Asset::class);
if ($assets = Asset::with('assetstatus')->with('assignedTo')
->withTrashed()->where('serial',$serial)->get()) { $assets = Asset::with('assetstatus')->with('assignedTo');
return (new AssetsTransformer)->transformAssets($assets, $assets->count());
if ($request->input('deleted', 'false') === 'true') {
$assets = $assets->withTrashed();
} }
return response()->json(Helper::formatStandardApiResponse('error', null, 'Asset not found'), 200);
$assets = $assets->where('serial', $serial)->get();
if ($assets) {
return (new AssetsTransformer)->transformAssets($assets, $assets->count());
} else {
return response()->json(Helper::formatStandardApiResponse('error', null, 'Asset not found'), 200);
}
} }
/** /**
* Returns JSON with information about an asset for detail view. * Returns JSON with information about an asset for detail view.
* *