Skip to content

Commit

Permalink
Move defaultMirkoOrmOptions to shared, to avoid implicit importing th…
Browse files Browse the repository at this point in the history
…e server code by using it.
  • Loading branch information
CeEv committed Nov 18, 2024
1 parent 73df13f commit 0a72ea4
Show file tree
Hide file tree
Showing 16 changed files with 42 additions and 83 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
12 changes: 3 additions & 9 deletions apps/server/src/modules/h5p-editor/h5p-editor.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/modules/idp-console/idp-console.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';

Expand Down
14 changes: 4 additions & 10 deletions apps/server/src/modules/management/management-server.module.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
12 changes: 3 additions & 9 deletions apps/server/src/modules/server/admin-api.server.module.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';

Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/modules/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './server.config';
export * from './server.config'; // TODO: Remove me!!!
export * from './server.module';
12 changes: 3 additions & 9 deletions apps/server/src/modules/server/server.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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';

Expand Down Expand Up @@ -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];

Expand Down
12 changes: 3 additions & 9 deletions apps/server/src/modules/tldraw/tldraw-api.module.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
12 changes: 3 additions & 9 deletions apps/server/src/modules/tldraw/tldraw-console.module.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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]),
Expand Down
11 changes: 3 additions & 8 deletions apps/server/src/modules/tldraw/tldraw-ws.module.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions apps/server/src/shared/common/defaultMikroOrmOptions.ts
Original file line number Diff line number Diff line change
@@ -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.`),
};
1 change: 1 addition & 0 deletions apps/server/src/shared/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { RequestTimeout } from './decorators';
export { defaultMikroOrmOptions } from './defaultMikroOrmOptions';
export * from './error';
export * from './guards';
export * from './interceptor';
Expand Down

0 comments on commit 0a72ea4

Please sign in to comment.