user/src/app.module.ts

66 lines
2.2 KiB
TypeScript

import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { UserModule } from './modules/user/user.module';
import {
ConfigurationModule,
ConfigurationModuleOptions,
} from '@mobicoop/configuration-module';
import {
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';
@Module({
imports: [
ConfigModule.forRoot({ isGlobal: true }),
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'),
},
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,
},
],
messagePublisher,
}),
}),
UserModule,
MessagerModule,
],
exports: [UserModule, MessagerModule],
})
export class AppModule {}