fix(domain-manager): prioritize non-seed workspaces in selection

Updated workspace selection logic to prioritize non-seed workspaces. Returns a seed workspace only if no non-seed workspaces are available to improve filtering consistency and avoid unintended behavior.
This commit is contained in:
Antoine Moreaux 2024-12-19 15:16:41 +01:00
parent 53576245aa
commit 6e87a86d67

View File

@ -12,6 +12,10 @@ import {
import { getDomainNameByEmail } from 'src/utils/get-domain-name-by-email';
import { isDefined } from 'src/utils/is-defined';
import { isWorkEmail } from 'src/utils/is-work-email';
import {
SEED_ACME_WORKSPACE_ID,
SEED_APPLE_WORKSPACE_ID,
} from 'src/database/typeorm-seeds/core/workspaces';
@Injectable()
export class DomainManagerService {
@ -153,7 +157,14 @@ export class DomainManagerService {
);
}
return workspaces[0];
const nonSeedWorkspace = workspaces.find(
(workspace) =>
![SEED_APPLE_WORKSPACE_ID, SEED_ACME_WORKSPACE_ID].includes(
workspace.id,
),
);
return nonSeedWorkspace ?? workspaces[workspaces.length - 1];
}
throw new Error(