Skip to content

Commit

Permalink
refactor(workspace): clean up resolver and improve error handling (#9225
Browse files Browse the repository at this point in the history
)

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.
  • Loading branch information
AMoreaux authored Dec 24, 2024
1 parent 612f20e commit 53f0cd7
Showing 1 changed file with 43 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}),
};
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);
}
}
}

0 comments on commit 53f0cd7

Please sign in to comment.