diff --git a/apps/server/src/modules/board/board-collaboration.module.ts b/apps/server/src/modules/board/board-collaboration.module.ts index 4bdd0b0180e..84354cdfa19 100644 --- a/apps/server/src/modules/board/board-collaboration.module.ts +++ b/apps/server/src/modules/board/board-collaboration.module.ts @@ -1,12 +1,12 @@ import { AuthGuardModule, AuthGuardOptions } from '@infra/auth-guard'; import { MikroOrmModule } from '@mikro-orm/nestjs'; -import { defaultMikroOrmOptions } from '@modules/server'; import { Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import { ALL_ENTITIES } from '@shared/domain/entity'; import { createConfigModuleOptions, DB_PASSWORD, DB_URL, DB_USERNAME } from '@src/config'; import { CoreModule } from '@src/core'; import { RabbitMQWrapperModule } from '@src/infra/rabbitmq'; +import { defaultMikroOrmOptions } from '@shared/common'; import { AuthorizationModule } from '../authorization'; import { config } from './board-collaboration.config'; import { BoardWsApiModule } from './board-ws-api.module'; diff --git a/apps/server/src/modules/board/board-collaboration.testing.module.ts b/apps/server/src/modules/board/board-collaboration.testing.module.ts index 68f7c038104..4f0e78deed7 100644 --- a/apps/server/src/modules/board/board-collaboration.testing.module.ts +++ b/apps/server/src/modules/board/board-collaboration.testing.module.ts @@ -1,4 +1,4 @@ -import { defaultMikroOrmOptions, serverConfig } from '@modules/server'; +import { serverConfig } from '@modules/server'; import { Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import { ALL_ENTITIES } from '@shared/domain/entity'; @@ -7,6 +7,7 @@ import { CoreModule } from '@src/core'; import { AuthGuardModule, AuthGuardOptions } from '@src/infra/auth-guard'; import { MongoMemoryDatabaseModule } from '@src/infra/database'; import { RabbitMQWrapperTestModule } from '@src/infra/rabbitmq'; +import { defaultMikroOrmOptions } from '@shared/common'; import { AuthenticationApiModule } from '../authentication/authentication-api.module'; import { AuthorizationModule } from '../authorization'; import { config as boardCollaborationConfig } from './board-collaboration.config'; diff --git a/apps/server/src/modules/deletion-console/deletion-console.module.ts b/apps/server/src/modules/deletion-console/deletion-console.module.ts index 8cab979dc6f..1cedf762c5a 100644 --- a/apps/server/src/modules/deletion-console/deletion-console.module.ts +++ b/apps/server/src/modules/deletion-console/deletion-console.module.ts @@ -7,8 +7,8 @@ import { ConsoleWriterModule } from '@infra/console'; import { UserModule } from '@modules/user'; import { ALL_ENTITIES } from '@shared/domain/entity'; import { DB_PASSWORD, DB_URL, DB_USERNAME, createConfigModuleOptions } from '@src/config'; -import { defaultMikroOrmOptions } from '@modules/server'; import { AccountModule } from '@modules/account'; +import { defaultMikroOrmOptions } from '@shared/common'; import { getDeletionClientConfig } from './deletion-client/deletion-client.config'; import { FileEntity } from '../files/entity'; import { DeletionClient } from './deletion-client'; 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 f6d440130e0..9b0a3327f31 100644 --- a/apps/server/src/modules/files-storage/files-storage.module.ts +++ b/apps/server/src/modules/files-storage/files-storage.module.ts @@ -9,6 +9,7 @@ import { Module, NotFoundException } from '@nestjs/common'; import { ALL_ENTITIES } from '@shared/domain/entity'; import { DB_PASSWORD, DB_URL, DB_USERNAME } from '@src/config'; import { LoggerModule } from '@src/core/logger'; +import { defaultMikroOrmOptions } from '@shared/common'; import { FileRecord, FileRecordSecurityCheck } from './entity'; import { s3Config } from './files-storage.config'; import { FileRecordRepo } from './repo'; @@ -29,12 +30,6 @@ const imports = [ ]; const providers = [FilesStorageService, PreviewService, FileRecordRepo]; -const defaultMikroOrmOptions: MikroOrmModuleSyncOptions = { - findOneOrFailHandler: (entityName: string, where: Dictionary | IPrimaryKey) => - // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - new NotFoundException(`The requested ${entityName}: ${where} has not been found.`), -}; - @Module({ imports: [ ...imports, diff --git a/apps/server/src/modules/fwu-learning-contents/fwu-learning-contents.module.ts b/apps/server/src/modules/fwu-learning-contents/fwu-learning-contents.module.ts index 01f90028efd..cf37ee653a9 100644 --- a/apps/server/src/modules/fwu-learning-contents/fwu-learning-contents.module.ts +++ b/apps/server/src/modules/fwu-learning-contents/fwu-learning-contents.module.ts @@ -1,28 +1,22 @@ import { AuthGuardModule, AuthGuardOptions } from '@infra/auth-guard'; 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 { MikroOrmModule } from '@mikro-orm/nestjs'; import { AuthorizationModule } from '@modules/authorization'; import { SystemEntity } from '@modules/system/entity'; import { HttpModule } from '@nestjs/axios'; -import { Module, NotFoundException } from '@nestjs/common'; +import { Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import { Role, SchoolEntity, SchoolYearEntity, User } from '@shared/domain/entity'; import { createConfigModuleOptions, DB_PASSWORD, DB_URL, DB_USERNAME } from '@src/config'; import { CoreModule } from '@src/core'; import { LoggerModule } from '@src/core/logger'; import { AccountEntity } from '@src/modules/account/domain/entity/account.entity'; +import { defaultMikroOrmOptions } from '@shared/common'; import { FwuLearningContentsController } from './controller/fwu-learning-contents.controller'; import { config, s3Config } from './fwu-learning-contents.config'; import { FwuLearningContentsUc } from './uc/fwu-learning-contents.uc'; -const defaultMikroOrmOptions: MikroOrmModuleSyncOptions = { - findOneOrFailHandler: (entityName: string, where: Dictionary | IPrimaryKey) => - // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - new NotFoundException(`The requested ${entityName}: ${where} has not been found.`), -}; - @Module({ imports: [ AuthorizationModule, diff --git a/apps/server/src/modules/h5p-editor/h5p-editor.module.ts b/apps/server/src/modules/h5p-editor/h5p-editor.module.ts index 4c2bcc32b00..92bb164504d 100644 --- a/apps/server/src/modules/h5p-editor/h5p-editor.module.ts +++ b/apps/server/src/modules/h5p-editor/h5p-editor.module.ts @@ -2,15 +2,15 @@ import { AuthGuardModule, AuthGuardOptions } from '@infra/auth-guard'; import { AuthorizationClientModule } from '@infra/authorization-client'; 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 { MikroOrmModule } from '@mikro-orm/nestjs'; import { UserModule } from '@modules/user'; -import { Module, NotFoundException } from '@nestjs/common'; +import { Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import { ALL_ENTITIES } from '@shared/domain/entity'; import { createConfigModuleOptions, DB_PASSWORD, DB_URL, DB_USERNAME } from '@src/config'; import { CoreModule } from '@src/core'; import { Logger } from '@src/core/logger'; +import { defaultMikroOrmOptions } from '@shared/common'; import { H5PEditorController } from './controller/h5p-editor.controller'; import { H5PContent, InstalledLibrary } from './entity'; import { authorizationClientConfig, config, s3ConfigContent, s3ConfigLibraries } from './h5p-editor.config'; @@ -19,12 +19,6 @@ import { H5PContentRepo, LibraryRepo } from './repo'; import { ContentStorage, LibraryStorage, TemporaryFileStorage } from './service'; import { H5PEditorUc } from './uc/h5p.uc'; -const defaultMikroOrmOptions: MikroOrmModuleSyncOptions = { - findOneOrFailHandler: (entityName: string, where: Dictionary | IPrimaryKey) => - // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - new NotFoundException(`The requested ${entityName}: ${where} has not been found.`), -}; - const imports = [ AuthorizationClientModule.register(authorizationClientConfig), CoreModule, diff --git a/apps/server/src/modules/idp-console/idp-console.module.ts b/apps/server/src/modules/idp-console/idp-console.module.ts index 508d7b514dc..8bbd28c36c3 100644 --- a/apps/server/src/modules/idp-console/idp-console.module.ts +++ b/apps/server/src/modules/idp-console/idp-console.module.ts @@ -3,7 +3,6 @@ import { RabbitMQWrapperModule } from '@infra/rabbitmq'; import { SchulconnexClientModule } from '@infra/schulconnex-client/schulconnex-client.module'; import { MikroOrmModule } from '@mikro-orm/nestjs'; import { AccountModule } from '@modules/account'; -import { defaultMikroOrmOptions } from '@modules/server'; import { SynchronizationEntity, SynchronizationModule } from '@modules/synchronization'; import { UserModule } from '@modules/user'; import { Module } from '@nestjs/common'; @@ -12,6 +11,7 @@ import { ALL_ENTITIES } from '@shared/domain/entity'; import { DB_PASSWORD, DB_URL, DB_USERNAME } from '@src/config'; import { LoggerModule } from '@src/core/logger'; import { ConsoleModule } from 'nestjs-console'; +import { defaultMikroOrmOptions } from '@shared/common'; import { IdpSyncConsole } from './idp-sync-console'; import { SynchronizationUc } from './uc'; diff --git a/apps/server/src/modules/management/management-server.module.ts b/apps/server/src/modules/management/management-server.module.ts index ba2feba4dfe..366aef4af06 100644 --- a/apps/server/src/modules/management/management-server.module.ts +++ b/apps/server/src/modules/management/management-server.module.ts @@ -1,18 +1,12 @@ import { MongoMemoryDatabaseModule } from '@infra/database'; -import { MongoDatabaseModuleOptions } from '@infra/database/mongo-memory-database/types'; -import { Dictionary, IPrimaryKey } from '@mikro-orm/core'; -import { MikroOrmModule, MikroOrmModuleSyncOptions } from '@mikro-orm/nestjs'; -import { DynamicModule, Module, NotFoundException } from '@nestjs/common'; +import { MongoDatabaseModuleOptions } from '@infra/database/mongo-memory-database/types'; // Fix me!! +import { MikroOrmModule } from '@mikro-orm/nestjs'; +import { DynamicModule, Module } from '@nestjs/common'; import { ALL_ENTITIES } from '@shared/domain/entity'; import { DB_PASSWORD, DB_URL, DB_USERNAME } from '@src/config'; +import { defaultMikroOrmOptions } from '@shared/common'; import { ManagementModule } from './management.module'; -export const defaultMikroOrmOptions: MikroOrmModuleSyncOptions = { - findOneOrFailHandler: (entityName: string, where: Dictionary | IPrimaryKey) => - // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - new NotFoundException(`The requested ${entityName}: ${where} has not been found.`), -}; - @Module({ imports: [ ManagementModule, diff --git a/apps/server/src/modules/server/admin-api.server.module.ts b/apps/server/src/modules/server/admin-api.server.module.ts index fa40347b5bb..10ef2ff0f1b 100644 --- a/apps/server/src/modules/server/admin-api.server.module.ts +++ b/apps/server/src/modules/server/admin-api.server.module.ts @@ -1,13 +1,12 @@ import { Configuration } from '@hpi-schul-cloud/commons'; import { AuthGuardModule, AuthGuardOptions } from '@infra/auth-guard'; -import { Dictionary, IPrimaryKey } from '@mikro-orm/core'; -import { MikroOrmModule, MikroOrmModuleSyncOptions } from '@mikro-orm/nestjs'; +import { MikroOrmModule } from '@mikro-orm/nestjs'; import { DeletionApiModule } from '@modules/deletion/deletion-api.module'; import { FileEntity } from '@modules/files/entity'; import { LegacySchoolAdminApiModule } from '@modules/legacy-school/legacy-school-admin.api-module'; import { ToolAdminApiModule } from '@modules/tool/tool-admin-api.module'; import { UserAdminApiModule } from '@modules/user/user-admin-api.module'; -import { DynamicModule, Module, NotFoundException } from '@nestjs/common'; +import { DynamicModule, Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import { CqrsModule } from '@nestjs/cqrs'; import { ALL_ENTITIES } from '@shared/domain/entity'; @@ -16,6 +15,7 @@ import { LoggerModule } from '@src/core/logger'; import { MongoDatabaseModuleOptions, MongoMemoryDatabaseModule } from '@src/infra/database'; import { EtherpadClientModule } from '@src/infra/etherpad-client'; import { RabbitMQWrapperModule, RabbitMQWrapperTestModule } from '@src/infra/rabbitmq'; +import { defaultMikroOrmOptions } from '@shared/common'; import { AdminApiRegistrationPinModule } from '../registration-pin/admin-api-registration-pin.module'; import { adminApiServerConfig } from './admin-api-server.config'; @@ -33,12 +33,6 @@ const serverModules = [ AuthGuardModule.register([AuthGuardOptions.X_API_KEY]), ]; -const defaultMikroOrmOptions: MikroOrmModuleSyncOptions = { - findOneOrFailHandler: (entityName: string, where: Dictionary | IPrimaryKey) => - // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - new NotFoundException(`The requested ${entityName}: ${where} has not been found.`), -}; - @Module({ imports: [ RabbitMQWrapperModule, diff --git a/apps/server/src/modules/server/index.ts b/apps/server/src/modules/server/index.ts index 9b15d3dd353..c9fa5da6147 100644 --- a/apps/server/src/modules/server/index.ts +++ b/apps/server/src/modules/server/index.ts @@ -1,2 +1,2 @@ -export * from './server.config'; +export * from './server.config'; // TODO: Remove me!!! export * from './server.module'; diff --git a/apps/server/src/modules/server/server.module.ts b/apps/server/src/modules/server/server.module.ts index 46cafe9c2e7..e95d93f2103 100644 --- a/apps/server/src/modules/server/server.module.ts +++ b/apps/server/src/modules/server/server.module.ts @@ -4,8 +4,7 @@ import { MongoDatabaseModuleOptions, MongoMemoryDatabaseModule } from '@infra/da import { MailModule } from '@infra/mail'; import { RabbitMQWrapperModule, RabbitMQWrapperTestModule } from '@infra/rabbitmq'; import { SchulconnexClientModule } from '@infra/schulconnex-client/schulconnex-client.module'; -import { Dictionary, IPrimaryKey } from '@mikro-orm/core'; -import { MikroOrmModule, MikroOrmModuleSyncOptions } from '@mikro-orm/nestjs'; +import { MikroOrmModule } from '@mikro-orm/nestjs'; import { AccountApiModule } from '@modules/account/account-api.module'; import { AlertModule } from '@modules/alert/alert.module'; import { AuthenticationApiModule } from '@modules/authentication/authentication-api.module'; @@ -42,12 +41,13 @@ import { UserLoginMigrationApiModule } from '@modules/user-login-migration/user- import { UsersAdminApiModule } from '@modules/user/legacy/users-admin-api.module'; import { UserApiModule } from '@modules/user/user-api.module'; import { VideoConferenceApiModule } from '@modules/video-conference/video-conference-api.module'; -import { DynamicModule, Module, NotFoundException } from '@nestjs/common'; +import { DynamicModule, Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import { ALL_ENTITIES } from '@shared/domain/entity'; import { createConfigModuleOptions, DB_PASSWORD, DB_URL, DB_USERNAME } from '@src/config'; import { CoreModule } from '@src/core'; import { LoggerModule } from '@src/core/logger'; +import { defaultMikroOrmOptions } from '@shared/common'; import { ServerConfigController, ServerController, ServerUc } from './api'; import { SERVER_CONFIG_TOKEN, serverConfig } from './server.config'; @@ -106,12 +106,6 @@ const serverModules = [ ShdApiModule, ]; -export const defaultMikroOrmOptions: MikroOrmModuleSyncOptions = { - findOneOrFailHandler: (entityName: string, where: Dictionary | IPrimaryKey) => - // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - new NotFoundException(`The requested ${entityName}: ${where} has not been found.`), -}; - const providers = [ServerUc, { provide: SERVER_CONFIG_TOKEN, useValue: serverConfig() }]; const controllers = [ServerController, ServerConfigController]; diff --git a/apps/server/src/modules/tldraw/tldraw-api.module.ts b/apps/server/src/modules/tldraw/tldraw-api.module.ts index e5d85599267..1e40e769924 100644 --- a/apps/server/src/modules/tldraw/tldraw-api.module.ts +++ b/apps/server/src/modules/tldraw/tldraw-api.module.ts @@ -1,23 +1,17 @@ import { AuthGuardModule, AuthGuardOptions } from '@infra/auth-guard'; -import { Dictionary, IPrimaryKey } from '@mikro-orm/core'; -import { MikroOrmModule, MikroOrmModuleSyncOptions } from '@mikro-orm/nestjs'; -import { Module, NotFoundException } from '@nestjs/common'; +import { MikroOrmModule } from '@mikro-orm/nestjs'; +import { Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import { createConfigModuleOptions, DB_PASSWORD, DB_USERNAME } from '@src/config'; import { CoreModule } from '@src/core'; import { LoggerModule } from '@src/core/logger'; +import { defaultMikroOrmOptions } from '@shared/common'; import { config, TLDRAW_DB_URL } from './config'; import { TldrawController } from './controller'; import { TldrawDrawing } from './entities'; import { TldrawBoardRepo, TldrawRepo, YMongodb } from './repo'; import { TldrawService } from './service'; -const defaultMikroOrmOptions: MikroOrmModuleSyncOptions = { - findOneOrFailHandler: (entityName: string, where: Dictionary | IPrimaryKey) => - // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - new NotFoundException(`The requested ${entityName}: ${where} has not been found.`), -}; - @Module({ imports: [ LoggerModule, diff --git a/apps/server/src/modules/tldraw/tldraw-console.module.ts b/apps/server/src/modules/tldraw/tldraw-console.module.ts index cc25308ce27..2fc741de464 100644 --- a/apps/server/src/modules/tldraw/tldraw-console.module.ts +++ b/apps/server/src/modules/tldraw/tldraw-console.module.ts @@ -1,15 +1,15 @@ import { ConsoleWriterModule } from '@infra/console'; 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 } from '@nestjs/common'; +import { MikroOrmModule } from '@mikro-orm/nestjs'; +import { Module } from '@nestjs/common'; import { ConfigModule, ConfigService } from '@nestjs/config'; import { initialisePerformanceObserver } from '@shared/common/measure-utils'; import { createConfigModuleOptions, DB_PASSWORD, DB_USERNAME } from '@src/config'; import { CoreModule } from '@src/core'; import { Logger, LoggerModule } from '@src/core/logger'; import { ConsoleModule } from 'nestjs-console'; +import { defaultMikroOrmOptions } from '@shared/common'; import { FilesStorageClientModule } from '../files-storage-client'; import { config, TLDRAW_DB_URL, TldrawConfig, tldrawS3Config } from './config'; import { TldrawDrawing } from './entities'; @@ -18,12 +18,6 @@ import { TldrawRepo, YMongodb } from './repo'; import { TldrawFilesStorageAdapterService } from './service'; import { TldrawDeleteFilesUc } from './uc'; -const defaultMikroOrmOptions: MikroOrmModuleSyncOptions = { - findOneOrFailHandler: (entityName: string, where: Dictionary | IPrimaryKey) => - // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - new NotFoundException(`The requested ${entityName}: ${where} has not been found.`), -}; - @Module({ imports: [ S3ClientModule.register([tldrawS3Config]), diff --git a/apps/server/src/modules/tldraw/tldraw-ws.module.ts b/apps/server/src/modules/tldraw/tldraw-ws.module.ts index 7273c14814c..307048ab233 100644 --- a/apps/server/src/modules/tldraw/tldraw-ws.module.ts +++ b/apps/server/src/modules/tldraw/tldraw-ws.module.ts @@ -1,12 +1,12 @@ -import { Dictionary, IPrimaryKey } from '@mikro-orm/core'; -import { MikroOrmModule, MikroOrmModuleSyncOptions } from '@mikro-orm/nestjs'; +import { MikroOrmModule } from '@mikro-orm/nestjs'; import { HttpModule } from '@nestjs/axios'; -import { Module, NotFoundException } from '@nestjs/common'; +import { Module } from '@nestjs/common'; import { ConfigModule, ConfigService } from '@nestjs/config'; import { initialisePerformanceObserver } from '@shared/common/measure-utils'; import { createConfigModuleOptions, DB_PASSWORD, DB_USERNAME } from '@src/config'; import { CoreModule } from '@src/core'; import { Logger, LoggerModule } from '@src/core/logger'; +import { defaultMikroOrmOptions } from '@shared/common'; import { config, TLDRAW_DB_URL, TldrawConfig } from './config'; import { TldrawWs } from './controller'; import { TldrawDrawing } from './entities'; @@ -15,11 +15,6 @@ import { TldrawRedisFactory, TldrawRedisService } from './redis'; import { TldrawBoardRepo, TldrawRepo, YMongodb } from './repo'; import { TldrawWsService } from './service'; -const defaultMikroOrmOptions: MikroOrmModuleSyncOptions = { - findOneOrFailHandler: (entityName: string, where: Dictionary | IPrimaryKey) => - // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - new NotFoundException(`The requested ${entityName}: ${where} has not been found.`), -}; @Module({ imports: [ HttpModule, diff --git a/apps/server/src/shared/common/defaultMikroOrmOptions.ts b/apps/server/src/shared/common/defaultMikroOrmOptions.ts new file mode 100644 index 00000000000..8c731e38c34 --- /dev/null +++ b/apps/server/src/shared/common/defaultMikroOrmOptions.ts @@ -0,0 +1,9 @@ +import { MikroOrmModuleSyncOptions } from '@mikro-orm/nestjs'; +import { NotFoundException } from '@nestjs/common'; +import { Dictionary, IPrimaryKey } from '@mikro-orm/core'; + +export const defaultMikroOrmOptions: MikroOrmModuleSyncOptions = { + findOneOrFailHandler: (entityName: string, where: Dictionary | IPrimaryKey) => + // eslint-disable-next-line @typescript-eslint/restrict-template-expressions + new NotFoundException(`The requested ${entityName}: ${where} has not been found.`), +}; diff --git a/apps/server/src/shared/common/index.ts b/apps/server/src/shared/common/index.ts index 95ae196d3a1..0497258c967 100644 --- a/apps/server/src/shared/common/index.ts +++ b/apps/server/src/shared/common/index.ts @@ -1,4 +1,5 @@ export { RequestTimeout } from './decorators'; +export { defaultMikroOrmOptions } from './defaultMikroOrmOptions'; export * from './error'; export * from './guards'; export * from './interceptor';