mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 02:15:21 +00:00
Compare commits
1 Commits
dev
...
fix/remove
Author | SHA1 | Date | |
---|---|---|---|
2c3b985594 |
@ -75,13 +75,6 @@ export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
||||
})
|
||||
subspaces?: SubspaceEntity[];
|
||||
|
||||
// Position columns
|
||||
@Column({ type: 'float', nullable: false, default: 0 })
|
||||
public x: number; // X coordinate for position
|
||||
|
||||
@Column({ type: 'float', nullable: false, default: 0 })
|
||||
public y: number; // Y coordinate for position
|
||||
|
||||
@OneToMany(
|
||||
() => DeviceEntity,
|
||||
(devicesSpaceEntity) => devicesSpaceEntity.spaceDevice,
|
||||
|
@ -6,7 +6,6 @@ import {
|
||||
IsArray,
|
||||
IsMongoId,
|
||||
IsNotEmpty,
|
||||
IsNumber,
|
||||
IsOptional,
|
||||
IsString,
|
||||
IsUUID,
|
||||
@ -48,14 +47,6 @@ export class AddSpaceDto {
|
||||
@IsOptional()
|
||||
public icon?: string;
|
||||
|
||||
@ApiProperty({ description: 'X position on canvas', example: 120 })
|
||||
@IsNumber()
|
||||
x: number;
|
||||
|
||||
@ApiProperty({ description: 'Y position on canvas', example: 200 })
|
||||
@IsNumber()
|
||||
y: number;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'UUID of the Space Model',
|
||||
example: 'd290f1ee-6c54-4b01-90e6-d701748f0851',
|
||||
|
@ -4,7 +4,6 @@ import { Type } from 'class-transformer';
|
||||
import {
|
||||
ArrayUnique,
|
||||
IsArray,
|
||||
IsNumber,
|
||||
IsOptional,
|
||||
IsString,
|
||||
NotEquals,
|
||||
@ -36,16 +35,6 @@ export class UpdateSpaceDto {
|
||||
@IsOptional()
|
||||
public icon?: string;
|
||||
|
||||
@ApiProperty({ description: 'X position on canvas', example: 120 })
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
x?: number;
|
||||
|
||||
@ApiProperty({ description: 'Y position on canvas', example: 200 })
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
y?: number;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
description: 'List of subspace modifications',
|
||||
type: [UpdateSubspaceDto],
|
||||
|
@ -93,6 +93,9 @@ export class SpaceService {
|
||||
parentUuid && !isRecursiveCall
|
||||
? await this.validationService.validateSpace(parentUuid)
|
||||
: null;
|
||||
if (parent) {
|
||||
await this.validateNamingConflict(addSpaceDto.spaceName, parent);
|
||||
}
|
||||
|
||||
const spaceModel = spaceModelUuid
|
||||
? await this.validationService.validateSpaceModel(spaceModelUuid)
|
||||
@ -102,8 +105,6 @@ export class SpaceService {
|
||||
// todo: find a better way to handle this instead of naming every key
|
||||
spaceName: addSpaceDto.spaceName,
|
||||
icon: addSpaceDto.icon,
|
||||
x: addSpaceDto.x,
|
||||
y: addSpaceDto.y,
|
||||
spaceModel,
|
||||
parent: isRecursiveCall
|
||||
? recursiveCallParentEntity
|
||||
@ -505,6 +506,8 @@ export class SpaceService {
|
||||
spaceUuid,
|
||||
);
|
||||
|
||||
await this.validateNamingConflict(updateSpaceDto.spaceName, space, true);
|
||||
|
||||
if (space.spaceModel && !updateSpaceDto.spaceModelUuid) {
|
||||
await queryRunner.manager.update(SpaceEntity, space.uuid, {
|
||||
spaceModel: null,
|
||||
@ -655,13 +658,11 @@ export class SpaceService {
|
||||
updateSpaceDto: UpdateSpaceDto,
|
||||
queryRunner: QueryRunner,
|
||||
): Promise<void> {
|
||||
const { spaceName, x, y, icon } = updateSpaceDto;
|
||||
const { spaceName, icon } = updateSpaceDto;
|
||||
|
||||
const updateFields: Partial<SpaceEntity> = {};
|
||||
|
||||
if (spaceName) updateFields.spaceName = spaceName;
|
||||
if (x !== undefined) updateFields.x = x;
|
||||
if (y !== undefined) updateFields.y = y;
|
||||
if (icon) updateFields.icon = icon;
|
||||
|
||||
if (Object.keys(updateFields).length > 0) {
|
||||
@ -828,4 +829,34 @@ export class SpaceService {
|
||||
queryRunner,
|
||||
);
|
||||
}
|
||||
|
||||
async validateNamingConflict(
|
||||
newSpaceName: string,
|
||||
parent: SpaceEntity,
|
||||
isUpdate: boolean = false,
|
||||
): Promise<void> {
|
||||
if (!isUpdate && parent.spaceName === newSpaceName) {
|
||||
throw new HttpException(
|
||||
`Space can't be created with the same name as its parent space`,
|
||||
HttpStatus.BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
if (parent.children?.some((child) => child.spaceName === newSpaceName)) {
|
||||
throw new HttpException(
|
||||
`Space name cannot be the same as one of its siblings/children`,
|
||||
HttpStatus.BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
if (isUpdate) {
|
||||
const sibling = await this.spaceRepository.exists({
|
||||
where: { spaceName: newSpaceName, parent: { uuid: parent.uuid } },
|
||||
});
|
||||
if (sibling) {
|
||||
throw new HttpException(
|
||||
`Space name cannot be the same as one of its siblings/children`,
|
||||
HttpStatus.BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user