mirror of
https://github.com/snipe/snipe-it.git
synced 2024-09-20 15:57:41 -07:00
Merge remote-tracking branch 'origin/develop'
This commit is contained in:
commit
dd55aedb87
|
@ -379,16 +379,26 @@ class AssetsController extends Controller
|
||||||
$assets = $assets->withTrashed();
|
$assets = $assets->withTrashed();
|
||||||
}
|
}
|
||||||
|
|
||||||
$assets = $assets->get();
|
if (($assets = $assets->get()) && ($assets->count()) > 0) {
|
||||||
|
|
||||||
if (($assets) && ($assets->count() > 0)) {
|
// If there is exactly one result and the deleted parameter is not passed, we should pull the first (and only)
|
||||||
return (new AssetsTransformer)->transformAssets($assets, $assets->count());
|
// asset from the returned collection, since transformAsset() expects an Asset object, NOT a collection
|
||||||
|
if (($assets->count() == 1) && ($request->input('deleted') != 'true')) {
|
||||||
|
return (new AssetsTransformer)->transformAsset($assets->first());
|
||||||
|
|
||||||
|
// If there is more than one result OR if the endpoint is requesting deleted items (even if there is only one
|
||||||
|
// match, return the normal collection transformed.
|
||||||
} else {
|
} else {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.does_not_exist')), 200);
|
return (new AssetsTransformer)->transformAssets($assets, $assets->count());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If there are 0 results, return the "no such asset" response
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.does_not_exist')), 200);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns JSON with information about an asset (by serial) for detail view.
|
* Returns JSON with information about an asset (by serial) for detail view.
|
||||||
*
|
*
|
||||||
|
@ -409,11 +419,24 @@ class AssetsController extends Controller
|
||||||
|
|
||||||
$assets = $assets->get();
|
$assets = $assets->get();
|
||||||
|
|
||||||
if (($assets) && ($assets->count() > 0)) {
|
if (($assets = $assets->get()) && ($assets->count()) > 0) {
|
||||||
return (new AssetsTransformer)->transformAssets($assets, $assets->count());
|
|
||||||
|
// If there is exactly one result and the deleted parameter is not passed, we should pull the first (and only)
|
||||||
|
// asset from the returned collection, since transformAsset() expects an Asset object, NOT a collection
|
||||||
|
if (($assets->count() == 1) && ($request->input('deleted') != 'true')) {
|
||||||
|
return (new AssetsTransformer)->transformAsset($assets->first());
|
||||||
|
|
||||||
|
// If there is more than one result OR if the endpoint is requesting deleted items (even if there is only one
|
||||||
|
// match, return the normal collection transformed.
|
||||||
} else {
|
} else {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.does_not_exist')), 200);
|
return (new AssetsTransformer)->transformAssets($assets, $assets->count());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there are 0 results, return the "no such asset" response
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.does_not_exist')), 200);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue