feat(website-extras): implement toggle functionality for website extras and update related tests

This commit is contained in:
2026-07-31 09:47:56 -03:00
parent 45e56c43a6
commit 40cbac17c6
5 changed files with 68 additions and 0 deletions

View File

@@ -166,6 +166,24 @@ class WebsiteExtraService
});
}
public function toggleForTenant(Tenant $tenant, string $extraCode): WebsiteExtra
{
$definition = $this->definitionForTenant($tenant, $extraCode);
return DB::transaction(function () use ($tenant, $definition): WebsiteExtra {
$websiteExtra = $tenant->websiteExtras()
->where('website_type_extra_id', $definition->id)
->lockForUpdate()
->firstOrFail();
$websiteExtra->update([
'is_enabled' => ! $websiteExtra->is_enabled,
]);
return $websiteExtra;
});
}
public function definitionForTenant(Tenant $tenant, string $extraCode): WebsiteTypeExtra
{
return WebsiteTypeExtra::query()