From ebdbc6cf46416a3ab7b52495998da26f469432c4 Mon Sep 17 00:00:00 2001 From: Gsk54 Date: Wed, 25 Jan 2023 18:13:50 +0100 Subject: [PATCH 1/3] fix enum values --- .../primaries/configuration.presenter.ts | 10 ++++++++++ .../adapters/primaries/configuration.proto | 6 +----- .../configuration/configuration.module.ts | 17 +++++++++++++++-- .../domain/dtos/create-configuration.request.ts | 6 +++--- .../configuration/domain/dtos/domain.enum.ts | 2 +- .../domain/dtos/update-configuration.request.ts | 4 ++-- .../configuration.repository.spec.ts | 16 ++++++++-------- .../unit/create-configuration.usecase.spec.ts | 2 +- .../unit/delete-configuration.usecase.spec.ts | 6 +++--- .../find-all-configurations.usecase.spec.ts | 6 +++--- .../find-configuration-by-uuid.usecase.spec.ts | 2 +- 11 files changed, 48 insertions(+), 29 deletions(-) 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', }; From 27e10d812f39c96fd0800927f6e549c041ff2e24 Mon Sep 17 00:00:00 2001 From: Gsk54 Date: Wed, 25 Jan 2023 18:26:54 +0100 Subject: [PATCH 2/3] fix env ci --check --- ci/.env.ci | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/.env.ci b/ci/.env.ci index bc9fdb7..464101c 100644 --- a/ci/.env.ci +++ b/ci/.env.ci @@ -1,9 +1,9 @@ # SERVICE SERVICE_URL=0.0.0.0 -SERVICE_PORT=5001 +SERVICE_PORT=5003 # PRISMA -DATABASE_URL="postgresql://user:user@db:5432/user?schema=public" +DATABASE_URL="postgresql://configuration:configuration@db:5432/configuration?schema=public" # RABBIT MQ RMQ_URI=amqp://broker:5672 From fcc8d01457392b19c156649cdc4fd321d2f01b1a Mon Sep 17 00:00:00 2001 From: Gsk54 Date: Wed, 25 Jan 2023 18:30:25 +0100 Subject: [PATCH 3/3] add configuration service --- package-lock.json | 45 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 46 insertions(+) diff --git a/package-lock.json b/package-lock.json index 1b02548..4900698 100644 --- a/package-lock.json +++ b/package-lock.json @@ -37,6 +37,7 @@ "@types/supertest": "^2.0.11", "@typescript-eslint/eslint-plugin": "^5.0.0", "@typescript-eslint/parser": "^5.0.0", + "dotenv-cli": "^7.0.0", "eslint": "^8.0.1", "eslint-config-prettier": "^8.3.0", "eslint-plugin-prettier": "^4.0.0", @@ -3744,6 +3745,30 @@ "node": ">=12" } }, + "node_modules/dotenv-cli": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/dotenv-cli/-/dotenv-cli-7.0.0.tgz", + "integrity": "sha512-XfMzVdpdDTRnlcgvFLg3lSyiLXqFxS4tH7RbK5IxkC4XIUuxPyrGoDufkfLjy/dA28EILzEu+mros6h8aQmyGg==", + "dev": true, + "dependencies": { + "cross-spawn": "^7.0.3", + "dotenv": "^16.0.0", + "dotenv-expand": "^10.0.0", + "minimist": "^1.2.6" + }, + "bin": { + "dotenv": "cli.js" + } + }, + "node_modules/dotenv-cli/node_modules/dotenv-expand": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-10.0.0.tgz", + "integrity": "sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==", + "dev": true, + "engines": { + "node": ">=12" + } + }, "node_modules/dotenv-expand": { "version": "8.0.3", "resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-8.0.3.tgz", @@ -11492,6 +11517,26 @@ "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.1.tgz", "integrity": "sha512-1K6hR6wtk2FviQ4kEiSjFiH5rpzEVi8WW0x96aztHVMhEspNpc4DVOUTEHtEva5VThQ8IaBX1Pe4gSzpVVUsKQ==" }, + "dotenv-cli": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/dotenv-cli/-/dotenv-cli-7.0.0.tgz", + "integrity": "sha512-XfMzVdpdDTRnlcgvFLg3lSyiLXqFxS4tH7RbK5IxkC4XIUuxPyrGoDufkfLjy/dA28EILzEu+mros6h8aQmyGg==", + "dev": true, + "requires": { + "cross-spawn": "^7.0.3", + "dotenv": "^16.0.0", + "dotenv-expand": "^10.0.0", + "minimist": "^1.2.6" + }, + "dependencies": { + "dotenv-expand": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-10.0.0.tgz", + "integrity": "sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==", + "dev": true + } + } + }, "dotenv-expand": { "version": "8.0.3", "resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-8.0.3.tgz", diff --git a/package.json b/package.json index eb9fdae..53702f6 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "@types/supertest": "^2.0.11", "@typescript-eslint/eslint-plugin": "^5.0.0", "@typescript-eslint/parser": "^5.0.0", + "dotenv-cli": "^7.0.0", "eslint": "^8.0.1", "eslint-config-prettier": "^8.3.0", "eslint-plugin-prettier": "^4.0.0",