refactor(workspace): clean up resolver and improve error handling (#9225)

Removed unused `LoginTokenService` imports and dependencies for better
code clarity. Enhanced error handling in
`getPublicWorkspaceDataBySubdomain` with a try-catch block, ensuring
consistent exception handling. This improves maintainability and
robustness of the resolver.
This commit is contained in:
Antoine Moreaux
2024-12-24 14:41:20 +01:00
committed by GitHub
parent 612f20e925
commit 53f0cd7205

View File

@ -12,7 +12,6 @@ import { FileUpload, GraphQLUpload } from 'graphql-upload';
import { FileFolder } from 'src/engine/core-modules/file/interfaces/file-folder.interface';
import { LoginTokenService } from 'src/engine/core-modules/auth/token/services/login-token.service';
import { BillingSubscription } from 'src/engine/core-modules/billing/entities/billing-subscription.entity';
import { BillingSubscriptionService } from 'src/engine/core-modules/billing/services/billing-subscription.service';
import { DomainManagerService } from 'src/engine/core-modules/domain-manager/service/domain-manager.service';
@ -54,7 +53,6 @@ import { WorkspaceService } from './services/workspace.service';
export class WorkspaceResolver {
constructor(
private readonly workspaceService: WorkspaceService,
private readonly loginTokenService: LoginTokenService,
private readonly domainManagerService: DomainManagerService,
private readonly userWorkspaceService: UserWorkspaceService,
private readonly environmentService: EnvironmentService,
@ -186,50 +184,54 @@ export class WorkspaceResolver {
@Query(() => PublicWorkspaceDataOutput)
async getPublicWorkspaceDataBySubdomain(@OriginHeader() origin: string) {
const workspace =
await this.domainManagerService.getWorkspaceByOriginOrDefaultWorkspace(
origin,
try {
const workspace =
await this.domainManagerService.getWorkspaceByOriginOrDefaultWorkspace(
origin,
);
workspaceValidator.assertIsDefinedOrThrow(
workspace,
new WorkspaceException(
'Workspace not found',
WorkspaceExceptionCode.WORKSPACE_NOT_FOUND,
),
);
workspaceValidator.assertIsDefinedOrThrow(
workspace,
new WorkspaceException(
'Workspace not found',
WorkspaceExceptionCode.WORKSPACE_NOT_FOUND,
),
);
let workspaceLogoWithToken = '';
let workspaceLogoWithToken = '';
if (workspace.logo) {
try {
const workspaceLogoToken = await this.fileService.encodeFileToken({
workspaceId: workspace.id,
});
if (workspace.logo) {
try {
const workspaceLogoToken = await this.fileService.encodeFileToken({
workspaceId: workspace.id,
});
workspaceLogoWithToken = `${workspace.logo}?token=${workspaceLogoToken}`;
} catch (e) {
workspaceLogoWithToken = workspace.logo;
workspaceLogoWithToken = `${workspace.logo}?token=${workspaceLogoToken}`;
} catch (e) {
workspaceLogoWithToken = workspace.logo;
}
}
const systemEnabledProviders: AuthProviders = {
google: this.environmentService.get('AUTH_GOOGLE_ENABLED'),
magicLink: false,
password: this.environmentService.get('AUTH_PASSWORD_ENABLED'),
microsoft: this.environmentService.get('AUTH_MICROSOFT_ENABLED'),
sso: [],
};
return {
id: workspace.id,
logo: workspaceLogoWithToken,
displayName: workspace.displayName,
subdomain: workspace.subdomain,
authProviders: getAuthProvidersByWorkspace({
workspace,
systemEnabledProviders,
}),
};
} catch (err) {
workspaceGraphqlApiExceptionHandler(err);
}
const systemEnabledProviders: AuthProviders = {
google: this.environmentService.get('AUTH_GOOGLE_ENABLED'),
magicLink: false,
password: this.environmentService.get('AUTH_PASSWORD_ENABLED'),
microsoft: this.environmentService.get('AUTH_MICROSOFT_ENABLED'),
sso: [],
};
return {
id: workspace.id,
logo: workspaceLogoWithToken,
displayName: workspace.displayName,
subdomain: workspace.subdomain,
authProviders: getAuthProvidersByWorkspace({
workspace,
systemEnabledProviders,
}),
};
}
}