mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 08:54:54 +00:00
add space linking when create or update space
This commit is contained in:
@ -104,10 +104,23 @@ export class SpaceService {
|
||||
this.subSpaceService.extractTagsFromSubspace(subspaces);
|
||||
const allTags = [...tags, ...subspaceTags];
|
||||
this.validateUniqueTags(allTags);
|
||||
if (spaceModelUuid) {
|
||||
const hasDependencies = subspaces?.length > 0 || tags?.length > 0;
|
||||
if (!hasDependencies && !newSpace.spaceModel) {
|
||||
await this.spaceModelService.linkToSpace(
|
||||
newSpace,
|
||||
spaceModel,
|
||||
queryRunner,
|
||||
);
|
||||
} else if (hasDependencies) {
|
||||
throw new HttpException(
|
||||
`Space cannot be linked to a model because it has existing dependencies (subspaces or tags).`,
|
||||
HttpStatus.BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
await Promise.all([
|
||||
spaceModelUuid &&
|
||||
this.createFromModel(spaceModelUuid, queryRunner, newSpace),
|
||||
direction && parent
|
||||
? this.spaceLinkService.saveSpaceLink(
|
||||
parent.uuid,
|
||||
@ -125,9 +138,8 @@ export class SpaceService {
|
||||
projectUuid,
|
||||
)
|
||||
: Promise.resolve(),
|
||||
|
||||
tags?.length
|
||||
? this.createTags(tags, projectUuid, queryRunner, space)
|
||||
? this.createTags(tags, projectUuid, queryRunner, newSpace)
|
||||
: Promise.resolve(),
|
||||
]);
|
||||
|
||||
@ -454,6 +466,30 @@ export class SpaceService {
|
||||
|
||||
this.updateSpaceProperties(space, updateSpaceDto);
|
||||
|
||||
if (updateSpaceDto.spaceModelUuid) {
|
||||
const spaceModel = await this.validationService.validateSpaceModel(
|
||||
updateSpaceDto.spaceModelUuid,
|
||||
);
|
||||
|
||||
const hasDependencies =
|
||||
space.devices?.length > 0 ||
|
||||
space.subspaces?.length > 0 ||
|
||||
space.productAllocations?.length > 0;
|
||||
|
||||
if (!hasDependencies && !space.spaceModel) {
|
||||
await this.spaceModelService.linkToSpace(
|
||||
space,
|
||||
spaceModel,
|
||||
queryRunner,
|
||||
);
|
||||
} else if (hasDependencies) {
|
||||
throw new HttpException(
|
||||
`Space cannot be linked to a model because it has existing dependencies (devices, subspaces, or product allocations).`,
|
||||
HttpStatus.BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const hasSubspace = updateSpaceDto.subspace?.length > 0;
|
||||
const hasTags = updateSpaceDto.tags?.length > 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user