Skip to content

A free open source IT asset/license management system

Standardized transformer

snipe56957e28f9d8
diff --git a/app/Http/Transformers/AssetsTransformer.php b/app/Http/Transformers/AssetsTransformer.php
index 4ab40b6af0..4895eff6d5 100644
--- a/app/Http/Transformers/AssetsTransformer.php
+++ b/app/Http/Transformers/AssetsTransformer.php
@@ -6,6 +6,7 @@ use App\Helpers\Helper;
use App\Models\Accessory;
use App\Models\AccessoryCheckout;
use App\Models\Asset;
+use App\Models\Component;
use App\Models\License;
use App\Models\LicenseSeat;
use App\Models\Setting;
@@ -398,16 +399,22 @@ class AssetsTransformer
public function transformCheckedoutComponents(Collection $components_assets, $total)
{
$array = [];
- foreach ($components_assets as $component) {
+ foreach ($components_assets as $component_checkout) {
$array[] = [
- 'assigned_pivot_id' => $component->pivot->id,
- 'id' => (int) $component->id,
- 'name' => e($component->display_name),
- 'qty' => $component->pivot->assigned_qty,
- 'note' => ($component->pivot->note) ? e($component->pivot->note) : null,
- 'type' => 'asset',
- 'created_at' => Helper::getFormattedDateObject($component->pivot->created_at, 'datetime'),
- 'available_actions' => ['checkin' => true],
+ 'assigned_pivot_id' => $component_checkout->id,
+ 'name' => [
+ 'id' => $component_checkout->component->id,
+ 'name' => e($component_checkout->component->display_name),
+ 'type' => 'component',
+ ],
+ 'assigned_qty' => $component_checkout->assigned_qty,
+ 'note' => ($component_checkout->note) ? e($component_checkout->note) : null,
+ 'created_at' => Helper::getFormattedDateObject($component_checkout->created_at, 'datetime'),
+ 'created_by' => $component_checkout->adminuser ? [
+ 'id' => (int) $component_checkout->adminuser->id,
+ 'name' => e($component_checkout->adminuser->display_name),
+ ] : null,
+ 'available_actions' => ['checkin' => Gate::allows('checkin', Component::class)],
];
}
diff --git a/app/Http/Transformers/ComponentsTransformer.php b/app/Http/Transformers/ComponentsTransformer.php
index 4fc963b4ba..7a281d796b 100644
--- a/app/Http/Transformers/ComponentsTransformer.php
+++ b/app/Http/Transformers/ComponentsTransformer.php
@@ -88,9 +88,10 @@ class ComponentsTransformer
$array = [];
foreach ($components_assets as $asset) {
$array[] = [
- 'id' => (int) $asset->pivot->id,
- 'assigned_to' => $this->transformAssignedTo($asset),
- 'qty' => $asset->pivot->assigned_qty,
+ 'assigned_pivot_id' => (int) $asset->pivot->id,
+ 'name' => $this->transformAssignedTo($asset),
+ 'qty' => $asset->pivot->assigned_qty, // legacy?
+ 'assigned_qty' => $asset->pivot->assigned_qty,
'note' => ($asset->pivot->note) ? e($asset->pivot->note) : null,
'created_at' => Helper::getFormattedDateObject($asset->pivot->created_at, 'datetime'),
'available_actions' => ['checkin' => true],