From 05ea965ce40c2ce4eabc75fd5183061b320894eb Mon Sep 17 00:00:00 2001 From: Gsk54 Date: Thu, 26 Jan 2023 16:15:45 +0100 Subject: [PATCH] map for delete --- .../domain/usecases/delete-configuration.usecase.ts | 12 +++++++++++- .../tests/unit/delete-configuration.usecase.spec.ts | 5 +++++ .../tests/unit/update-configuration.usecase.spec.ts | 1 - 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/modules/configuration/domain/usecases/delete-configuration.usecase.ts b/src/modules/configuration/domain/usecases/delete-configuration.usecase.ts index b239dce..72d3085 100644 --- a/src/modules/configuration/domain/usecases/delete-configuration.usecase.ts +++ b/src/modules/configuration/domain/usecases/delete-configuration.usecase.ts @@ -1,4 +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'; @@ -11,6 +14,7 @@ export class DeleteConfigurationUseCase { private readonly _repository: ConfigurationRepository, private readonly _configurationMessager: ConfigurationMessager, private readonly _loggingMessager: LoggingMessager, + @InjectMapper() private readonly _mapper: Mapper, ) {} async execute(command: DeleteConfigurationCommand): Promise { @@ -18,7 +22,13 @@ export class DeleteConfigurationUseCase { const configuration = await this._repository.delete(command.uuid); this._configurationMessager.publish( 'delete', - JSON.stringify({ uuid: configuration.uuid }), + JSON.stringify( + this._mapper.map( + configuration, + Configuration, + ConfigurationMessagerPresenter, + ), + ), ); this._loggingMessager.publish( 'configuration.delete.info', diff --git a/src/modules/configuration/tests/unit/delete-configuration.usecase.spec.ts b/src/modules/configuration/tests/unit/delete-configuration.usecase.spec.ts index 35503c5..072220b 100644 --- a/src/modules/configuration/tests/unit/delete-configuration.usecase.spec.ts +++ b/src/modules/configuration/tests/unit/delete-configuration.usecase.spec.ts @@ -1,3 +1,5 @@ +import { classes } from '@automapper/classes'; +import { AutomapperModule } from '@automapper/nestjs'; import { Test, TestingModule } from '@nestjs/testing'; import { ConfigurationMessager } from '../../adapters/secondaries/configuration.messager'; import { ConfigurationRepository } from '../../adapters/secondaries/configuration.repository'; @@ -5,6 +7,7 @@ import { LoggingMessager } from '../../adapters/secondaries/logging.messager'; import { DeleteConfigurationCommand } from '../../commands/delete-configuration.command'; import { Domain } from '../../domain/dtos/domain.enum'; import { DeleteConfigurationUseCase } from '../../domain/usecases/delete-configuration.usecase'; +import { ConfigurationProfile } from '../../mappers/configuration.profile'; const mockConfigurations = [ { @@ -54,12 +57,14 @@ describe('DeleteConfigurationUseCase', () => { beforeAll(async () => { const module: TestingModule = await Test.createTestingModule({ + imports: [AutomapperModule.forRoot({ strategyInitializer: classes() })], providers: [ { provide: ConfigurationRepository, useValue: mockConfigurationRepository, }, DeleteConfigurationUseCase, + ConfigurationProfile, { provide: ConfigurationMessager, useValue: mockMessager, diff --git a/src/modules/configuration/tests/unit/update-configuration.usecase.spec.ts b/src/modules/configuration/tests/unit/update-configuration.usecase.spec.ts index 093c7df..7d022f1 100644 --- a/src/modules/configuration/tests/unit/update-configuration.usecase.spec.ts +++ b/src/modules/configuration/tests/unit/update-configuration.usecase.spec.ts @@ -48,7 +48,6 @@ describe('UpdateConfigurationUseCase', () => { beforeAll(async () => { const module: TestingModule = await Test.createTestingModule({ imports: [AutomapperModule.forRoot({ strategyInitializer: classes() })], - providers: [ { provide: ConfigurationRepository,