From 6b081008192e5df4eecfa4ea7aca011492286660 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 11 Jul 2024 10:02:35 +0200 Subject: [PATCH] chore: Refactor checkIfDomainIsAlreadyUsed function --- bootstrap/helpers/shared.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index cf12d1195..8cee3e4c6 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -2168,7 +2168,7 @@ function ip_match($ip, $cidrs, &$match = null) return false; } -function checkIfDomainIsAlreadyUsed(Collection|array $domains, ?string $teamId, string $uuid) +function checkIfDomainIsAlreadyUsed(Collection|array $domains, ?string $teamId = null, ?string $uuid = null) { if (is_null($teamId)) { return response()->json(['error' => 'Team ID is required.'], 400); @@ -2184,8 +2184,12 @@ function checkIfDomainIsAlreadyUsed(Collection|array $domains, ?string $teamId, return str($domain); }); - $applications = Application::ownedByCurrentTeamAPI($teamId)->get(['fqdn', 'uuid'])->filter(fn ($app) => $app->uuid !== $uuid); - $serviceApplications = ServiceApplication::ownedByCurrentTeamAPI($teamId)->get(['fqdn', 'uuid'])->filter(fn ($app) => $app->uuid !== $uuid); + $applications = Application::ownedByCurrentTeamAPI($teamId)->get(['fqdn', 'uuid']); + $serviceApplications = ServiceApplication::ownedByCurrentTeamAPI($teamId)->get(['fqdn', 'uuid']); + if ($uuid) { + $applications = $applications->filter(fn ($app) => $app->uuid !== $uuid); + $serviceApplications = $serviceApplications->filter(fn ($app) => $app->uuid !== $uuid); + } $domainFound = false; foreach ($applications as $app) { if (is_null($app->fqdn)) {