diff --git a/src/app.module.ts b/src/app.module.ts index 69bca0e..8236fec 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -5,6 +5,7 @@ import { ConfigModule } from '@nestjs/config'; import { ConfigurationModule } from './modules/configuration/configuration.module'; import { HealthModule } from './modules/health/health.module'; import { MatcherModule } from './modules/matcher/matcher.module'; +import { AdModule } from './modules/ad/ad.modules'; @Module({ imports: [ @@ -13,6 +14,7 @@ import { MatcherModule } from './modules/matcher/matcher.module'; ConfigurationModule, HealthModule, MatcherModule, + AdModule, ], controllers: [], providers: [], diff --git a/src/modules/ad/ad.modules.ts b/src/modules/ad/ad.modules.ts new file mode 100644 index 0000000..bb8b761 --- /dev/null +++ b/src/modules/ad/ad.modules.ts @@ -0,0 +1,34 @@ +import { RabbitMQModule } from '@golevelup/nestjs-rabbitmq'; +import { Module } from '@nestjs/common'; +import { ConfigModule, ConfigService } from '@nestjs/config'; +import { AdMessagerController } from './adapters/primaries/ad-messager.controller'; + +@Module({ + imports: [ + RabbitMQModule.forRootAsync(RabbitMQModule, { + imports: [ConfigModule], + useFactory: async (configService: ConfigService) => ({ + exchanges: [ + { + name: configService.get('RMQ_EXCHANGE'), + type: 'topic', + }, + ], + handlers: { + adCreated: { + exchange: configService.get('RMQ_EXCHANGE'), + routingKey: 'ad.created', + }, + }, + uri: configService.get('RMQ_URI'), + connectionInitOptions: { wait: true }, + enableControllerDiscovery: true, + }), + inject: [ConfigService], + }), + ], + controllers: [AdMessagerController], + providers: [], + exports: [], +}) +export class AdModule {} diff --git a/src/modules/ad/adapters/primaries/ad-messager.controller.ts b/src/modules/ad/adapters/primaries/ad-messager.controller.ts new file mode 100644 index 0000000..6d8e1ab --- /dev/null +++ b/src/modules/ad/adapters/primaries/ad-messager.controller.ts @@ -0,0 +1,19 @@ +import { RabbitSubscribe } from '@golevelup/nestjs-rabbitmq'; +import { Controller } from '@nestjs/common'; +// import { Ad } from '../../domain/entities/ad'; + +@Controller() +export class AdMessagerController { + @RabbitSubscribe({ + name: 'adCreated', + }) + public adCreatedHandler(message: string) { + console.log(JSON.parse(message)); + // try { + // const createdAd: Ad = JSON.parse(message); + // console.log(createdAd); + // } catch (e) { + // console.log('error', e); + // } + } +} diff --git a/src/modules/ad/domain/entities/ad.ts b/src/modules/ad/domain/entities/ad.ts new file mode 100644 index 0000000..b4725ad --- /dev/null +++ b/src/modules/ad/domain/entities/ad.ts @@ -0,0 +1,41 @@ +import { AutoMap } from '@automapper/classes'; + +export class Ad { + @AutoMap() + uuid: string; + + driver: boolean; + passenger: boolean; + frequency: number; + fromDate: string; + toDate: string; + monTime: string; + tueTime: string; + wedTime: string; + thuTime: string; + friTime: string; + satTime: string; + sunTime: string; + monMargin: number; + tueMargin: number; + wedMargin: number; + thuMargin: number; + friMargin: number; + satMargin: number; + sunMargin: number; + driverDuration: number; + driverDistance: number; + passengerDuration: number; + passengerDistance: number; + originType: number; + destinationType: number; + waypoints: []; + direction: string; + fwdAzimuth: number; + backAzimuth: number; + seatsDriver: number; + seatsPassenger: number; + seatsUsed: number; + createdAt: string; + updatedAt: string; +}