diff --git a/apps/server/src/modules/files-storage/files-storage.module.ts b/apps/server/src/modules/files-storage/files-storage.module.ts index e6f4efb5ac4..0b049951767 100644 --- a/apps/server/src/modules/files-storage/files-storage.module.ts +++ b/apps/server/src/modules/files-storage/files-storage.module.ts @@ -5,7 +5,7 @@ import { RabbitMQWrapperModule } from '@infra/rabbitmq'; import { S3ClientModule } from '@infra/s3-client'; import { Dictionary, IPrimaryKey } from '@mikro-orm/core'; import { MikroOrmModule, MikroOrmModuleSyncOptions } from '@mikro-orm/nestjs'; -import { Module, NotFoundException, Scope } from '@nestjs/common'; +import { Module, NotFoundException } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import { ALL_ENTITIES } from '@shared/domain/entity'; import { DB_PASSWORD, DB_URL, DB_USERNAME, createConfigModuleOptions } from '@src/config'; @@ -49,8 +49,6 @@ const defaultMikroOrmOptions: MikroOrmModuleSyncOptions = { password: DB_PASSWORD, user: DB_USERNAME, entities: [...ALL_ENTITIES, FileRecord, FileRecordSecurityCheck], - registerRequestContext: false, // disable the automatic context - scope: Scope.REQUEST, // use nestjs request scopes instead // debug: true, // use it for locally debugging of querys }), diff --git a/apps/server/src/modules/files-storage/uc/files-storage.uc.ts b/apps/server/src/modules/files-storage/uc/files-storage.uc.ts index 7355aab1a15..7ff269380bb 100644 --- a/apps/server/src/modules/files-storage/uc/files-storage.uc.ts +++ b/apps/server/src/modules/files-storage/uc/files-storage.uc.ts @@ -1,3 +1,4 @@ +import { EntityManager, RequestContext } from '@mikro-orm/core'; import { AuthorizationContext } from '@modules/authorization'; import { AuthorizationReferenceService } from '@modules/authorization/domain'; import { HttpService } from '@nestjs/axios'; @@ -36,7 +37,8 @@ export class FilesStorageUC { private readonly authorizationReferenceService: AuthorizationReferenceService, private readonly httpService: HttpService, private readonly filesStorageService: FilesStorageService, - private readonly previewService: PreviewService + private readonly previewService: PreviewService, + private readonly em: EntityManager ) { this.logger.setContext(FilesStorageUC.name); } @@ -69,7 +71,11 @@ export class FilesStorageUC { const fileDto = FileDtoBuilder.buildFromRequest(info, file); try { - const result = await this.filesStorageService.uploadFile(userId, params, fileDto); + const result = await RequestContext.createAsync(this.em, async () => { + const record = await this.filesStorageService.uploadFile(userId, params, fileDto); + + return record; + }); resolve(result); } catch (error) { this.logger.error({ message: 'could not upload file', error: error as Error });