170 lines
5.0 KiB
TypeScript
170 lines
5.0 KiB
TypeScript
import { Module, Provider } from '@nestjs/common';
|
|
import { CqrsModule } from '@nestjs/cqrs';
|
|
import {
|
|
AD_MESSAGE_PUBLISHER,
|
|
AD_REPOSITORY,
|
|
AD_DIRECTION_ENCODER,
|
|
AD_ROUTE_PROVIDER,
|
|
AD_GET_BASIC_ROUTE_CONTROLLER,
|
|
TIMEZONE_FINDER,
|
|
TIME_CONVERTER,
|
|
INPUT_DATETIME_TRANSFORMER,
|
|
AD_GET_DETAILED_ROUTE_CONTROLLER,
|
|
OUTPUT_DATETIME_TRANSFORMER,
|
|
MATCHING_REPOSITORY,
|
|
AD_CONFIGURATION_REPOSITORY,
|
|
} from './ad.di-tokens';
|
|
import { MessageBrokerPublisher } from '@mobicoop/message-broker-module';
|
|
import { AdRepository } from './infrastructure/ad.repository';
|
|
import { PrismaService } from './infrastructure/prisma.service';
|
|
import { AdMapper } from './ad.mapper';
|
|
import { AdCreatedMessageHandler } from './interface/message-handlers/ad-created.message-handler';
|
|
import { PostgresDirectionEncoder } from '@modules/geography/infrastructure/postgres-direction-encoder';
|
|
import { GetBasicRouteController } from '@modules/geography/interface/controllers/get-basic-route.controller';
|
|
import { RouteProvider } from './infrastructure/route-provider';
|
|
import { GeographyModule } from '@modules/geography/geography.module';
|
|
import { CreateAdService } from './core/application/commands/create-ad/create-ad.service';
|
|
import { MatchGrpcController } from './interface/grpc-controllers/match.grpc-controller';
|
|
import { MatchQueryHandler } from './core/application/queries/match/match.query-handler';
|
|
import { TimezoneFinder } from './infrastructure/timezone-finder';
|
|
import { TimeConverter } from './infrastructure/time-converter';
|
|
import { InputDateTimeTransformer } from './infrastructure/input-datetime-transformer';
|
|
import { GetDetailedRouteController } from '@modules/geography/interface/controllers/get-detailed-route.controller';
|
|
import { MatchMapper } from './match.mapper';
|
|
import { OutputDateTimeTransformer } from './infrastructure/output-datetime-transformer';
|
|
import { MatchingRepository } from './infrastructure/matching.repository';
|
|
import { MatchingMapper } from './matching.mapper';
|
|
import { CacheModule } from '@nestjs/cache-manager';
|
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
import { redisStore } from 'cache-manager-ioredis-yet';
|
|
import {
|
|
RedisClientOptions,
|
|
RedisModule,
|
|
RedisModuleOptions,
|
|
} from '@songkeys/nestjs-redis';
|
|
import { ConfigurationRepository } from '@mobicoop/configuration-module';
|
|
|
|
const imports = [
|
|
CqrsModule,
|
|
CacheModule.registerAsync<RedisClientOptions>({
|
|
imports: [ConfigModule],
|
|
useFactory: async (configService: ConfigService) => ({
|
|
store: await redisStore({
|
|
host: configService.get<string>('REDIS_HOST'),
|
|
port: configService.get<number>('REDIS_PORT'),
|
|
password: configService.get<string>('REDIS_PASSWORD'),
|
|
ttl: configService.get('CACHE_TTL'),
|
|
}),
|
|
}),
|
|
inject: [ConfigService],
|
|
}),
|
|
RedisModule.forRootAsync({
|
|
imports: [ConfigModule],
|
|
inject: [ConfigService],
|
|
useFactory: async (
|
|
configService: ConfigService,
|
|
): Promise<RedisModuleOptions> => {
|
|
return {
|
|
config: {
|
|
host: configService.get<string>('REDIS_HOST') as string,
|
|
port: configService.get<number>('REDIS_PORT') as number,
|
|
password: configService.get<string>('REDIS_PASSWORD'),
|
|
},
|
|
};
|
|
},
|
|
}),
|
|
GeographyModule,
|
|
];
|
|
|
|
const grpcControllers = [MatchGrpcController];
|
|
|
|
const messageHandlers = [AdCreatedMessageHandler];
|
|
|
|
const commandHandlers: Provider[] = [CreateAdService];
|
|
|
|
const queryHandlers: Provider[] = [MatchQueryHandler];
|
|
|
|
const mappers: Provider[] = [AdMapper, MatchMapper, MatchingMapper];
|
|
|
|
const repositories: Provider[] = [
|
|
{
|
|
provide: AD_REPOSITORY,
|
|
useClass: AdRepository,
|
|
},
|
|
{
|
|
provide: MATCHING_REPOSITORY,
|
|
useClass: MatchingRepository,
|
|
},
|
|
{
|
|
provide: AD_CONFIGURATION_REPOSITORY,
|
|
useClass: ConfigurationRepository,
|
|
},
|
|
];
|
|
|
|
const messagePublishers: Provider[] = [
|
|
{
|
|
provide: AD_MESSAGE_PUBLISHER,
|
|
useExisting: MessageBrokerPublisher,
|
|
},
|
|
];
|
|
|
|
const orms: Provider[] = [PrismaService];
|
|
|
|
const adapters: Provider[] = [
|
|
{
|
|
provide: AD_DIRECTION_ENCODER,
|
|
useClass: PostgresDirectionEncoder,
|
|
},
|
|
{
|
|
provide: AD_ROUTE_PROVIDER,
|
|
useClass: RouteProvider,
|
|
},
|
|
{
|
|
provide: AD_GET_BASIC_ROUTE_CONTROLLER,
|
|
useClass: GetBasicRouteController,
|
|
},
|
|
{
|
|
provide: AD_GET_DETAILED_ROUTE_CONTROLLER,
|
|
useClass: GetDetailedRouteController,
|
|
},
|
|
{
|
|
provide: TIMEZONE_FINDER,
|
|
useClass: TimezoneFinder,
|
|
},
|
|
{
|
|
provide: TIME_CONVERTER,
|
|
useClass: TimeConverter,
|
|
},
|
|
{
|
|
provide: INPUT_DATETIME_TRANSFORMER,
|
|
useClass: InputDateTimeTransformer,
|
|
},
|
|
{
|
|
provide: OUTPUT_DATETIME_TRANSFORMER,
|
|
useClass: OutputDateTimeTransformer,
|
|
},
|
|
];
|
|
|
|
@Module({
|
|
imports,
|
|
controllers: [...grpcControllers],
|
|
providers: [
|
|
...messageHandlers,
|
|
...commandHandlers,
|
|
...queryHandlers,
|
|
...mappers,
|
|
...repositories,
|
|
...messagePublishers,
|
|
...orms,
|
|
...adapters,
|
|
],
|
|
exports: [
|
|
PrismaService,
|
|
AdMapper,
|
|
AD_REPOSITORY,
|
|
AD_DIRECTION_ENCODER,
|
|
AD_MESSAGE_PUBLISHER,
|
|
],
|
|
})
|
|
export class AdModule {}
|