Fix package limits in tenant overview
This commit is contained in:
@@ -29,23 +29,34 @@ class TenantPackageController extends Controller
|
||||
->orderBy('created_at', 'desc')
|
||||
->get();
|
||||
|
||||
$packages->each(function ($package) {
|
||||
$pkg = $package->package;
|
||||
$package->remaining_events = $pkg->max_events_per_year - $package->used_events;
|
||||
$package->package_limits = array_merge(
|
||||
$pkg->limits,
|
||||
[
|
||||
'branding_allowed' => $pkg->branding_allowed,
|
||||
'watermark_allowed' => $pkg->watermark_allowed,
|
||||
'features' => $pkg->features,
|
||||
]
|
||||
);
|
||||
});
|
||||
$packages->each(fn (TenantPackage $package) => $this->hydratePackageSnapshot($package));
|
||||
|
||||
$activePackage = $tenant->activeResellerPackage?->load('package');
|
||||
|
||||
if ($activePackage instanceof TenantPackage) {
|
||||
$this->hydratePackageSnapshot($activePackage);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'data' => $packages,
|
||||
'active_package' => $tenant->activeResellerPackage ? $tenant->activeResellerPackage->load('package') : null,
|
||||
'active_package' => $activePackage,
|
||||
'message' => 'Tenant packages loaded successfully.',
|
||||
]);
|
||||
}
|
||||
|
||||
private function hydratePackageSnapshot(TenantPackage $package): void
|
||||
{
|
||||
$pkg = $package->package;
|
||||
|
||||
$maxEvents = $pkg?->max_events_per_year;
|
||||
$package->remaining_events = $maxEvents === null ? null : max($maxEvents - $package->used_events, 0);
|
||||
$package->package_limits = array_merge(
|
||||
$pkg?->limits ?? [],
|
||||
[
|
||||
'branding_allowed' => $pkg?->branding_allowed,
|
||||
'watermark_allowed' => $pkg?->watermark_allowed,
|
||||
'features' => $pkg?->features ?? [],
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user