refactor modules
This commit is contained in:
parent
aa06b8c54c
commit
74a855c1b9
|
@ -53,7 +53,5 @@ import { HealthModule } from '@modules/health/health.module';
|
|||
HealthModule,
|
||||
AdModule,
|
||||
],
|
||||
controllers: [],
|
||||
providers: [],
|
||||
})
|
||||
export class AppModule {}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { Module, Provider } from '@nestjs/common';
|
||||
import { CreateAdGrpcController } from './interface/grpc-controllers/create-ad.grpc.controller';
|
||||
import { CqrsModule } from '@nestjs/cqrs';
|
||||
import {
|
||||
|
@ -25,40 +25,66 @@ import { FindAdByIdQueryHandler } from './core/queries/find-ad-by-id/find-ad-by-
|
|||
import { PublishMessageWhenAdIsCreatedDomainEventHandler } from './core/event-handlers/publish-message-when-ad-is-created.domain-event-handler';
|
||||
import { PublishLogMessageWhenAdIsCreatedDomainEventHandler } from './core/event-handlers/publish-log-message-when-ad-is-created.domain-event-handler';
|
||||
|
||||
const grpcControllers = [CreateAdGrpcController, FindAdByIdGrpcController];
|
||||
|
||||
const eventHandlers: Provider[] = [
|
||||
PublishMessageWhenAdIsCreatedDomainEventHandler,
|
||||
PublishLogMessageWhenAdIsCreatedDomainEventHandler,
|
||||
];
|
||||
|
||||
const commandHandlers: Provider[] = [CreateAdService];
|
||||
|
||||
const queryHandlers: Provider[] = [FindAdByIdQueryHandler];
|
||||
|
||||
const mappers: Provider[] = [AdMapper];
|
||||
|
||||
const repositories: Provider[] = [
|
||||
{
|
||||
provide: AD_REPOSITORY,
|
||||
useClass: AdRepository,
|
||||
},
|
||||
];
|
||||
|
||||
const messageBrokers: Provider[] = [
|
||||
{
|
||||
provide: MESSAGE_BROKER_PUBLISHER,
|
||||
useClass: MessageBrokerPublisher,
|
||||
},
|
||||
{
|
||||
provide: MESSAGE_PUBLISHER,
|
||||
useClass: MessagePublisher,
|
||||
},
|
||||
];
|
||||
|
||||
const orms: Provider[] = [PrismaService];
|
||||
|
||||
const utilities: Provider[] = [
|
||||
{
|
||||
provide: PARAMS_PROVIDER,
|
||||
useClass: DefaultParamsProvider,
|
||||
},
|
||||
{
|
||||
provide: TIMEZONE_FINDER,
|
||||
useClass: TimezoneFinder,
|
||||
},
|
||||
{
|
||||
provide: TIME_CONVERTER,
|
||||
useClass: TimeConverter,
|
||||
},
|
||||
];
|
||||
|
||||
@Module({
|
||||
imports: [CqrsModule],
|
||||
controllers: [CreateAdGrpcController, FindAdByIdGrpcController],
|
||||
controllers: [...grpcControllers],
|
||||
providers: [
|
||||
CreateAdService,
|
||||
FindAdByIdQueryHandler,
|
||||
PublishMessageWhenAdIsCreatedDomainEventHandler,
|
||||
PublishLogMessageWhenAdIsCreatedDomainEventHandler,
|
||||
PrismaService,
|
||||
AdMapper,
|
||||
{
|
||||
provide: AD_REPOSITORY,
|
||||
useClass: AdRepository,
|
||||
},
|
||||
{
|
||||
provide: PARAMS_PROVIDER,
|
||||
useClass: DefaultParamsProvider,
|
||||
},
|
||||
{
|
||||
provide: MESSAGE_BROKER_PUBLISHER,
|
||||
useClass: MessageBrokerPublisher,
|
||||
},
|
||||
{
|
||||
provide: MESSAGE_PUBLISHER,
|
||||
useClass: MessagePublisher,
|
||||
},
|
||||
{
|
||||
provide: TIMEZONE_FINDER,
|
||||
useClass: TimezoneFinder,
|
||||
},
|
||||
{
|
||||
provide: TIME_CONVERTER,
|
||||
useClass: TimeConverter,
|
||||
},
|
||||
...eventHandlers,
|
||||
...commandHandlers,
|
||||
...queryHandlers,
|
||||
...mappers,
|
||||
...repositories,
|
||||
...messageBrokers,
|
||||
...orms,
|
||||
...utilities,
|
||||
],
|
||||
exports: [
|
||||
PrismaService,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { Module, Provider } from '@nestjs/common';
|
||||
import { HealthHttpController } from './interface/http-controllers/health.http.controller';
|
||||
import { TerminusModule } from '@nestjs/terminus';
|
||||
import { MESSAGE_BROKER_PUBLISHER, MESSAGE_PUBLISHER } from 'src/app.constants';
|
||||
|
@ -10,23 +10,33 @@ import { AD_REPOSITORY } from './health.di-tokens';
|
|||
import { HealthGrpcController } from './interface/grpc-controllers/health.grpc.controller';
|
||||
import { AdModule } from '@modules/ad/ad.module';
|
||||
|
||||
const grpcControllers = [HealthGrpcController];
|
||||
|
||||
const httpControllers = [HealthHttpController];
|
||||
|
||||
const useCases: Provider[] = [RepositoriesHealthIndicatorUseCase];
|
||||
|
||||
const repositories: Provider[] = [
|
||||
{
|
||||
provide: AD_REPOSITORY,
|
||||
useClass: AdRepository,
|
||||
},
|
||||
];
|
||||
|
||||
const messageBrokers: Provider[] = [
|
||||
{
|
||||
provide: MESSAGE_BROKER_PUBLISHER,
|
||||
useClass: MessageBrokerPublisher,
|
||||
},
|
||||
{
|
||||
provide: MESSAGE_PUBLISHER,
|
||||
useClass: MessagePublisher,
|
||||
},
|
||||
];
|
||||
|
||||
@Module({
|
||||
imports: [TerminusModule, AdModule],
|
||||
controllers: [HealthGrpcController, HealthHttpController],
|
||||
providers: [
|
||||
RepositoriesHealthIndicatorUseCase,
|
||||
{
|
||||
provide: AD_REPOSITORY,
|
||||
useClass: AdRepository,
|
||||
},
|
||||
{
|
||||
provide: MESSAGE_BROKER_PUBLISHER,
|
||||
useClass: MessageBrokerPublisher,
|
||||
},
|
||||
{
|
||||
provide: MESSAGE_PUBLISHER,
|
||||
useClass: MessagePublisher,
|
||||
},
|
||||
],
|
||||
controllers: [...grpcControllers, ...httpControllers],
|
||||
providers: [...useCases, ...repositories, ...messageBrokers],
|
||||
})
|
||||
export class HealthModule {}
|
||||
|
|
Loading…
Reference in New Issue