mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 02:36:19 +00:00
added space model details to space
This commit is contained in:
@ -17,7 +17,7 @@ export class CreateSpaceProductModelDto {
|
||||
})
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
productId: string;
|
||||
productUuid: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Number of products in the model',
|
||||
|
@ -21,6 +21,12 @@ export class SpaceProductItemModelService {
|
||||
) {
|
||||
await this.validateTags(itemModelDtos, queryRunner, spaceModel);
|
||||
|
||||
if (!spaceProductModel) {
|
||||
throw new HttpException(
|
||||
'Space product model is required to create product items.',
|
||||
HttpStatus.BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
try {
|
||||
const productItems = itemModelDtos.map((dto) =>
|
||||
queryRunner.manager.create(this.spaceProductItemRepository.target, {
|
||||
|
@ -25,7 +25,7 @@ export class SpaceProductModelService {
|
||||
const productModels = await Promise.all(
|
||||
spaceProductModelDtos.map(async (dto) => {
|
||||
this.validateProductCount(dto);
|
||||
const product = await this.getProduct(dto.productId);
|
||||
const product = await this.getProduct(dto.productUuid);
|
||||
return queryRunner.manager.create(
|
||||
this.spaceProductModelRepository.target,
|
||||
{
|
||||
@ -40,14 +40,15 @@ export class SpaceProductModelService {
|
||||
const savedProductModels = await queryRunner.manager.save(productModels);
|
||||
|
||||
await Promise.all(
|
||||
spaceProductModelDtos.map((dto, index) =>
|
||||
this.spaceProductItemModelService.createProdutItemModel(
|
||||
spaceProductModelDtos.map((dto, index) => {
|
||||
const savedModel = savedProductModels[index];
|
||||
return this.spaceProductItemModelService.createProdutItemModel(
|
||||
dto.items,
|
||||
savedProductModels[index],
|
||||
savedModel, // Pass the saved model
|
||||
spaceModel,
|
||||
queryRunner,
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
} catch (error) {
|
||||
if (error instanceof HttpException) {
|
||||
@ -65,7 +66,7 @@ export class SpaceProductModelService {
|
||||
const productItemCount = dto.items.length;
|
||||
if (dto.productCount !== productItemCount) {
|
||||
throw new HttpException(
|
||||
`Product count (${dto.productCount}) does not match the number of items (${productItemCount}) for product ID ${dto.productId}.`,
|
||||
`Product count (${dto.productCount}) does not match the number of items (${productItemCount}) for product ID ${dto.productUuid}.`,
|
||||
HttpStatus.BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { Type } from 'class-transformer';
|
||||
import {
|
||||
ArrayNotEmpty,
|
||||
IsArray,
|
||||
IsBoolean,
|
||||
IsNotEmpty,
|
||||
@ -11,6 +12,42 @@ import {
|
||||
ValidateNested,
|
||||
} from 'class-validator';
|
||||
|
||||
export class CreateSpaceProductItemDto {
|
||||
@ApiProperty({
|
||||
description: 'Specific name for the product item',
|
||||
example: 'Light 1',
|
||||
})
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
tag: string;
|
||||
}
|
||||
|
||||
class ProductAssignmentDto {
|
||||
@ApiProperty({
|
||||
description: 'UUID of the product to be assigned',
|
||||
example: 'prod-uuid-1234',
|
||||
})
|
||||
@IsNotEmpty()
|
||||
productId: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Number of items to assign for the product',
|
||||
example: 3,
|
||||
})
|
||||
count: number;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Specific names for each product item',
|
||||
type: [CreateSpaceProductItemDto],
|
||||
example: [{ tag: 'Light 1' }, { tag: 'Light 2' }, { tag: 'Light 3' }],
|
||||
})
|
||||
@IsArray()
|
||||
@ArrayNotEmpty()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => CreateSpaceProductItemDto)
|
||||
items: CreateSpaceProductItemDto[];
|
||||
}
|
||||
|
||||
export class AddSpaceDto {
|
||||
@ApiProperty({
|
||||
description: 'Name of the space (e.g., Floor 1, Unit 101)',
|
||||
@ -29,9 +66,14 @@ export class AddSpaceDto {
|
||||
@IsOptional()
|
||||
parentUuid?: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Icon identifier for the space',
|
||||
example: 'assets/location',
|
||||
required: false,
|
||||
})
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
public icon: string;
|
||||
public icon?: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Indicates whether the space is private or public',
|
||||
@ -49,16 +91,29 @@ export class AddSpaceDto {
|
||||
@IsNumber()
|
||||
y: number;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'UUID of the Space',
|
||||
example: 'd290f1ee-6c54-4b01-90e6-d701748f0851',
|
||||
})
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
spaceModelUuid?: string;
|
||||
|
||||
@ApiProperty({ description: 'Y position on canvas', example: 200 })
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
direction: string;
|
||||
direction?: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'List of products assigned to this space',
|
||||
type: [ProductAssignmentDto],
|
||||
required: false,
|
||||
})
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@IsOptional()
|
||||
@Type(() => ProductAssignmentDto)
|
||||
products: ProductAssignmentDto[];
|
||||
products?: ProductAssignmentDto[];
|
||||
}
|
||||
|
||||
export class AddUserSpaceDto {
|
||||
@ -101,11 +156,3 @@ export class AddUserSpaceUsingCodeDto {
|
||||
Object.assign(this, dto);
|
||||
}
|
||||
}
|
||||
|
||||
class ProductAssignmentDto {
|
||||
@IsNotEmpty()
|
||||
productId: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
count: number;
|
||||
}
|
||||
|
Reference in New Issue
Block a user