diff --git a/src/space/dtos/update.space.dto.ts b/src/space/dtos/update.space.dto.ts index 93ff377..0491aa1 100644 --- a/src/space/dtos/update.space.dto.ts +++ b/src/space/dtos/update.space.dto.ts @@ -2,6 +2,7 @@ import { ORPHAN_SPACE_NAME } from '@app/common/constants/orphan-constant'; import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; import { Type } from 'class-transformer'; import { + ArrayUnique, IsArray, IsNumber, IsOptional, @@ -49,6 +50,20 @@ export class UpdateSpaceDto { description: 'List of subspace modifications', type: [UpdateSubspaceDto], }) + @ArrayUnique((subspace) => subspace.subspaceName, { + message(validationArguments) { + const subspaces = validationArguments.value; + const nameCounts = subspaces.reduce((acc, curr) => { + acc[curr.subspaceName] = (acc[curr.subspaceName] || 0) + 1; + return acc; + }, {}); + // Find duplicates + const duplicates = Object.keys(nameCounts).filter( + (name) => nameCounts[name] > 1, + ); + return `Duplicate subspace names found: ${duplicates.join(', ')}`; + }, + }) @IsOptional() @IsArray() @ValidateNested({ each: true }) diff --git a/src/space/services/space.service.ts b/src/space/services/space.service.ts index a4e3af7..f0ea822 100644 --- a/src/space/services/space.service.ts +++ b/src/space/services/space.service.ts @@ -426,7 +426,7 @@ export class SpaceService { } } - async disableSpace(space: SpaceEntity, orphanSpace: SpaceEntity) { + private async disableSpace(space: SpaceEntity, orphanSpace: SpaceEntity) { await this.commandBus.execute( new DisableSpaceCommand({ spaceUuid: space.uuid, orphanSpace }), ); diff --git a/src/space/services/subspace/subspace-product-allocation.service.ts b/src/space/services/subspace/subspace-product-allocation.service.ts index a74823c..4ba7c9c 100644 --- a/src/space/services/subspace/subspace-product-allocation.service.ts +++ b/src/space/services/subspace/subspace-product-allocation.service.ts @@ -23,7 +23,7 @@ export class SubspaceProductAllocationService { // spaceAllocationsToExclude?: SpaceProductAllocationEntity[], ): Promise { try { - if (!allocationsData.length) return; + if (!allocationsData?.length) return; const allocations: SubspaceProductAllocationEntity[] = []; @@ -112,7 +112,7 @@ export class SubspaceProductAllocationService { ); // Create the product-tag mapping based on the processed tags - const productTagMapping = subspace.productAllocations.map( + const productTagMapping = subspace.productAllocations?.map( ({ tagUuid, tagName, productUuid }) => { const inputTag = tagUuid ? createdTagsByUUID.get(tagUuid) diff --git a/src/space/services/subspace/subspace.service.ts b/src/space/services/subspace/subspace.service.ts index d1bf83f..15bda14 100644 --- a/src/space/services/subspace/subspace.service.ts +++ b/src/space/services/subspace/subspace.service.ts @@ -39,7 +39,7 @@ export class SubSpaceService { private readonly subspaceProductAllocationService: SubspaceProductAllocationService, ) {} - async createSubspaces( + private async createSubspaces( subspaceData: Array<{ subspaceName: string; space: SpaceEntity;