fix enum values

This commit is contained in:
Gsk54 2023-01-25 18:13:50 +01:00
parent fd11af5ba3
commit ebdbc6cf46
11 changed files with 48 additions and 29 deletions

View File

@ -1,6 +1,16 @@
import { AutoMap } from '@automapper/classes'; import { AutoMap } from '@automapper/classes';
import { Domain } from '../../domain/dtos/domain.enum';
export class ConfigurationPresenter { export class ConfigurationPresenter {
@AutoMap()
uuid: string;
@AutoMap()
domain: Domain;
@AutoMap()
key: string;
@AutoMap() @AutoMap()
value: string; value: string;
} }

View File

@ -16,15 +16,11 @@ message ConfigurationByUuid {
message Configuration { message Configuration {
string uuid = 1; string uuid = 1;
Domain domain = 2; string domain = 2;
string key = 3; string key = 3;
string value = 4; string value = 4;
} }
enum Domain {
user = 0;
}
message ConfigurationFilter { message ConfigurationFilter {
optional int32 page = 1; optional int32 page = 1;
optional int32 perPage = 2; optional int32 perPage = 2;

View File

@ -1,14 +1,27 @@
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { CqrsModule } from '@nestjs/cqrs'; import { CqrsModule } from '@nestjs/cqrs';
import { DatabaseModule } from '../database/database.module'; import { DatabaseModule } from '../database/database.module';
import { ConfigRepository } from '../database/src/domain/configuration.repository';
import { ConfigurationController } from './adapters/primaries/configuration.controller'; 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'; import { ConfigurationProfile } from './mappers/configuration.profile';
@Module({ @Module({
imports: [DatabaseModule, CqrsModule], imports: [DatabaseModule, CqrsModule],
exports: [], exports: [],
controllers: [ConfigurationController], controllers: [ConfigurationController],
providers: [ConfigurationProfile, ConfigRepository], providers: [
ConfigurationProfile,
ConfigurationRepository,
FindAllConfigurationsUseCase,
FindConfigurationByUuidUseCase,
CreateConfigurationUseCase,
UpdateConfigurationUseCase,
DeleteConfigurationUseCase,
],
}) })
export class ConfigurationModule {} export class ConfigurationModule {}

View File

@ -1,5 +1,5 @@
import { AutoMap } from '@automapper/classes'; 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'; import { Domain } from './domain.enum';
export class CreateConfigurationRequest { export class CreateConfigurationRequest {
@ -8,7 +8,7 @@ export class CreateConfigurationRequest {
@AutoMap() @AutoMap()
uuid?: string; uuid?: string;
@IsString() @IsEnum(Domain)
@IsNotEmpty() @IsNotEmpty()
@AutoMap() @AutoMap()
domain: Domain; domain: Domain;
@ -18,7 +18,7 @@ export class CreateConfigurationRequest {
@AutoMap() @AutoMap()
key: string; key: string;
@IsEmail() @IsString()
@IsNotEmpty() @IsNotEmpty()
@AutoMap() @AutoMap()
value: string; value: string;

View File

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

View File

@ -1,5 +1,5 @@
import { AutoMap } from '@automapper/classes'; 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'; import { Domain } from './domain.enum';
export class UpdateConfigurationRequest { export class UpdateConfigurationRequest {
@ -8,7 +8,7 @@ export class UpdateConfigurationRequest {
@AutoMap() @AutoMap()
uuid: string; uuid: string;
@IsString() @IsEnum(Domain)
@IsOptional() @IsOptional()
@AutoMap() @AutoMap()
domain?: Domain; domain?: Domain;

View File

@ -14,7 +14,7 @@ describe('ConfigurationRepository', () => {
for (let i = 0; i < nbToCreate; i++) { for (let i = 0; i < nbToCreate; i++) {
await prismaService.configuration.create({ await prismaService.configuration.create({
data: { data: {
domain: Domain.user, domain: Domain.USER,
key: `key-${i}`, key: `key-${i}`,
value: `key-${i}`, value: `key-${i}`,
}, },
@ -70,7 +70,7 @@ describe('ConfigurationRepository', () => {
it('should return a configuration', async () => { it('should return a configuration', async () => {
const configurationToFind = await prismaService.configuration.create({ const configurationToFind = await prismaService.configuration.create({
data: { data: {
domain: Domain.user, domain: Domain.USER,
key: 'key1', key: 'key1',
value: 'value1', value: 'value1',
}, },
@ -94,14 +94,14 @@ describe('ConfigurationRepository', () => {
it('should return a configuration according to its domain and key', async () => { it('should return a configuration according to its domain and key', async () => {
const configurationToFind = await prismaService.configuration.create({ const configurationToFind = await prismaService.configuration.create({
data: { data: {
domain: Domain.user, domain: Domain.USER,
key: 'key1', key: 'key1',
value: 'value1', value: 'value1',
}, },
}); });
const configuration = await configurationRepository.findOne({ const configuration = await configurationRepository.findOne({
domain: Domain.user, domain: Domain.USER,
key: 'key1', key: 'key1',
}); });
@ -110,7 +110,7 @@ describe('ConfigurationRepository', () => {
it('should return null with unknown domain and key', async () => { it('should return null with unknown domain and key', async () => {
const configuration = await configurationRepository.findOne({ const configuration = await configurationRepository.findOne({
domain: Domain.user, domain: Domain.USER,
key: 'key1', key: 'key1',
}); });
expect(configuration).toBeNull(); expect(configuration).toBeNull();
@ -122,7 +122,7 @@ describe('ConfigurationRepository', () => {
const beforeCount = await prismaService.configuration.count(); const beforeCount = await prismaService.configuration.count();
const configurationToCreate: Configuration = new Configuration(); const configurationToCreate: Configuration = new Configuration();
configurationToCreate.domain = Domain.user; configurationToCreate.domain = Domain.USER;
configurationToCreate.key = 'key1'; configurationToCreate.key = 'key1';
configurationToCreate.value = 'value1'; configurationToCreate.value = 'value1';
const configuration = await configurationRepository.create( const configuration = await configurationRepository.create(
@ -140,7 +140,7 @@ describe('ConfigurationRepository', () => {
it('should update configuration key', async () => { it('should update configuration key', async () => {
const configurationToUpdate = await prismaService.configuration.create({ const configurationToUpdate = await prismaService.configuration.create({
data: { data: {
domain: Domain.user, domain: Domain.USER,
key: 'key1', key: 'key1',
value: 'value1', value: 'value1',
}, },
@ -174,7 +174,7 @@ describe('ConfigurationRepository', () => {
it('should delete a configuration', async () => { it('should delete a configuration', async () => {
const configurationToRemove = await prismaService.configuration.create({ const configurationToRemove = await prismaService.configuration.create({
data: { data: {
domain: Domain.user, domain: Domain.USER,
key: 'key1', key: 'key1',
value: 'value1', value: 'value1',
}, },

View File

@ -10,7 +10,7 @@ import { CreateConfigurationUseCase } from '../../domain/usecases/create-configu
import { ConfigurationProfile } from '../../mappers/configuration.profile'; import { ConfigurationProfile } from '../../mappers/configuration.profile';
const newConfigurationRequest: CreateConfigurationRequest = { const newConfigurationRequest: CreateConfigurationRequest = {
domain: Domain.user, domain: Domain.USER,
key: 'minAge', key: 'minAge',
value: '16', value: '16',
}; };

View File

@ -7,19 +7,19 @@ import { DeleteConfigurationUseCase } from '../../domain/usecases/delete-configu
const mockConfigurations = [ const mockConfigurations = [
{ {
uuid: 'bb281075-1b98-4456-89d6-c643d3044a91', uuid: 'bb281075-1b98-4456-89d6-c643d3044a91',
domain: Domain.user, domain: Domain.USER,
key: 'key1', key: 'key1',
value: 'value1', value: 'value1',
}, },
{ {
uuid: 'bb281075-1b98-4456-89d6-c643d3044a92', uuid: 'bb281075-1b98-4456-89d6-c643d3044a92',
domain: Domain.user, domain: Domain.USER,
key: 'key2', key: 'key2',
value: 'value2', value: 'value2',
}, },
{ {
uuid: 'bb281075-1b98-4456-89d6-c643d3044a93', uuid: 'bb281075-1b98-4456-89d6-c643d3044a93',
domain: Domain.user, domain: Domain.USER,
key: 'key3', key: 'key3',
value: 'value3', value: 'value3',
}, },

View File

@ -16,19 +16,19 @@ const findAllConfigurationsQuery: FindAllConfigurationsQuery =
const mockConfigurations = [ const mockConfigurations = [
{ {
uuid: 'bb281075-1b98-4456-89d6-c643d3044a91', uuid: 'bb281075-1b98-4456-89d6-c643d3044a91',
domain: Domain.user, domain: Domain.USER,
key: 'key1', key: 'key1',
value: 'value1', value: 'value1',
}, },
{ {
uuid: 'bb281075-1b98-4456-89d6-c643d3044a92', uuid: 'bb281075-1b98-4456-89d6-c643d3044a92',
domain: Domain.user, domain: Domain.USER,
key: 'key2', key: 'key2',
value: 'value2', value: 'value2',
}, },
{ {
uuid: 'bb281075-1b98-4456-89d6-c643d3044a93', uuid: 'bb281075-1b98-4456-89d6-c643d3044a93',
domain: Domain.user, domain: Domain.USER,
key: 'key3', key: 'key3',
value: 'value3', value: 'value3',
}, },

View File

@ -8,7 +8,7 @@ import { FindConfigurationByUuidQuery } from '../../queries/find-configuration-b
const mockConfiguration = { const mockConfiguration = {
uuid: 'bb281075-1b98-4456-89d6-c643d3044a91', uuid: 'bb281075-1b98-4456-89d6-c643d3044a91',
domain: Domain.user, domain: Domain.USER,
key: 'key1', key: 'key1',
value: 'value1', value: 'value1',
}; };