- Implemented client access token verification middleware to secure API endpoints. - Updated ServiceController to fetch active hosting services for authenticated users. - Refactored OrderController to ensure order retrieval is customer-specific. - Improved error logging in VmController for unexpected vCenter responses. - Disabled VNPay auto-deposit in TransactionController, switching to manual deposit flow. - Enhanced ServiceClientDetailResource to include Plesk credentials for hosting accounts. - Adjusted VpsServiceResource to dynamically set page type based on product type. - Added logging for PowerShellService to capture errors in RDP port changes. - Provisioning job now resolves service plans and logs relevant information for hosting accounts. - Updated database migrations to add necessary fields for service plans and DNS servers. - Refactored Service and ServicePlan models to establish relationships with hosting accounts and DNS servers.
67 lines
2.4 KiB
PHP
67 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources\Api\Service;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class VpsServiceResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
private function resolveSpecs($product): ?array
|
|
{
|
|
$addons = $this->addons ?? collect();
|
|
if ($addons->isNotEmpty()) {
|
|
return [
|
|
'cpu' => (int) $addons->where('addon_type', 'cpu')->sum('addon_value'),
|
|
'ram' => (int) $addons->where('addon_type', 'ram')->sum('addon_value'),
|
|
'disk' => (int) $addons->where('addon_type', 'disk')->sum('addon_value'),
|
|
'bandwidth' => (int) $addons->where('addon_type', 'bandwidth')->sum('addon_value'),
|
|
];
|
|
}
|
|
return $product ? [
|
|
'cpu' => (int) ($product->cpu ?? 0),
|
|
'ram' => (int) ($product->ram ?? 0),
|
|
'disk' => (int) ($product->disk ?? 0),
|
|
'bandwidth' => (int) ($product->bandwidth ?? 0),
|
|
] : null;
|
|
}
|
|
|
|
public function toArray(Request $request): array
|
|
{
|
|
$orderItem = $this->orderItem;
|
|
$invoice = $this->invoice;
|
|
$order = $orderItem?->order ?? $invoice?->order;
|
|
$product = $orderItem?->product ?? $this->product;
|
|
|
|
return [
|
|
'uuid' => $this->uuid,
|
|
'server_name' => $this->server_name,
|
|
'invoice_num' => $invoice?->invoice_number,
|
|
'order_item_id' => $this->order_item_id,
|
|
'order_num' => $order?->order_num,
|
|
'status' => $this->status,
|
|
'status_label' => $this->status_label,
|
|
'auto_renew' => (bool) $this->auto_renew,
|
|
'started_at' => $this->started_at?->toISOString(),
|
|
'expires_at' => $this->expires_at?->toISOString(),
|
|
'os' => [
|
|
'version' => $orderItem?->os?->version,
|
|
'group' => $orderItem?->os?->osGroup?->name,
|
|
],
|
|
'product' => $product ? [
|
|
'uuid' => $product->uuid,
|
|
'name' => $product->name,
|
|
'slug' => $product->slug,
|
|
'product_type' => $product->product_type,
|
|
'page_type' => 'service_' . str_replace(' ', '_', $product->product_type),
|
|
] : null,
|
|
'specs' => $this->resolveSpecs($product),
|
|
];
|
|
}
|
|
}
|