From 63f1f7a7c05c5e2720a3ab8a973dd9516c7603dc Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Sun, 9 Mar 2025 14:03:59 +0400 Subject: [PATCH 1/2] fixed get spaces --- .../space-model-product-allocation.service.ts | 13 ------------- src/space/services/space.service.ts | 3 ++- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/space-model/services/space-model-product-allocation.service.ts b/src/space-model/services/space-model-product-allocation.service.ts index d895500..d57a6af 100644 --- a/src/space-model/services/space-model-product-allocation.service.ts +++ b/src/space-model/services/space-model-product-allocation.service.ts @@ -14,7 +14,6 @@ import { ModifyAction } from '@app/common/constants/modify-action.enum'; import { NewTagEntity } from '@app/common/modules/tag'; import { ProductEntity } from '@app/common/modules/product/entities'; import { SpaceRepository } from '@app/common/modules/space'; -import { SpaceProductAllocationService } from 'src/space/services/space-product-allocation.service'; import { SpaceEntity } from '@app/common/modules/space/entities/space.entity'; @Injectable() @@ -23,7 +22,6 @@ export class SpaceModelProductAllocationService { private readonly tagService: NewTagService, private readonly spaceModelProductAllocationRepository: SpaceModelProductAllocationRepoitory, private readonly spaceRepository: SpaceRepository, - private readonly spaceProductAllocationService: SpaceProductAllocationService, ) {} async createProductAllocations( @@ -114,23 +112,12 @@ export class SpaceModelProductAllocationService { } else if (!allocation.tags.some((t) => t.uuid === tag.uuid)) { allocation.tags.push(tag); await this.saveAllocation(allocation, queryRunner); - await this.spaceProductAllocationService.addTagToAllocationFromModel( - allocation, - queryRunner, - tag, - spaces, - ); } } } if (productAllocations.length > 0) { await this.saveAllocations(productAllocations, queryRunner); - await this.spaceProductAllocationService.createAllocationFromModel( - productAllocations, - queryRunner, - spaces, - ); } return productAllocations; diff --git a/src/space/services/space.service.ts b/src/space/services/space.service.ts index 844c42f..46e584b 100644 --- a/src/space/services/space.service.ts +++ b/src/space/services/space.service.ts @@ -276,10 +276,11 @@ export class SpaceService { const spaces = await queryBuilder.getMany(); const transformedSpaces = spaces.map(this.transformSpace); + const spaceHierarchy = this.buildSpaceHierarchy(transformedSpaces); return new SuccessResponseDto({ message: `Spaces in community ${communityUuid} successfully fetched in hierarchy`, - data: onlyWithDevices ? spaces : transformedSpaces, + data: onlyWithDevices ? spaces : spaceHierarchy, statusCode: HttpStatus.OK, }); } catch (error) { From 054df46936cf5310639afda0118481b9b47ceac5 Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Sun, 9 Mar 2025 20:12:19 +0400 Subject: [PATCH 2/2] fix create space --- src/space/services/space-validation.service.ts | 8 ++++---- src/space/services/space.service.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/space/services/space-validation.service.ts b/src/space/services/space-validation.service.ts index be173b0..c9080db 100644 --- a/src/space/services/space-validation.service.ts +++ b/src/space/services/space-validation.service.ts @@ -165,10 +165,10 @@ export class ValidationService { where: { uuid: spaceModelUuid }, relations: [ 'subspaceModels', - 'subspaceModels.tags', - 'tags', - 'subspaceModels.tags.product', - 'tags.product', + 'subspaceModels.productAllocations', + 'subspaceModels.productAllocations.tags', + 'productAllocations.product', + 'productAllocations.tags', ], }); diff --git a/src/space/services/space.service.ts b/src/space/services/space.service.ts index 46e584b..73ee5ee 100644 --- a/src/space/services/space.service.ts +++ b/src/space/services/space.service.ts @@ -106,7 +106,7 @@ export class SpaceService { this.validateUniqueTags(allTags); if (spaceModelUuid) { const hasDependencies = subspaces?.length > 0 || tags?.length > 0; - if (!hasDependencies && !newSpace.spaceModel) { + if (!hasDependencies) { await this.spaceModelService.linkToSpace( newSpace, spaceModel,