diff --git a/src/space/services/space.service.ts b/src/space/services/space.service.ts index c1e21c6..fa9c30c 100644 --- a/src/space/services/space.service.ts +++ b/src/space/services/space.service.ts @@ -212,6 +212,7 @@ export class SpaceService { { subspaceTagsDisabled: false }, ) .leftJoinAndSelect('subspaceTags.product', 'subspaceTagProduct') + .leftJoinAndSelect('space.spaceModel', 'spaceModel') .where('space.community_id = :communityUuid', { communityUuid }) .andWhere('space.spaceName != :orphanSpaceName', { orphanSpaceName: ORPHAN_SPACE_NAME, @@ -286,6 +287,7 @@ export class SpaceService { .andWhere('space.spaceName != :orphanSpaceName', { orphanSpaceName: ORPHAN_SPACE_NAME, }) + .andWhere('space.uuid = :spaceUuid', { spaceUuid }) .andWhere('space.disabled = :disabled', { disabled: false }); const space = await queryBuilder.getOne(); @@ -362,7 +364,7 @@ export class SpaceService { updateSpaceDto: UpdateSpaceDto, ): Promise { const { communityUuid, spaceUuid, projectUuid } = params; - + const queryRunner = this.dataSource.createQueryRunner(); try { @@ -584,7 +586,11 @@ export class SpaceService { addSpaceDto: AddSpaceDto, spaceModelUuid?: string, ) { - if (spaceModelUuid && (addSpaceDto.tags || addSpaceDto.subspaces)) { + const hasTagsOrSubspaces = + (addSpaceDto.tags && addSpaceDto.tags.length > 0) || + (addSpaceDto.subspaces && addSpaceDto.subspaces.length > 0); + + if (spaceModelUuid && hasTagsOrSubspaces) { throw new HttpException( 'For space creation choose either space model or products and subspace', HttpStatus.CONFLICT, diff --git a/src/space/services/subspace/subspace.service.ts b/src/space/services/subspace/subspace.service.ts index 599a282..3a27aee 100644 --- a/src/space/services/subspace/subspace.service.ts +++ b/src/space/services/subspace/subspace.service.ts @@ -387,6 +387,7 @@ export class SubSpaceService { const createTagDtos: CreateTagDto[] = subspace.tags?.map((tag) => ({ tag: tag.tag as string, + uuid: tag.uuid, productUuid: tag.productUuid as string, })) || []; const subSpace = await this.createSubspacesFromDto( @@ -441,15 +442,17 @@ export class SubSpaceService { ); if (subspace.tags?.length) { - const modifyTagDtos = subspace.tags.map((tag) => ({ + const modifyTagDtos: CreateTagDto[] = subspace.tags.map((tag) => ({ uuid: tag.uuid, - action: ModifyAction.DELETE, + action: ModifyAction.ADD, + tag: tag.tag, + productUuid: tag.product.uuid, })); - await this.tagService.modifyTags( + await this.tagService.moveTags( modifyTagDtos, queryRunner, + subspace.space, null, - subspace, ); }