mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 07:07:21 +00:00
fix: add unique validation on subspaces in update space dto (#460)
This commit is contained in:
@ -2,6 +2,7 @@ import { ORPHAN_SPACE_NAME } from '@app/common/constants/orphan-constant';
|
|||||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||||
import { Type } from 'class-transformer';
|
import { Type } from 'class-transformer';
|
||||||
import {
|
import {
|
||||||
|
ArrayUnique,
|
||||||
IsArray,
|
IsArray,
|
||||||
IsNumber,
|
IsNumber,
|
||||||
IsOptional,
|
IsOptional,
|
||||||
@ -49,6 +50,20 @@ export class UpdateSpaceDto {
|
|||||||
description: 'List of subspace modifications',
|
description: 'List of subspace modifications',
|
||||||
type: [UpdateSubspaceDto],
|
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()
|
@IsOptional()
|
||||||
@IsArray()
|
@IsArray()
|
||||||
@ValidateNested({ each: true })
|
@ValidateNested({ each: true })
|
||||||
|
@ -426,7 +426,7 @@ export class SpaceService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async disableSpace(space: SpaceEntity, orphanSpace: SpaceEntity) {
|
private async disableSpace(space: SpaceEntity, orphanSpace: SpaceEntity) {
|
||||||
await this.commandBus.execute(
|
await this.commandBus.execute(
|
||||||
new DisableSpaceCommand({ spaceUuid: space.uuid, orphanSpace }),
|
new DisableSpaceCommand({ spaceUuid: space.uuid, orphanSpace }),
|
||||||
);
|
);
|
||||||
|
@ -23,7 +23,7 @@ export class SubspaceProductAllocationService {
|
|||||||
// spaceAllocationsToExclude?: SpaceProductAllocationEntity[],
|
// spaceAllocationsToExclude?: SpaceProductAllocationEntity[],
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
try {
|
try {
|
||||||
if (!allocationsData.length) return;
|
if (!allocationsData?.length) return;
|
||||||
|
|
||||||
const allocations: SubspaceProductAllocationEntity[] = [];
|
const allocations: SubspaceProductAllocationEntity[] = [];
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ export class SubspaceProductAllocationService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Create the product-tag mapping based on the processed tags
|
// Create the product-tag mapping based on the processed tags
|
||||||
const productTagMapping = subspace.productAllocations.map(
|
const productTagMapping = subspace.productAllocations?.map(
|
||||||
({ tagUuid, tagName, productUuid }) => {
|
({ tagUuid, tagName, productUuid }) => {
|
||||||
const inputTag = tagUuid
|
const inputTag = tagUuid
|
||||||
? createdTagsByUUID.get(tagUuid)
|
? createdTagsByUUID.get(tagUuid)
|
||||||
|
@ -39,7 +39,7 @@ export class SubSpaceService {
|
|||||||
private readonly subspaceProductAllocationService: SubspaceProductAllocationService,
|
private readonly subspaceProductAllocationService: SubspaceProductAllocationService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async createSubspaces(
|
private async createSubspaces(
|
||||||
subspaceData: Array<{
|
subspaceData: Array<{
|
||||||
subspaceName: string;
|
subspaceName: string;
|
||||||
space: SpaceEntity;
|
space: SpaceEntity;
|
||||||
|
Reference in New Issue
Block a user