Refactor VM resource specs resolution and enhance order payment success email with addon summary; add UpdateVmConfigJob for CPU/RAM updates
This commit is contained in:
@@ -12,6 +12,25 @@ class ServiceClientDetailResource extends JsonResource
|
||||
*
|
||||
* @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
|
||||
{
|
||||
if (!$this->resource) {
|
||||
@@ -35,12 +54,7 @@ class ServiceClientDetailResource extends JsonResource
|
||||
'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,
|
||||
'specs' => $this->resolveSpecs($product),
|
||||
'order' => $order ? [
|
||||
'total' => (float) $order->total,
|
||||
'months' => (int) $orderItem->months,
|
||||
|
||||
Reference in New Issue
Block a user