Merge pull request #16540 from marcusmoore/bug/sc-28607

Early return null from location transformer for missing accessory
This commit is contained in:
snipe 2025-03-31 12:34:22 +01:00 committed by GitHub
commit 1d3069fe84
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -101,11 +101,8 @@ class LocationsTransformer
$array = [ $array = [
'id' => $accessory_checkout->id, 'id' => $accessory_checkout->id,
'assigned_to' => $accessory_checkout->assigned_to, 'assigned_to' => $accessory_checkout->assigned_to,
'accessory' => [ 'accessory' => $this->transformAccessory($accessory_checkout->accessory),
'id' => $accessory_checkout->accessory->id, 'image' => ($accessory_checkout?->accessory?->image) ? Storage::disk('public')->url('accessories/' . e($accessory_checkout->accessory->image)) : null,
'name' => $accessory_checkout->accessory->name,
],
'image' => ($accessory_checkout->accessory->image) ? Storage::disk('public')->url('accessories/'.e($accessory_checkout->accessory->image)) : null,
'note' => $accessory_checkout->note ? e($accessory_checkout->note) : null, 'note' => $accessory_checkout->note ? e($accessory_checkout->note) : null,
'created_by' => $accessory_checkout->adminuser ? [ 'created_by' => $accessory_checkout->adminuser ? [
'id' => (int) $accessory_checkout->adminuser->id, 'id' => (int) $accessory_checkout->adminuser->id,
@ -153,4 +150,16 @@ class LocationsTransformer
return $array; return $array;
} }
} }
private function transformAccessory(?Accessory $accessory): ?array
{
if ($accessory) {
return [
'id' => $accessory->id,
'name' => $accessory->name,
];
}
return null;
}
} }