matcher/src/app.module.ts

73 lines
2.7 KiB
TypeScript

import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { AdModule } from './modules/ad/ad.module';
import {
ConfigurationModule,
ConfigurationModuleOptions,
} from '@mobicoop/configuration-module';
import { EventEmitterModule } from '@nestjs/event-emitter';
import { RequestContextModule } from 'nestjs-request-context';
import { MessagerModule } from '@modules/messager/messager.module';
import { HealthModule, HealthRepositoryPort } from '@mobicoop/health-module';
import { AD_REPOSITORY } from '@modules/ad/ad.di-tokens';
import { MESSAGE_PUBLISHER } from '@modules/messager/messager.di-tokens';
import { HealthModuleOptions } from '@mobicoop/health-module/dist/core/domain/types/health.types';
import { MessagePublisherPort } from '@mobicoop/ddd-library';
import { GeographyModule } from '@modules/geography/geography.module';
@Module({
imports: [
ConfigModule.forRoot({ isGlobal: true }),
EventEmitterModule.forRoot(),
RequestContextModule,
ConfigurationModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (
configService: ConfigService,
): Promise<ConfigurationModuleOptions> => ({
domain: configService.get<string>(
'SERVICE_CONFIGURATION_DOMAIN',
) as string,
messageBroker: {
uri: configService.get<string>('MESSAGE_BROKER_URI') as string,
exchange: configService.get<string>(
'MESSAGE_BROKER_EXCHANGE',
) as string,
},
redis: {
host: configService.get<string>('REDIS_HOST') as string,
password: configService.get<string>('REDIS_PASSWORD'),
port: configService.get<number>('REDIS_PORT') as number,
},
setConfigurationBrokerQueue: 'matcher-configuration-create-update',
deleteConfigurationQueue: 'matcher-configuration-delete',
propagateConfigurationQueue: 'matcher-configuration-propagate',
}),
}),
HealthModule.forRootAsync({
imports: [AdModule, MessagerModule],
inject: [AD_REPOSITORY, MESSAGE_PUBLISHER],
useFactory: async (
adRepository: HealthRepositoryPort,
messagePublisher: MessagePublisherPort,
): Promise<HealthModuleOptions> => ({
serviceName: 'matcher',
criticalLoggingKey: 'logging.matcher.health.crit',
checkRepositories: [
{
name: 'AdRepository',
repository: adRepository,
},
],
messagePublisher,
}),
}),
AdModule,
GeographyModule,
MessagerModule,
],
exports: [AdModule, GeographyModule, MessagerModule],
})
export class AppModule {}