Merge pull request #236 from SyncrowIOT:bugfix/fix-space-update

fix space
This commit is contained in:
hannathkadher
2025-02-02 23:16:01 +04:00
committed by GitHub
2 changed files with 15 additions and 6 deletions

View File

@ -212,6 +212,7 @@ export class SpaceService {
{ subspaceTagsDisabled: false }, { subspaceTagsDisabled: false },
) )
.leftJoinAndSelect('subspaceTags.product', 'subspaceTagProduct') .leftJoinAndSelect('subspaceTags.product', 'subspaceTagProduct')
.leftJoinAndSelect('space.spaceModel', 'spaceModel')
.where('space.community_id = :communityUuid', { communityUuid }) .where('space.community_id = :communityUuid', { communityUuid })
.andWhere('space.spaceName != :orphanSpaceName', { .andWhere('space.spaceName != :orphanSpaceName', {
orphanSpaceName: ORPHAN_SPACE_NAME, orphanSpaceName: ORPHAN_SPACE_NAME,
@ -286,6 +287,7 @@ export class SpaceService {
.andWhere('space.spaceName != :orphanSpaceName', { .andWhere('space.spaceName != :orphanSpaceName', {
orphanSpaceName: ORPHAN_SPACE_NAME, orphanSpaceName: ORPHAN_SPACE_NAME,
}) })
.andWhere('space.uuid = :spaceUuid', { spaceUuid })
.andWhere('space.disabled = :disabled', { disabled: false }); .andWhere('space.disabled = :disabled', { disabled: false });
const space = await queryBuilder.getOne(); const space = await queryBuilder.getOne();
@ -362,7 +364,7 @@ export class SpaceService {
updateSpaceDto: UpdateSpaceDto, updateSpaceDto: UpdateSpaceDto,
): Promise<BaseResponseDto> { ): Promise<BaseResponseDto> {
const { communityUuid, spaceUuid, projectUuid } = params; const { communityUuid, spaceUuid, projectUuid } = params;
const queryRunner = this.dataSource.createQueryRunner(); const queryRunner = this.dataSource.createQueryRunner();
try { try {
@ -584,7 +586,11 @@ export class SpaceService {
addSpaceDto: AddSpaceDto, addSpaceDto: AddSpaceDto,
spaceModelUuid?: string, 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( throw new HttpException(
'For space creation choose either space model or products and subspace', 'For space creation choose either space model or products and subspace',
HttpStatus.CONFLICT, HttpStatus.CONFLICT,

View File

@ -387,6 +387,7 @@ export class SubSpaceService {
const createTagDtos: CreateTagDto[] = const createTagDtos: CreateTagDto[] =
subspace.tags?.map((tag) => ({ subspace.tags?.map((tag) => ({
tag: tag.tag as string, tag: tag.tag as string,
uuid: tag.uuid,
productUuid: tag.productUuid as string, productUuid: tag.productUuid as string,
})) || []; })) || [];
const subSpace = await this.createSubspacesFromDto( const subSpace = await this.createSubspacesFromDto(
@ -441,15 +442,17 @@ export class SubSpaceService {
); );
if (subspace.tags?.length) { if (subspace.tags?.length) {
const modifyTagDtos = subspace.tags.map((tag) => ({ const modifyTagDtos: CreateTagDto[] = subspace.tags.map((tag) => ({
uuid: tag.uuid, 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, modifyTagDtos,
queryRunner, queryRunner,
subspace.space,
null, null,
subspace,
); );
} }