import { HealthModule, HealthModuleOptions } from '@mobicoop/health-module'; import { MessagerModule } from '@modules/messager/messager.module'; import { Module } from '@nestjs/common'; import { ConfigModule, ConfigService } from '@nestjs/config'; import { HEALTH_CRITICAL_LOGGING_KEY, SERVICE_NAME } from './app.constants'; import { MessagePublisherPort } from '@mobicoop/ddd-library'; import { ConfigurationModuleOptions, ConfigurationModule as ConfigurationModulePackage, } from '@mobicoop/configuration-module'; import { MESSAGE_PUBLISHER } from '@modules/messager/messager.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 redisConfig from './config/redis.config'; import { Transport } from '@nestjs/microservices'; import matchConfig from './config/match.config'; import geographyConfig from './config/geography.config'; import authConfig from './config/auth.config'; @Module({ imports: [ ConfigModule.forRoot({ isGlobal: true, load: [ authConfig, brokerConfig, carpoolConfig, geographyConfig, matchConfig, paginationConfig, redisConfig, serviceConfig, ], }), EventEmitterModule.forRoot(), HealthModule.forRootAsync({ imports: [MessagerModule, ConfigModule], inject: [MESSAGE_PUBLISHER, ConfigService], useFactory: async ( messagePublisher: MessagePublisherPort, configService: ConfigService, ): Promise => ({ serviceName: SERVICE_NAME, criticalLoggingKey: HEALTH_CRITICAL_LOGGING_KEY, messagePublisher, checkMicroservices: [ { host: configService.get('redis.host') as string, port: configService.get('redis.port') as string, password: configService.get('redis.password'), name: 'Redis', transport: Transport.REDIS, }, ], }), }), ConfigurationModulePackage.forRootAsync({ imports: [ConfigModule], inject: [ConfigService], useFactory: async ( configService: ConfigService, ): Promise => { return { 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 {}