2023-06-01 06:32:51 -04:00
|
|
|
import { BullModule } from '@nestjs/bullmq';
|
2024-06-27 15:54:20 -04:00
|
|
|
import { Inject, Module, OnModuleDestroy, OnModuleInit, ValidationPipe } from '@nestjs/common';
|
2023-03-28 12:29:20 -04:00
|
|
|
import { ConfigModule } from '@nestjs/config';
|
2024-06-27 15:54:20 -04:00
|
|
|
import { APP_FILTER, APP_GUARD, APP_INTERCEPTOR, APP_PIPE, ModuleRef } from '@nestjs/core';
|
2024-03-17 20:16:02 +01:00
|
|
|
import { EventEmitterModule } from '@nestjs/event-emitter';
|
2023-10-31 23:40:35 -05:00
|
|
|
import { ScheduleModule, SchedulerRegistry } from '@nestjs/schedule';
|
2023-01-11 21:34:36 -05:00
|
|
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
2024-04-15 19:39:06 -04:00
|
|
|
import { ClsModule } from 'nestjs-cls';
|
2024-03-12 01:19:12 -04:00
|
|
|
import { OpenTelemetryModule } from 'nestjs-otel';
|
2024-03-30 00:16:06 -04:00
|
|
|
import { commands } from 'src/commands';
|
2024-04-15 19:39:06 -04:00
|
|
|
import { bullConfig, bullQueues, clsConfig, immichAppConfig } from 'src/config';
|
2024-03-30 00:16:06 -04:00
|
|
|
import { controllers } from 'src/controllers';
|
2024-03-20 22:15:09 -05:00
|
|
|
import { databaseConfig } from 'src/database.config';
|
2024-03-30 00:16:06 -04:00
|
|
|
import { entities } from 'src/entities';
|
2024-06-27 15:54:20 -04:00
|
|
|
import { IEventRepository } from 'src/interfaces/event.interface';
|
2024-03-21 09:08:29 -05:00
|
|
|
import { AuthGuard } from 'src/middleware/auth.guard';
|
|
|
|
import { ErrorInterceptor } from 'src/middleware/error.interceptor';
|
|
|
|
import { FileUploadInterceptor } from 'src/middleware/file-upload.interceptor';
|
2024-06-05 17:07:47 -04:00
|
|
|
import { HttpExceptionFilter } from 'src/middleware/http-exception.filter';
|
2024-04-16 19:21:57 -04:00
|
|
|
import { LoggingInterceptor } from 'src/middleware/logging.interceptor';
|
2024-03-30 00:16:06 -04:00
|
|
|
import { repositories } from 'src/repositories';
|
|
|
|
import { services } from 'src/services';
|
2024-06-27 15:54:20 -04:00
|
|
|
import { setupEventHandlers } from 'src/utils/events';
|
2024-03-20 22:15:09 -05:00
|
|
|
import { otelConfig } from 'src/utils/instrumentation';
|
2023-01-11 21:34:36 -05:00
|
|
|
|
2024-04-15 19:39:06 -04:00
|
|
|
const common = [...services, ...repositories];
|
2023-01-11 21:34:36 -05:00
|
|
|
|
2024-03-21 09:08:29 -05:00
|
|
|
const middleware = [
|
|
|
|
FileUploadInterceptor,
|
2024-06-05 17:07:47 -04:00
|
|
|
{ provide: APP_FILTER, useClass: HttpExceptionFilter },
|
2024-03-21 09:08:29 -05:00
|
|
|
{ provide: APP_PIPE, useValue: new ValidationPipe({ transform: true, whitelist: true }) },
|
2024-04-16 19:21:57 -04:00
|
|
|
{ provide: APP_INTERCEPTOR, useClass: LoggingInterceptor },
|
2024-03-21 09:08:29 -05:00
|
|
|
{ provide: APP_INTERCEPTOR, useClass: ErrorInterceptor },
|
|
|
|
{ provide: APP_GUARD, useClass: AuthGuard },
|
|
|
|
];
|
|
|
|
|
|
|
|
const imports = [
|
|
|
|
BullModule.forRoot(bullConfig),
|
|
|
|
BullModule.registerQueue(...bullQueues),
|
2024-04-15 19:39:06 -04:00
|
|
|
ClsModule.forRoot(clsConfig),
|
2024-03-21 09:08:29 -05:00
|
|
|
ConfigModule.forRoot(immichAppConfig),
|
|
|
|
EventEmitterModule.forRoot(),
|
|
|
|
OpenTelemetryModule.forRoot(otelConfig),
|
|
|
|
TypeOrmModule.forRoot(databaseConfig),
|
2024-03-30 00:16:06 -04:00
|
|
|
TypeOrmModule.forFeature(entities),
|
2024-03-21 09:08:29 -05:00
|
|
|
];
|
|
|
|
|
2023-01-11 21:34:36 -05:00
|
|
|
@Module({
|
2024-03-21 09:08:29 -05:00
|
|
|
imports: [...imports, ScheduleModule.forRoot()],
|
|
|
|
controllers: [...controllers],
|
2024-03-30 00:16:06 -04:00
|
|
|
providers: [...common, ...middleware],
|
2024-03-21 09:08:29 -05:00
|
|
|
})
|
2024-06-27 15:54:20 -04:00
|
|
|
export class ApiModule implements OnModuleInit, OnModuleDestroy {
|
|
|
|
constructor(
|
|
|
|
private moduleRef: ModuleRef,
|
|
|
|
@Inject(IEventRepository) private eventRepository: IEventRepository,
|
|
|
|
) {}
|
2024-03-21 09:08:29 -05:00
|
|
|
|
|
|
|
async onModuleInit() {
|
2024-06-27 15:54:20 -04:00
|
|
|
setupEventHandlers(this.moduleRef);
|
|
|
|
await this.eventRepository.emit('onBootstrapEvent', 'api');
|
|
|
|
}
|
|
|
|
|
|
|
|
async onModuleDestroy() {
|
|
|
|
await this.eventRepository.emit('onShutdownEvent');
|
2024-03-21 09:08:29 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Module({
|
|
|
|
imports: [...imports],
|
2024-03-30 00:16:06 -04:00
|
|
|
providers: [...common, SchedulerRegistry],
|
2023-01-11 21:34:36 -05:00
|
|
|
})
|
2024-06-27 15:54:20 -04:00
|
|
|
export class MicroservicesModule implements OnModuleInit, OnModuleDestroy {
|
|
|
|
constructor(
|
|
|
|
private moduleRef: ModuleRef,
|
|
|
|
@Inject(IEventRepository) private eventRepository: IEventRepository,
|
|
|
|
) {}
|
2024-03-21 09:08:29 -05:00
|
|
|
|
|
|
|
async onModuleInit() {
|
2024-06-27 15:54:20 -04:00
|
|
|
setupEventHandlers(this.moduleRef);
|
|
|
|
await this.eventRepository.emit('onBootstrapEvent', 'microservices');
|
|
|
|
}
|
|
|
|
|
|
|
|
async onModuleDestroy() {
|
|
|
|
await this.eventRepository.emit('onShutdownEvent');
|
2024-03-21 09:08:29 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Module({
|
|
|
|
imports: [...imports],
|
2024-03-30 00:16:06 -04:00
|
|
|
providers: [...common, ...commands, SchedulerRegistry],
|
2024-03-21 09:08:29 -05:00
|
|
|
})
|
|
|
|
export class ImmichAdminModule {}
|
2024-01-09 17:07:01 -05:00
|
|
|
|
|
|
|
@Module({
|
|
|
|
imports: [
|
|
|
|
ConfigModule.forRoot(immichAppConfig),
|
2024-03-17 20:16:02 +01:00
|
|
|
EventEmitterModule.forRoot(),
|
2024-01-09 17:07:01 -05:00
|
|
|
TypeOrmModule.forRoot(databaseConfig),
|
2024-03-30 00:16:06 -04:00
|
|
|
TypeOrmModule.forFeature(entities),
|
2024-03-24 23:02:04 -04:00
|
|
|
OpenTelemetryModule.forRoot(otelConfig),
|
2024-01-09 17:07:01 -05:00
|
|
|
],
|
2024-03-21 09:08:29 -05:00
|
|
|
controllers: [...controllers],
|
2024-03-30 00:16:06 -04:00
|
|
|
providers: [...common, ...middleware, SchedulerRegistry],
|
2024-01-09 17:07:01 -05:00
|
|
|
})
|
2024-03-20 16:46:59 -05:00
|
|
|
export class AppTestModule {}
|