Merge branch 'fixEnums' into 'main'

fix enum values

See merge request v3/services/configuration!1
This commit is contained in:
Sylvain Briat 2023-01-25 17:33:20 +00:00
commit 85a03f23d8
14 changed files with 96 additions and 31 deletions

View File

@ -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

45
package-lock.json generated
View File

@ -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",

View File

@ -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",

View File

@ -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;
}

View File

@ -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;

View File

@ -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 {}

View File

@ -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;

View File

@ -1,3 +1,3 @@
export enum Domain {
user = 'USER',
USER = 'USER',
}

View File

@ -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;

View File

@ -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',
},

View File

@ -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',
};

View File

@ -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',
},

View File

@ -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',
},

View File

@ -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',
};