feat: Add product specifications, order details, and VM information to the service client detail resource and eager load related data.

This commit is contained in:
pbao9
2026-03-13 17:03:10 +07:00
parent 0e5832b1fb
commit 44f4f64b37
2 changed files with 38 additions and 8 deletions
@@ -18,17 +18,43 @@ class ServiceClientDetailResource extends JsonResource
return [];
}
$orderItem = $this->orderItem;
$order = $orderItem?->order;
$vm = $order?->vmWare?->first();
$product = $orderItem?->product;
return [
'uuid' => $this->uuid,
'uuid' => $this->uuid,
'server_name' => $this->server_name,
'status' => $this->status,
'auto_renew' => $this->auto_renew,
'started_at' => $this->started_at?->toISOString(),
'expires_at' => $this->expires_at?->toISOString(),
'status' => $this->status,
'auto_renew' => $this->auto_renew,
'started_at' => $this->started_at?->toISOString(),
'expires_at' => $this->expires_at?->toISOString(),
'os' => [
'version' => $this->orderItem?->os?->version,
'group' => $this->orderItem?->os?->os_group?->name,
'version' => $orderItem?->os?->version,
'group' => $orderItem?->os?->osGroup?->name,
],
'specs' => $product ? [
'cpu' => (int) ($product->cpu ?? 0),
'ram' => (int) ($product->ram ?? 0),
'disk' => (int) ($product->disk ?? 0),
'bandwidth' => (int) ($product->bandwidth ?? 0),
] : null,
'order' => $order ? [
'total' => (float) $order->total,
'months' => (int) $orderItem->months,
'billing_label' => $orderItem->billing_label,
] : null,
'vm' => $vm ? [
'id' => $vm->id,
'vmware_id' => $vm->vmware_id,
'ip_address' => $vm->ipAddress?->ip,
'hostname' => $vm->hostname,
'username' => $vm->user,
'password' => $vm->getRawOriginal('password'),
'port' => $vm->port,
'status' => $vm->status,
] : null,
];
}
}
@@ -47,7 +47,11 @@ class ServiceClientRepository extends BaseApiRepository implements ServiceClient
public function getDetailService(string $uuid)
{
return $this->model
->with(['orderItem.os.osGroup.host.datacenter.vCenter'])
->with([
'orderItem.os.osGroup',
'orderItem.product',
'orderItem.order.vmWare.ipAddress',
])
->where('uuid', $uuid)
->first();
}