diff --git a/src/modules/configuration/adapters/primaries/configuration.presenter.ts b/src/modules/configuration/adapters/primaries/configuration.presenter.ts index 6846d40..1182c65 100644 --- a/src/modules/configuration/adapters/primaries/configuration.presenter.ts +++ b/src/modules/configuration/adapters/primaries/configuration.presenter.ts @@ -1,6 +1,16 @@ import { AutoMap } from '@automapper/classes'; +import { Domain } from '../../domain/dtos/domain.enum'; export class ConfigurationPresenter { + @AutoMap() + uuid: string; + + @AutoMap() + domain: Domain; + + @AutoMap() + key: string; + @AutoMap() value: string; } diff --git a/src/modules/configuration/adapters/primaries/configuration.proto b/src/modules/configuration/adapters/primaries/configuration.proto index 0397587..99becb3 100644 --- a/src/modules/configuration/adapters/primaries/configuration.proto +++ b/src/modules/configuration/adapters/primaries/configuration.proto @@ -16,15 +16,11 @@ message ConfigurationByUuid { message Configuration { string uuid = 1; - Domain domain = 2; + string domain = 2; string key = 3; string value = 4; } -enum Domain { - user = 0; -} - message ConfigurationFilter { optional int32 page = 1; optional int32 perPage = 2; diff --git a/src/modules/configuration/configuration.module.ts b/src/modules/configuration/configuration.module.ts index ab63e64..67755e2 100644 --- a/src/modules/configuration/configuration.module.ts +++ b/src/modules/configuration/configuration.module.ts @@ -1,14 +1,27 @@ import { Module } from '@nestjs/common'; import { CqrsModule } from '@nestjs/cqrs'; import { DatabaseModule } from '../database/database.module'; -import { ConfigRepository } from '../database/src/domain/configuration.repository'; import { ConfigurationController } from './adapters/primaries/configuration.controller'; +import { ConfigurationRepository } from './adapters/secondaries/configuration.repository'; +import { CreateConfigurationUseCase } from './domain/usecases/create-configuration.usecase'; +import { DeleteConfigurationUseCase } from './domain/usecases/delete-configuration.usecase'; +import { FindAllConfigurationsUseCase } from './domain/usecases/find-all-configurations.usecase'; +import { FindConfigurationByUuidUseCase } from './domain/usecases/find-configuration-by-uuid.usecase'; +import { UpdateConfigurationUseCase } from './domain/usecases/update-configuration.usecase'; import { ConfigurationProfile } from './mappers/configuration.profile'; @Module({ imports: [DatabaseModule, CqrsModule], exports: [], controllers: [ConfigurationController], - providers: [ConfigurationProfile, ConfigRepository], + providers: [ + ConfigurationProfile, + ConfigurationRepository, + FindAllConfigurationsUseCase, + FindConfigurationByUuidUseCase, + CreateConfigurationUseCase, + UpdateConfigurationUseCase, + DeleteConfigurationUseCase, + ], }) export class ConfigurationModule {} diff --git a/src/modules/configuration/domain/dtos/create-configuration.request.ts b/src/modules/configuration/domain/dtos/create-configuration.request.ts index 0e8b416..77f358d 100644 --- a/src/modules/configuration/domain/dtos/create-configuration.request.ts +++ b/src/modules/configuration/domain/dtos/create-configuration.request.ts @@ -1,5 +1,5 @@ import { AutoMap } from '@automapper/classes'; -import { IsEmail, IsNotEmpty, IsOptional, IsString } from 'class-validator'; +import { IsEnum, IsNotEmpty, IsOptional, IsString } from 'class-validator'; import { Domain } from './domain.enum'; export class CreateConfigurationRequest { @@ -8,7 +8,7 @@ export class CreateConfigurationRequest { @AutoMap() uuid?: string; - @IsString() + @IsEnum(Domain) @IsNotEmpty() @AutoMap() domain: Domain; @@ -18,7 +18,7 @@ export class CreateConfigurationRequest { @AutoMap() key: string; - @IsEmail() + @IsString() @IsNotEmpty() @AutoMap() value: string; diff --git a/src/modules/configuration/domain/dtos/domain.enum.ts b/src/modules/configuration/domain/dtos/domain.enum.ts index 2a33fd2..9d09c7d 100644 --- a/src/modules/configuration/domain/dtos/domain.enum.ts +++ b/src/modules/configuration/domain/dtos/domain.enum.ts @@ -1,3 +1,3 @@ export enum Domain { - user = 'USER', + USER = 'USER', } diff --git a/src/modules/configuration/domain/dtos/update-configuration.request.ts b/src/modules/configuration/domain/dtos/update-configuration.request.ts index 77ec611..4eca021 100644 --- a/src/modules/configuration/domain/dtos/update-configuration.request.ts +++ b/src/modules/configuration/domain/dtos/update-configuration.request.ts @@ -1,5 +1,5 @@ import { AutoMap } from '@automapper/classes'; -import { IsNotEmpty, IsOptional, IsString } from 'class-validator'; +import { IsEnum, IsNotEmpty, IsOptional, IsString } from 'class-validator'; import { Domain } from './domain.enum'; export class UpdateConfigurationRequest { @@ -8,7 +8,7 @@ export class UpdateConfigurationRequest { @AutoMap() uuid: string; - @IsString() + @IsEnum(Domain) @IsOptional() @AutoMap() domain?: Domain; diff --git a/src/modules/configuration/tests/integration/configuration.repository.spec.ts b/src/modules/configuration/tests/integration/configuration.repository.spec.ts index 43e3f13..d6cbda0 100644 --- a/src/modules/configuration/tests/integration/configuration.repository.spec.ts +++ b/src/modules/configuration/tests/integration/configuration.repository.spec.ts @@ -14,7 +14,7 @@ describe('ConfigurationRepository', () => { for (let i = 0; i < nbToCreate; i++) { await prismaService.configuration.create({ data: { - domain: Domain.user, + domain: Domain.USER, key: `key-${i}`, value: `key-${i}`, }, @@ -70,7 +70,7 @@ describe('ConfigurationRepository', () => { it('should return a configuration', async () => { const configurationToFind = await prismaService.configuration.create({ data: { - domain: Domain.user, + domain: Domain.USER, key: 'key1', value: 'value1', }, @@ -94,14 +94,14 @@ describe('ConfigurationRepository', () => { it('should return a configuration according to its domain and key', async () => { const configurationToFind = await prismaService.configuration.create({ data: { - domain: Domain.user, + domain: Domain.USER, key: 'key1', value: 'value1', }, }); const configuration = await configurationRepository.findOne({ - domain: Domain.user, + domain: Domain.USER, key: 'key1', }); @@ -110,7 +110,7 @@ describe('ConfigurationRepository', () => { it('should return null with unknown domain and key', async () => { const configuration = await configurationRepository.findOne({ - domain: Domain.user, + domain: Domain.USER, key: 'key1', }); expect(configuration).toBeNull(); @@ -122,7 +122,7 @@ describe('ConfigurationRepository', () => { const beforeCount = await prismaService.configuration.count(); const configurationToCreate: Configuration = new Configuration(); - configurationToCreate.domain = Domain.user; + configurationToCreate.domain = Domain.USER; configurationToCreate.key = 'key1'; configurationToCreate.value = 'value1'; const configuration = await configurationRepository.create( @@ -140,7 +140,7 @@ describe('ConfigurationRepository', () => { it('should update configuration key', async () => { const configurationToUpdate = await prismaService.configuration.create({ data: { - domain: Domain.user, + domain: Domain.USER, key: 'key1', value: 'value1', }, @@ -174,7 +174,7 @@ describe('ConfigurationRepository', () => { it('should delete a configuration', async () => { const configurationToRemove = await prismaService.configuration.create({ data: { - domain: Domain.user, + domain: Domain.USER, key: 'key1', value: 'value1', }, diff --git a/src/modules/configuration/tests/unit/create-configuration.usecase.spec.ts b/src/modules/configuration/tests/unit/create-configuration.usecase.spec.ts index dc5260c..107ab34 100644 --- a/src/modules/configuration/tests/unit/create-configuration.usecase.spec.ts +++ b/src/modules/configuration/tests/unit/create-configuration.usecase.spec.ts @@ -10,7 +10,7 @@ import { CreateConfigurationUseCase } from '../../domain/usecases/create-configu import { ConfigurationProfile } from '../../mappers/configuration.profile'; const newConfigurationRequest: CreateConfigurationRequest = { - domain: Domain.user, + domain: Domain.USER, key: 'minAge', value: '16', }; 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 491b7da..eda9c97 100644 --- a/src/modules/configuration/tests/unit/delete-configuration.usecase.spec.ts +++ b/src/modules/configuration/tests/unit/delete-configuration.usecase.spec.ts @@ -7,19 +7,19 @@ import { DeleteConfigurationUseCase } from '../../domain/usecases/delete-configu const mockConfigurations = [ { uuid: 'bb281075-1b98-4456-89d6-c643d3044a91', - domain: Domain.user, + domain: Domain.USER, key: 'key1', value: 'value1', }, { uuid: 'bb281075-1b98-4456-89d6-c643d3044a92', - domain: Domain.user, + domain: Domain.USER, key: 'key2', value: 'value2', }, { uuid: 'bb281075-1b98-4456-89d6-c643d3044a93', - domain: Domain.user, + domain: Domain.USER, key: 'key3', value: 'value3', }, diff --git a/src/modules/configuration/tests/unit/find-all-configurations.usecase.spec.ts b/src/modules/configuration/tests/unit/find-all-configurations.usecase.spec.ts index ccc089d..2ddd52f 100644 --- a/src/modules/configuration/tests/unit/find-all-configurations.usecase.spec.ts +++ b/src/modules/configuration/tests/unit/find-all-configurations.usecase.spec.ts @@ -16,19 +16,19 @@ const findAllConfigurationsQuery: FindAllConfigurationsQuery = const mockConfigurations = [ { uuid: 'bb281075-1b98-4456-89d6-c643d3044a91', - domain: Domain.user, + domain: Domain.USER, key: 'key1', value: 'value1', }, { uuid: 'bb281075-1b98-4456-89d6-c643d3044a92', - domain: Domain.user, + domain: Domain.USER, key: 'key2', value: 'value2', }, { uuid: 'bb281075-1b98-4456-89d6-c643d3044a93', - domain: Domain.user, + domain: Domain.USER, key: 'key3', value: 'value3', }, diff --git a/src/modules/configuration/tests/unit/find-configuration-by-uuid.usecase.spec.ts b/src/modules/configuration/tests/unit/find-configuration-by-uuid.usecase.spec.ts index 20071a8..9d60bae 100644 --- a/src/modules/configuration/tests/unit/find-configuration-by-uuid.usecase.spec.ts +++ b/src/modules/configuration/tests/unit/find-configuration-by-uuid.usecase.spec.ts @@ -8,7 +8,7 @@ import { FindConfigurationByUuidQuery } from '../../queries/find-configuration-b const mockConfiguration = { uuid: 'bb281075-1b98-4456-89d6-c643d3044a91', - domain: Domain.user, + domain: Domain.USER, key: 'key1', value: 'value1', };