diff --git a/packages/twenty-server/src/engine/core-modules/application/application.service.ts b/packages/twenty-server/src/engine/core-modules/application/application.service.ts index 7c63d32bf1e..3aa15129905 100644 --- a/packages/twenty-server/src/engine/core-modules/application/application.service.ts +++ b/packages/twenty-server/src/engine/core-modules/application/application.service.ts @@ -48,6 +48,41 @@ export class ApplicationService { return application.defaultRoleId; } + async findWorkspaceCustomFlatApplicationOrThrow({ + workspaceId, + }: { + workspaceId: string; + }) { + const workspace = await this.workspaceRepository.findOne({ + where: { id: workspaceId }, + withDeleted: true, + }); + + if (!isDefined(workspace)) { + throw new ApplicationException( + `Could not find workspace ${workspaceId}`, + ApplicationExceptionCode.APPLICATION_NOT_FOUND, + ); + } + + const { flatApplicationMaps } = + await this.workspaceCacheService.getOrRecompute(workspace.id, [ + 'flatApplicationMaps', + ]); + + const workspaceCustomFlatApplication = + flatApplicationMaps.byId[workspace.workspaceCustomApplicationId]; + + if (!isDefined(workspaceCustomFlatApplication)) { + throw new ApplicationException( + `Could not find workspace custom application for workspace ${workspaceId}`, + ApplicationExceptionCode.APPLICATION_NOT_FOUND, + ); + } + + return { workspaceCustomFlatApplication }; + } + async findWorkspaceTwentyStandardAndCustomApplicationOrThrow({ workspace: workspaceInput, workspaceId, diff --git a/packages/twenty-server/src/engine/core-modules/file/file-core-picture/services/file-core-picture.service.ts b/packages/twenty-server/src/engine/core-modules/file/file-core-picture/services/file-core-picture.service.ts index 808076ab826..722b0d1f7e0 100644 --- a/packages/twenty-server/src/engine/core-modules/file/file-core-picture/services/file-core-picture.service.ts +++ b/packages/twenty-server/src/engine/core-modules/file/file-core-picture/services/file-core-picture.service.ts @@ -60,7 +60,7 @@ export class FileCorePictureService { const universalIdentifier = applicationUniversalIdentifier ?? ( - await this.applicationService.findWorkspaceTwentyStandardAndCustomApplicationOrThrow( + await this.applicationService.findWorkspaceCustomFlatApplicationOrThrow( { workspaceId }, ) ).workspaceCustomFlatApplication.universalIdentifier; @@ -170,11 +170,9 @@ export class FileCorePictureService { }); const { workspaceCustomFlatApplication } = - await this.applicationService.findWorkspaceTwentyStandardAndCustomApplicationOrThrow( - { - workspaceId, - }, - ); + await this.applicationService.findWorkspaceCustomFlatApplicationOrThrow({ + workspaceId, + }); await this.fileStorageService.delete({ workspaceId, @@ -287,11 +285,9 @@ export class FileCorePictureService { }); const { workspaceCustomFlatApplication: sourceApplication } = - await this.applicationService.findWorkspaceTwentyStandardAndCustomApplicationOrThrow( - { - workspaceId: sourceWorkspaceId, - }, - ); + await this.applicationService.findWorkspaceCustomFlatApplicationOrThrow({ + workspaceId: sourceWorkspaceId, + }); const fileStream = await this.fileStorageService.readFile({ workspaceId: sourceWorkspaceId,