import { HealthModule, HealthModuleOptions, HealthRepositoryPort, } from '@mobicoop/health-module'; import { MessagerModule } from '@modules/messager/messager.module'; import { Module } from '@nestjs/common'; import { ConfigModule, ConfigService } from '@nestjs/config'; import { HEALTH_CONFIGURATION_REPOSITORY, HEALTH_CRITICAL_LOGGING_KEY, SERVICE_NAME, } from './app.constants'; import { MessagePublisherPort } from '@mobicoop/ddd-library'; import { MESSAGE_PUBLISHER } from '@modules/messager/messager.di-tokens'; import { CONFIGURATION_REPOSITORY } from '@modules/configuration/configuration.di-tokens'; import { ConfigurationModule } from '@modules/configuration/configuration.module'; import { EventEmitterModule } from '@nestjs/event-emitter'; import brokerConfig from './config/broker.config'; import carpoolConfig from './config/carpool.config'; import paginationConfig from './config/pagination.config'; import serviceConfig from './config/service.config'; import { RedisModule, RedisModuleOptions } from '@songkeys/nestjs-redis'; import redisConfig from './config/redis.config'; @Module({ imports: [ ConfigModule.forRoot({ isGlobal: true, load: [ brokerConfig, carpoolConfig, paginationConfig, redisConfig, serviceConfig, ], }), EventEmitterModule.forRoot(), HealthModule.forRootAsync({ imports: [ConfigurationModule, MessagerModule], inject: [CONFIGURATION_REPOSITORY, MESSAGE_PUBLISHER], useFactory: async ( configurationRepository: HealthRepositoryPort, messagePublisher: MessagePublisherPort, ): Promise => ({ serviceName: SERVICE_NAME, criticalLoggingKey: HEALTH_CRITICAL_LOGGING_KEY, checkRepositories: [ { name: HEALTH_CONFIGURATION_REPOSITORY, repository: configurationRepository, }, ], messagePublisher, }), }), RedisModule.forRootAsync({ imports: [ConfigModule], inject: [ConfigService], useFactory: async ( configService: ConfigService, ): Promise => { return { config: { host: configService.get('redis.host') as string, port: configService.get('redis.port') as number, password: configService.get('redis.password'), }, }; }, }), ConfigurationModule, MessagerModule, ], exports: [ConfigurationModule, MessagerModule], }) export class AppModule {}