feat(website-extras): implement toggle functionality for website extras and update related tests
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user