mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 20:54:53 +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;
|
||||
}
|
||||
|
||||
class ProductAssignmentDto {
|
||||
export class CreateSubspaceDto {
|
||||
@ApiProperty({
|
||||
description: 'Name of the subspace',
|
||||
example: 'Living Room',
|
||||
})
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
subspaceName: string;
|
||||
}
|
||||
|
||||
export class ProductAssignmentDto {
|
||||
@ApiProperty({
|
||||
description: 'UUID of the product to be assigned',
|
||||
example: 'prod-uuid-1234',
|
||||
@ -114,6 +124,16 @@ export class AddSpaceDto {
|
||||
@IsOptional()
|
||||
@Type(() => 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 {
|
||||
|
||||
@ -9,6 +9,7 @@ import {
|
||||
AddSpaceDto,
|
||||
CommunitySpaceParam,
|
||||
GetSpaceParam,
|
||||
ProductAssignmentDto,
|
||||
UpdateSpaceDto,
|
||||
} from '../dtos';
|
||||
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 { SpaceProductService } from './space-products';
|
||||
import { ProjectRepository } from '@app/common/modules/project/repositiories';
|
||||
import { CreateSubspaceModelDto } from 'src/space-model/dtos';
|
||||
|
||||
@Injectable()
|
||||
export class SpaceService {
|
||||
@ -34,11 +36,14 @@ export class SpaceService {
|
||||
addSpaceDto: AddSpaceDto,
|
||||
params: CommunitySpaceParam,
|
||||
): Promise<BaseResponseDto> {
|
||||
const { parentUuid, direction, products } = addSpaceDto;
|
||||
const { parentUuid, direction, products, spaceModelUuid, subspaces } =
|
||||
addSpaceDto;
|
||||
const { communityUuid, projectUuid } = params;
|
||||
|
||||
await this.validateProject(projectUuid);
|
||||
|
||||
this.validateSpaceCreation(spaceModelUuid, products, subspaces);
|
||||
|
||||
const community = await this.validateCommunity(communityUuid);
|
||||
|
||||
const parent = parentUuid ? await this.validateSpace(parentUuid) : null;
|
||||
@ -344,4 +349,17 @@ export class SpaceService {
|
||||
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