mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 22:34:54 +00:00
add validation to check both space model and products, subspaces are not created
This commit is contained in:
@ -22,7 +22,17 @@ export class CreateSpaceProductItemDto {
|
|||||||
tag: string;
|
tag: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ProductAssignmentDto {
|
export class CreateSubspaceDto {
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'Name of the subspace',
|
||||||
|
example: 'Living Room',
|
||||||
|
})
|
||||||
|
@IsNotEmpty()
|
||||||
|
@IsString()
|
||||||
|
subspaceName: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ProductAssignmentDto {
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
description: 'UUID of the product to be assigned',
|
description: 'UUID of the product to be assigned',
|
||||||
example: 'prod-uuid-1234',
|
example: 'prod-uuid-1234',
|
||||||
@ -114,6 +124,16 @@ export class AddSpaceDto {
|
|||||||
@IsOptional()
|
@IsOptional()
|
||||||
@Type(() => ProductAssignmentDto)
|
@Type(() => ProductAssignmentDto)
|
||||||
products?: ProductAssignmentDto[];
|
products?: ProductAssignmentDto[];
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'List of subspaces included in the model',
|
||||||
|
type: [CreateSubspaceDto],
|
||||||
|
})
|
||||||
|
@IsOptional()
|
||||||
|
@IsArray()
|
||||||
|
@ValidateNested({ each: true })
|
||||||
|
@Type(() => CreateSubspaceDto)
|
||||||
|
subspaces?: CreateSubspaceDto[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class AddUserSpaceDto {
|
export class AddUserSpaceDto {
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import {
|
|||||||
AddSpaceDto,
|
AddSpaceDto,
|
||||||
CommunitySpaceParam,
|
CommunitySpaceParam,
|
||||||
GetSpaceParam,
|
GetSpaceParam,
|
||||||
|
ProductAssignmentDto,
|
||||||
UpdateSpaceDto,
|
UpdateSpaceDto,
|
||||||
} from '../dtos';
|
} from '../dtos';
|
||||||
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
||||||
@ -19,6 +20,7 @@ import { generateRandomString } from '@app/common/helper/randomString';
|
|||||||
import { SpaceLinkService } from './space-link';
|
import { SpaceLinkService } from './space-link';
|
||||||
import { SpaceProductService } from './space-products';
|
import { SpaceProductService } from './space-products';
|
||||||
import { ProjectRepository } from '@app/common/modules/project/repositiories';
|
import { ProjectRepository } from '@app/common/modules/project/repositiories';
|
||||||
|
import { CreateSubspaceModelDto } from 'src/space-model/dtos';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SpaceService {
|
export class SpaceService {
|
||||||
@ -34,11 +36,14 @@ export class SpaceService {
|
|||||||
addSpaceDto: AddSpaceDto,
|
addSpaceDto: AddSpaceDto,
|
||||||
params: CommunitySpaceParam,
|
params: CommunitySpaceParam,
|
||||||
): Promise<BaseResponseDto> {
|
): Promise<BaseResponseDto> {
|
||||||
const { parentUuid, direction, products } = addSpaceDto;
|
const { parentUuid, direction, products, spaceModelUuid, subspaces } =
|
||||||
|
addSpaceDto;
|
||||||
const { communityUuid, projectUuid } = params;
|
const { communityUuid, projectUuid } = params;
|
||||||
|
|
||||||
await this.validateProject(projectUuid);
|
await this.validateProject(projectUuid);
|
||||||
|
|
||||||
|
this.validateSpaceCreation(spaceModelUuid, products, subspaces);
|
||||||
|
|
||||||
const community = await this.validateCommunity(communityUuid);
|
const community = await this.validateCommunity(communityUuid);
|
||||||
|
|
||||||
const parent = parentUuid ? await this.validateSpace(parentUuid) : null;
|
const parent = parentUuid ? await this.validateSpace(parentUuid) : null;
|
||||||
@ -344,4 +349,17 @@ export class SpaceService {
|
|||||||
HttpStatus.NOT_FOUND,
|
HttpStatus.NOT_FOUND,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private validateSpaceCreation(
|
||||||
|
spaceModelUuid?: string,
|
||||||
|
products?: ProductAssignmentDto[],
|
||||||
|
subSpaces?: CreateSubspaceModelDto[],
|
||||||
|
) {
|
||||||
|
if (spaceModelUuid && (products?.length || subSpaces?.length)) {
|
||||||
|
throw new HttpException(
|
||||||
|
'Space model cannot be assigned with products or subspaces.',
|
||||||
|
HttpStatus.CONFLICT,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user