diff --git a/apps/server/src/apps/h5p-library-management.app.ts b/apps/server/src/apps/h5p-library-management.app.ts index 10ef160e9c9..0de9d622672 100644 --- a/apps/server/src/apps/h5p-library-management.app.ts +++ b/apps/server/src/apps/h5p-library-management.app.ts @@ -13,12 +13,14 @@ import { H5PLibraryManagementService } from '@src/modules/h5p-library-management async function bootstrap() { sourceMapInstall(); - const nestApp = await NestFactory.createApplicationContext(H5PLibraryManagementModule); + const app = await NestFactory.createApplicationContext(H5PLibraryManagementModule); // WinstonLogger - nestApp.useLogger(await nestApp.resolve(LegacyLogger)); + app.useLogger(await app.resolve(LegacyLogger)); - const manager = new H5PLibraryManagementService(); - manager.run(); + await app.get(H5PLibraryManagementService).run(); + // TODO: properly close app (there is some issue with the logger) + // await app.close(); + process.exit(0); } void bootstrap(); diff --git a/apps/server/src/modules/h5p-library-management/h5p-library-management.module.ts b/apps/server/src/modules/h5p-library-management/h5p-library-management.module.ts index bf73ad3dcf5..4166390adc0 100644 --- a/apps/server/src/modules/h5p-library-management/h5p-library-management.module.ts +++ b/apps/server/src/modules/h5p-library-management/h5p-library-management.module.ts @@ -1,16 +1,22 @@ import { Dictionary, IPrimaryKey } from '@mikro-orm/core'; import { MikroOrmModule, MikroOrmModuleSyncOptions } from '@mikro-orm/nestjs'; import { Module, NotFoundException } from '@nestjs/common'; +import { ConfigModule } from '@nestjs/config'; import { Account, Role, School, SchoolYear, System, User } from '@shared/domain'; import { RabbitMQWrapperModule } from '@shared/infra/rabbitmq'; -import { DB_PASSWORD, DB_URL, DB_USERNAME } from '@src/config'; +import { DB_PASSWORD, DB_URL, DB_USERNAME, createConfigModuleOptions } from '@src/config'; import { CoreModule } from '@src/core'; -import { Logger } from '@src/core/logger'; +import { LegacyLogger, Logger } from '@src/core/logger'; +import { UserModule } from '..'; import { LibraryStorage } from '../h5p-editor/service'; +import { config, s3ConfigLibraries } from '../h5p-editor/h5p-editor.config'; +import { LibraryRepo } from '../h5p-editor/repo'; +import { createS3ClientAdapter } from '../h5p-editor'; -import { UserModule } from '..'; +import { H5PLibraryManagementService } from './service/h5p-library-management.service'; +import { InstalledLibrary } from '../h5p-editor/entity'; const defaultMikroOrmOptions: MikroOrmModuleSyncOptions = { findOneOrFailHandler: (entityName: string, where: Dictionary | IPrimaryKey) => @@ -29,13 +35,29 @@ const imports = [ clientUrl: DB_URL, password: DB_PASSWORD, user: DB_USERNAME, - entities: [User, Account, Role, School, System, SchoolYear], + allowGlobalContext: true, + entities: [User, Account, Role, School, System, SchoolYear, InstalledLibrary], }), + ConfigModule.forRoot(createConfigModuleOptions(config)), ]; const controllers = []; -const providers = [Logger, LibraryStorage]; +const providers = [ + Logger, + H5PLibraryManagementService, + LibraryRepo, + LibraryStorage, + { + provide: 'S3Config_Libraries', + useValue: s3ConfigLibraries, + }, + { + provide: 'S3ClientAdapter_Libraries', + useFactory: createS3ClientAdapter, + inject: ['S3Config_Libraries', LegacyLogger], + }, +]; @Module({ imports, diff --git a/apps/server/src/modules/h5p-library-management/service/h5p-library-management.service.ts b/apps/server/src/modules/h5p-library-management/service/h5p-library-management.service.ts index a8e034fd349..7005214f59e 100644 --- a/apps/server/src/modules/h5p-library-management/service/h5p-library-management.service.ts +++ b/apps/server/src/modules/h5p-library-management/service/h5p-library-management.service.ts @@ -2,9 +2,10 @@ import { Injectable } from '@nestjs/common'; @Injectable() export class H5PLibraryManagementService { - run() { + async run() { // for debugging only // eslint-disable-next-line no-console console.log('Hello from H5PLibraryManagementService'); + return Promise.resolve(); } }