user/src/app.module.ts

68 lines
2.3 KiB
TypeScript
Raw Normal View History

2022-12-13 12:39:06 +00:00
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
2023-03-31 08:33:59 +00:00
import { UserModule } from './modules/user/user.module';
import {
ConfigurationModule,
ConfigurationModuleOptions,
} from '@mobicoop/configuration-module';
import {
2023-07-20 15:22:31 +00:00
HealthModule,
HealthModuleOptions,
HealthRepositoryPort,
} from '@mobicoop/health-module';
import { MessagerModule } from './modules/messager/messager.module';
import { USER_REPOSITORY } from './modules/user/user.di-tokens';
import { MESSAGE_PUBLISHER } from './modules/messager/messager.di-tokens';
import { MessagePublisherPort } from '@mobicoop/ddd-library';
2023-07-21 12:22:13 +00:00
import { EventEmitterModule } from '@nestjs/event-emitter';
2022-12-13 12:39:06 +00:00
@Module({
2022-12-14 10:37:13 +00:00
imports: [
ConfigModule.forRoot({ isGlobal: true }),
2023-07-21 12:22:13 +00:00
EventEmitterModule.forRoot(),
2023-07-20 15:22:31 +00:00
ConfigurationModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (
configService: ConfigService,
): Promise<ConfigurationModuleOptions> => ({
domain: configService.get<string>('SERVICE_CONFIGURATION_DOMAIN'),
messageBroker: {
uri: configService.get<string>('MESSAGE_BROKER_URI'),
exchange: configService.get<string>('MESSAGE_BROKER_EXCHANGE'),
2023-07-20 15:22:31 +00:00
},
redis: {
host: configService.get<string>('REDIS_HOST'),
password: configService.get<string>('REDIS_PASSWORD'),
port: configService.get<number>('REDIS_PORT'),
},
setConfigurationBrokerQueue: 'user-configuration-create-update',
deleteConfigurationQueue: 'user-configuration-delete',
propagateConfigurationQueue: 'user-configuration-propagate',
}),
}),
HealthModule.forRootAsync({
imports: [UserModule, MessagerModule],
inject: [USER_REPOSITORY, MESSAGE_PUBLISHER],
useFactory: async (
userRepository: HealthRepositoryPort,
messagePublisher: MessagePublisherPort,
): Promise<HealthModuleOptions> => ({
serviceName: 'user',
criticalLoggingKey: 'logging.user.health.crit',
checkRepositories: [
{
name: 'UserRepository',
repository: userRepository,
},
2023-07-20 15:22:31 +00:00
],
messagePublisher,
}),
}),
UserModule,
MessagerModule,
2022-12-14 10:37:13 +00:00
],
2023-07-20 15:22:31 +00:00
exports: [UserModule, MessagerModule],
2022-12-13 12:39:06 +00:00
})
export class AppModule {}