diff --git a/README.md b/README.md index 416cf6c..d2c268f 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,10 @@ Each item consists in : - a **key** : the key of the configuration item (a string) - a **value** : the value of the configuration item (always a string, each service must cast the value if needed) +This service centralizes the configuration items, but theoratically each service should "push" its items toward the configuration service. + +Practically, it's the other way round as it's easier to use this configuration service as the single source of truth. This is why configuration items key and domain are immutable : services may use hardcoded domain-key pairs. Therefore, only values can be updated. + ## Available domains - **USER** : user related configuration item @@ -85,7 +89,7 @@ The app exposes the following [gRPC](https://grpc.io/) services : } ``` -- **Update** : update a configuration item +- **Update** : update a configuration item value ```json { diff --git a/src/modules/configuration/adapters/secondaries/configuration-messager.presenter.ts b/src/modules/configuration/adapters/secondaries/configuration-messager.presenter.ts new file mode 100644 index 0000000..7c6836b --- /dev/null +++ b/src/modules/configuration/adapters/secondaries/configuration-messager.presenter.ts @@ -0,0 +1,13 @@ +import { AutoMap } from '@automapper/classes'; +import { Domain } from '../../domain/dtos/domain.enum'; + +export class ConfigurationMessagerPresenter { + @AutoMap() + domain: Domain; + + @AutoMap() + key: string; + + @AutoMap() + value: string; +} diff --git a/src/modules/configuration/domain/usecases/create-configuration.usecase.ts b/src/modules/configuration/domain/usecases/create-configuration.usecase.ts index 000a463..171d33a 100644 --- a/src/modules/configuration/domain/usecases/create-configuration.usecase.ts +++ b/src/modules/configuration/domain/usecases/create-configuration.usecase.ts @@ -1,6 +1,7 @@ import { Mapper } from '@automapper/core'; import { InjectMapper } from '@automapper/nestjs'; import { CommandHandler } from '@nestjs/cqrs'; +import { ConfigurationMessagerPresenter } from '../../adapters/secondaries/configuration-messager.presenter'; import { ConfigurationMessager } from '../../adapters/secondaries/configuration.messager'; import { ConfigurationRepository } from '../../adapters/secondaries/configuration.repository'; import { LoggingMessager } from '../../adapters/secondaries/logging.messager'; @@ -28,7 +29,13 @@ export class CreateConfigurationUseCase { const configuration = await this._repository.create(entity); this._configurationMessager.publish( 'create', - JSON.stringify(configuration), + JSON.stringify( + this._mapper.map( + configuration, + Configuration, + ConfigurationMessagerPresenter, + ), + ), ); this._loggingMessager.publish( 'configuration.create.info', diff --git a/src/modules/configuration/domain/usecases/update-configuration.usecase.ts b/src/modules/configuration/domain/usecases/update-configuration.usecase.ts index 34a8d83..f217d9b 100644 --- a/src/modules/configuration/domain/usecases/update-configuration.usecase.ts +++ b/src/modules/configuration/domain/usecases/update-configuration.usecase.ts @@ -1,6 +1,7 @@ import { Mapper } from '@automapper/core'; import { InjectMapper } from '@automapper/nestjs'; import { CommandHandler } from '@nestjs/cqrs'; +import { ConfigurationMessagerPresenter } from '../../adapters/secondaries/configuration-messager.presenter'; import { ConfigurationMessager } from '../../adapters/secondaries/configuration.messager'; import { ConfigurationRepository } from '../../adapters/secondaries/configuration.repository'; import { LoggingMessager } from '../../adapters/secondaries/logging.messager'; @@ -31,7 +32,13 @@ export class UpdateConfigurationUseCase { ); this._configurationMessager.publish( 'update', - JSON.stringify(command.updateConfigurationRequest), + JSON.stringify( + this._mapper.map( + configuration, + Configuration, + ConfigurationMessagerPresenter, + ), + ), ); this._loggingMessager.publish( 'configuration.update.info', diff --git a/src/modules/configuration/mappers/configuration.profile.ts b/src/modules/configuration/mappers/configuration.profile.ts index 374b862..90c8322 100644 --- a/src/modules/configuration/mappers/configuration.profile.ts +++ b/src/modules/configuration/mappers/configuration.profile.ts @@ -2,6 +2,7 @@ import { createMap, forMember, ignore, Mapper } from '@automapper/core'; import { AutomapperProfile, InjectMapper } from '@automapper/nestjs'; import { Injectable } from '@nestjs/common'; import { ConfigurationPresenter } from '../adapters/primaries/configuration.presenter'; +import { ConfigurationMessagerPresenter } from '../adapters/secondaries/configuration-messager.presenter'; import { CreateConfigurationRequest } from '../domain/dtos/create-configuration.request'; import { UpdateConfigurationRequest } from '../domain/dtos/update-configuration.request'; import { Configuration } from '../domain/entities/configuration'; @@ -24,6 +25,8 @@ export class ConfigurationProfile extends AutomapperProfile { Configuration, forMember((dest) => dest.uuid, ignore()), ); + + createMap(mapper, Configuration, ConfigurationMessagerPresenter); }; } }