This commit is contained in:
sbriat 2023-04-24 16:44:52 +02:00
parent 9e11f2424b
commit e07e19261e
4 changed files with 96 additions and 0 deletions

View File

@ -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: [],

View File

@ -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<string>('RMQ_EXCHANGE'),
type: 'topic',
},
],
handlers: {
adCreated: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'ad.created',
},
},
uri: configService.get<string>('RMQ_URI'),
connectionInitOptions: { wait: true },
enableControllerDiscovery: true,
}),
inject: [ConfigService],
}),
],
controllers: [AdMessagerController],
providers: [],
exports: [],
})
export class AdModule {}

View File

@ -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);
// }
}
}

View File

@ -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;
}