propagate configuration

This commit is contained in:
Gsk54 2023-01-27 10:42:23 +01:00
parent f114834588
commit 9493781484
2 changed files with 29 additions and 7 deletions

View File

@ -6,6 +6,7 @@ import { DeleteConfigurationCommand } from '../../commands/delete-configuration.
import { SetConfigurationCommand } from '../../commands/set-configuration.command'; import { SetConfigurationCommand } from '../../commands/set-configuration.command';
import { DeleteConfigurationRequest } from '../../domain/dtos/delete-configuration.request'; import { DeleteConfigurationRequest } from '../../domain/dtos/delete-configuration.request';
import { SetConfigurationRequest } from '../../domain/dtos/set-configuration.request'; import { SetConfigurationRequest } from '../../domain/dtos/set-configuration.request';
import { Configuration } from '../../domain/entities/configuration';
@Controller() @Controller()
export class ConfigurationMessagerController { export class ConfigurationMessagerController {
@ -17,10 +18,10 @@ export class ConfigurationMessagerController {
@RabbitSubscribe({ @RabbitSubscribe({
exchange: 'configuration', exchange: 'configuration',
routingKey: ['create', 'update'], routingKey: ['create', 'update'],
queue: 'configuration-update', queue: 'user-configuration-update',
}) })
public async setConfigurationHandler(message: string) { public async setConfigurationHandler(message: string) {
const configuration = JSON.parse(message); const configuration: Configuration = JSON.parse(message);
if ( if (
configuration.domain == configuration.domain ==
this._configService.get<string>('SERVICE_CONFIGURATION_DOMAIN') this._configService.get<string>('SERVICE_CONFIGURATION_DOMAIN')
@ -39,10 +40,10 @@ export class ConfigurationMessagerController {
@RabbitSubscribe({ @RabbitSubscribe({
exchange: 'configuration', exchange: 'configuration',
routingKey: 'delete', routingKey: 'delete',
queue: 'configuration-delete', queue: 'user-configuration-delete',
}) })
public async configurationDeletedHandler(message: string) { public async configurationDeletedHandler(message: string) {
const deletedConfiguration = JSON.parse(message); const deletedConfiguration: Configuration = JSON.parse(message);
if ( if (
deletedConfiguration.domain == deletedConfiguration.domain ==
this._configService.get<string>('SERVICE_CONFIGURATION_DOMAIN') this._configService.get<string>('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<Configuration> = JSON.parse(message);
configurations.forEach(async (configuration) => {
if (
configuration.domain ==
this._configService.get<string>('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),
);
}
});
}
} }

View File

@ -1,9 +1,6 @@
import { AutoMap } from '@automapper/classes'; import { AutoMap } from '@automapper/classes';
export class Configuration { export class Configuration {
@AutoMap()
uuid: string;
@AutoMap() @AutoMap()
domain: string; domain: string;