From 949378148483bd8ec46d40768feb395621a21333 Mon Sep 17 00:00:00 2001 From: Gsk54 Date: Fri, 27 Jan 2023 10:42:23 +0100 Subject: [PATCH] propagate configuration --- .../configuration-messager.controller.ts | 33 ++++++++++++++++--- .../domain/entities/configuration.ts | 3 -- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/modules/configuration/adapters/primaries/configuration-messager.controller.ts b/src/modules/configuration/adapters/primaries/configuration-messager.controller.ts index 3a7cd0f..82796d2 100644 --- a/src/modules/configuration/adapters/primaries/configuration-messager.controller.ts +++ b/src/modules/configuration/adapters/primaries/configuration-messager.controller.ts @@ -6,6 +6,7 @@ import { DeleteConfigurationCommand } from '../../commands/delete-configuration. import { SetConfigurationCommand } from '../../commands/set-configuration.command'; import { DeleteConfigurationRequest } from '../../domain/dtos/delete-configuration.request'; import { SetConfigurationRequest } from '../../domain/dtos/set-configuration.request'; +import { Configuration } from '../../domain/entities/configuration'; @Controller() export class ConfigurationMessagerController { @@ -17,10 +18,10 @@ export class ConfigurationMessagerController { @RabbitSubscribe({ exchange: 'configuration', routingKey: ['create', 'update'], - queue: 'configuration-update', + queue: 'user-configuration-update', }) public async setConfigurationHandler(message: string) { - const configuration = JSON.parse(message); + const configuration: Configuration = JSON.parse(message); if ( configuration.domain == this._configService.get('SERVICE_CONFIGURATION_DOMAIN') @@ -39,10 +40,10 @@ export class ConfigurationMessagerController { @RabbitSubscribe({ exchange: 'configuration', routingKey: 'delete', - queue: 'configuration-delete', + queue: 'user-configuration-delete', }) public async configurationDeletedHandler(message: string) { - const deletedConfiguration = JSON.parse(message); + const deletedConfiguration: Configuration = JSON.parse(message); if ( deletedConfiguration.domain == this._configService.get('SERVICE_CONFIGURATION_DOMAIN') @@ -55,4 +56,28 @@ export class ConfigurationMessagerController { ); } } + + @RabbitSubscribe({ + exchange: 'configuration', + routingKey: 'propagate', + queue: 'user-configuration-propagate', + }) + public async propagateConfigurationsHandler(message: string) { + const configurations: Array = JSON.parse(message); + configurations.forEach(async (configuration) => { + if ( + configuration.domain == + this._configService.get('SERVICE_CONFIGURATION_DOMAIN') + ) { + const setConfigurationRequest: SetConfigurationRequest = + new SetConfigurationRequest(); + setConfigurationRequest.domain = configuration.domain; + setConfigurationRequest.key = configuration.key; + setConfigurationRequest.value = configuration.value; + await this._commandBus.execute( + new SetConfigurationCommand(setConfigurationRequest), + ); + } + }); + } } diff --git a/src/modules/configuration/domain/entities/configuration.ts b/src/modules/configuration/domain/entities/configuration.ts index 8d3d6c5..2008403 100644 --- a/src/modules/configuration/domain/entities/configuration.ts +++ b/src/modules/configuration/domain/entities/configuration.ts @@ -1,9 +1,6 @@ import { AutoMap } from '@automapper/classes'; export class Configuration { - @AutoMap() - uuid: string; - @AutoMap() domain: string;