fix unit tests as well as missing code
API CI/CD / Validate (composer + pint) (push) Successful in 2m7s
API CI/CD / Test (PHPUnit) (push) Failing after 2m23s
API CI/CD / Build frontend assets (push) Successful in 2m18s
API CI/CD / Security audit (push) Successful in 31s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
API CI/CD / Validate (composer + pint) (push) Successful in 2m7s
API CI/CD / Test (PHPUnit) (push) Failing after 2m23s
API CI/CD / Build frontend assets (push) Successful in 2m18s
API CI/CD / Security audit (push) Successful in 31s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
This commit is contained in:
@@ -24,7 +24,7 @@ class RoleCrudService
|
||||
|
||||
public function update(Role $role, array $payload): Role
|
||||
{
|
||||
$data = $this->normalizePayload($payload, $role->id, $role->slug ?? null);
|
||||
$data = $this->normalizePayload($payload, $role);
|
||||
|
||||
try {
|
||||
return DB::transaction(function () use ($role, $data) {
|
||||
@@ -51,14 +51,16 @@ class RoleCrudService
|
||||
}
|
||||
}
|
||||
|
||||
private function normalizePayload(array $payload, ?int $ignoreId = null, ?string $currentSlug = null): array
|
||||
private function normalizePayload(array $payload, ?Role $role = null): array
|
||||
{
|
||||
$rawName = trim((string) ($payload['name'] ?? ''));
|
||||
$rawSlug = trim((string) ($payload['slug'] ?? ''));
|
||||
$route = trim((string) ($payload['dashboard_route'] ?? ''));
|
||||
$desc = trim((string) ($payload['description'] ?? ''));
|
||||
$priority = (int) ($payload['priority'] ?? 0);
|
||||
$isActive = ! empty($payload['is_active']) ? 1 : 0;
|
||||
$rawName = trim((string) ($payload['name'] ?? $role?->name ?? ''));
|
||||
$rawSlug = trim((string) ($payload['slug'] ?? $role?->slug ?? ''));
|
||||
$route = trim((string) ($payload['dashboard_route'] ?? $role?->dashboard_route ?? ''));
|
||||
$desc = trim((string) ($payload['description'] ?? $role?->description ?? ''));
|
||||
$priority = (int) ($payload['priority'] ?? $role?->priority ?? 0);
|
||||
$isActive = array_key_exists('is_active', $payload)
|
||||
? (! empty($payload['is_active']) ? 1 : 0)
|
||||
: (int) ($role?->is_active ?? 0);
|
||||
|
||||
$name = strtolower($rawName);
|
||||
$dashboardRoute = strtolower($route);
|
||||
@@ -68,8 +70,8 @@ class RoleCrudService
|
||||
$slug = strtolower(preg_replace('/[^a-z0-9]+/i', '_', $slug));
|
||||
$slug = trim($slug, '_');
|
||||
|
||||
if ($slug !== $currentSlug) {
|
||||
$slug = $this->ensureUniqueSlug($slug, $ignoreId);
|
||||
if ($slug !== ($role?->slug ?? null)) {
|
||||
$slug = $this->ensureUniqueSlug($slug, $role?->id);
|
||||
}
|
||||
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user