mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 11:24:54 +00:00
fix the issue in unliking
This commit is contained in:
@ -14,7 +14,6 @@ import { ModifyAction } from '@app/common/constants/modify-action.enum';
|
|||||||
import { NewTagEntity } from '@app/common/modules/tag';
|
import { NewTagEntity } from '@app/common/modules/tag';
|
||||||
import { ProductEntity } from '@app/common/modules/product/entities';
|
import { ProductEntity } from '@app/common/modules/product/entities';
|
||||||
import { SpaceRepository } from '@app/common/modules/space';
|
import { SpaceRepository } from '@app/common/modules/space';
|
||||||
import { SpaceEntity } from '@app/common/modules/space/entities/space.entity';
|
|
||||||
import { ProjectEntity } from '@app/common/modules/project/entities';
|
import { ProjectEntity } from '@app/common/modules/project/entities';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@ -31,7 +30,6 @@ export class SpaceModelProductAllocationService {
|
|||||||
tags: ProcessTagDto[],
|
tags: ProcessTagDto[],
|
||||||
queryRunner?: QueryRunner,
|
queryRunner?: QueryRunner,
|
||||||
modifySubspaceModels?: ModifySubspaceModelDto[],
|
modifySubspaceModels?: ModifySubspaceModelDto[],
|
||||||
spaces?: SpaceEntity[],
|
|
||||||
): Promise<SpaceModelProductAllocationEntity[]> {
|
): Promise<SpaceModelProductAllocationEntity[]> {
|
||||||
try {
|
try {
|
||||||
if (!tags.length) return [];
|
if (!tags.length) return [];
|
||||||
@ -133,7 +131,6 @@ export class SpaceModelProductAllocationService {
|
|||||||
spaceModel: SpaceModelEntity,
|
spaceModel: SpaceModelEntity,
|
||||||
queryRunner: QueryRunner,
|
queryRunner: QueryRunner,
|
||||||
modifySubspaceModels?: ModifySubspaceModelDto[],
|
modifySubspaceModels?: ModifySubspaceModelDto[],
|
||||||
spaces?: SpaceEntity[],
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const addDtos = dtos.filter((dto) => dto.action === ModifyAction.ADD);
|
const addDtos = dtos.filter((dto) => dto.action === ModifyAction.ADD);
|
||||||
@ -184,15 +181,8 @@ export class SpaceModelProductAllocationService {
|
|||||||
spaceModel,
|
spaceModel,
|
||||||
queryRunner,
|
queryRunner,
|
||||||
modifySubspaceModels,
|
modifySubspaceModels,
|
||||||
spaces,
|
|
||||||
),
|
|
||||||
this.processDeleteActions(
|
|
||||||
filteredDtos,
|
|
||||||
queryRunner,
|
|
||||||
spaceModel,
|
|
||||||
project,
|
|
||||||
spaces,
|
|
||||||
),
|
),
|
||||||
|
this.processDeleteActions(filteredDtos, queryRunner, spaceModel),
|
||||||
]);
|
]);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw this.handleError(error, 'Error while updating product allocations');
|
throw this.handleError(error, 'Error while updating product allocations');
|
||||||
@ -205,7 +195,6 @@ export class SpaceModelProductAllocationService {
|
|||||||
spaceModel: SpaceModelEntity,
|
spaceModel: SpaceModelEntity,
|
||||||
queryRunner: QueryRunner,
|
queryRunner: QueryRunner,
|
||||||
modifySubspaceModels?: ModifySubspaceModelDto[],
|
modifySubspaceModels?: ModifySubspaceModelDto[],
|
||||||
spaces?: SpaceEntity[],
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const addDtos: ProcessTagDto[] = dtos
|
const addDtos: ProcessTagDto[] = dtos
|
||||||
.filter((dto) => dto.action === ModifyAction.ADD)
|
.filter((dto) => dto.action === ModifyAction.ADD)
|
||||||
@ -222,7 +211,6 @@ export class SpaceModelProductAllocationService {
|
|||||||
addDtos,
|
addDtos,
|
||||||
queryRunner,
|
queryRunner,
|
||||||
modifySubspaceModels,
|
modifySubspaceModels,
|
||||||
spaces,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -304,8 +292,6 @@ export class SpaceModelProductAllocationService {
|
|||||||
dtos: ModifyTagModelDto[],
|
dtos: ModifyTagModelDto[],
|
||||||
queryRunner: QueryRunner,
|
queryRunner: QueryRunner,
|
||||||
spaceModel: SpaceModelEntity,
|
spaceModel: SpaceModelEntity,
|
||||||
project: ProjectEntity,
|
|
||||||
spaces?: SpaceEntity[],
|
|
||||||
): Promise<SpaceModelProductAllocationEntity[]> {
|
): Promise<SpaceModelProductAllocationEntity[]> {
|
||||||
try {
|
try {
|
||||||
if (!dtos || dtos.length === 0) {
|
if (!dtos || dtos.length === 0) {
|
||||||
|
|||||||
@ -190,6 +190,8 @@ export class SpaceProductAllocationService {
|
|||||||
queryRunner: QueryRunner,
|
queryRunner: QueryRunner,
|
||||||
modifySubspace?: ModifySubspaceDto[],
|
modifySubspace?: ModifySubspaceDto[],
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
if (!dtos || dtos.length === 0) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
this.processAddActions(
|
this.processAddActions(
|
||||||
@ -343,10 +345,7 @@ export class SpaceProductAllocationService {
|
|||||||
space: SpaceEntity,
|
space: SpaceEntity,
|
||||||
): Promise<SpaceProductAllocationEntity[]> {
|
): Promise<SpaceProductAllocationEntity[]> {
|
||||||
try {
|
try {
|
||||||
if (!dtos || dtos.length === 0) {
|
if (!dtos || dtos.length === 0) return;
|
||||||
throw new Error('No DTOs provided for deletion.');
|
|
||||||
}
|
|
||||||
|
|
||||||
const tagUuidsToDelete = dtos
|
const tagUuidsToDelete = dtos
|
||||||
.filter((dto) => dto.action === ModifyAction.DELETE && dto.tagUuid)
|
.filter((dto) => dto.action === ModifyAction.DELETE && dto.tagUuid)
|
||||||
.map((dto) => dto.tagUuid);
|
.map((dto) => dto.tagUuid);
|
||||||
|
|||||||
@ -133,6 +133,7 @@ export class ValidationService {
|
|||||||
'subspaces.productAllocations.product',
|
'subspaces.productAllocations.product',
|
||||||
'subspaces.tags',
|
'subspaces.tags',
|
||||||
'subspaces.devices',
|
'subspaces.devices',
|
||||||
|
'spaceModel',
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -449,6 +449,11 @@ export class SpaceService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (space.spaceModel && !updateSpaceDto.spaceModelUuid) {
|
||||||
|
space.spaceModel = null;
|
||||||
|
await this.unlinkSpaceFromModel(space, queryRunner);
|
||||||
|
}
|
||||||
|
|
||||||
this.updateSpaceProperties(space, updateSpaceDto);
|
this.updateSpaceProperties(space, updateSpaceDto);
|
||||||
|
|
||||||
if (updateSpaceDto.spaceModelUuid) {
|
if (updateSpaceDto.spaceModelUuid) {
|
||||||
@ -535,15 +540,6 @@ export class SpaceService {
|
|||||||
queryRunner: QueryRunner,
|
queryRunner: QueryRunner,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await queryRunner.manager.update(
|
|
||||||
this.spaceRepository.target,
|
|
||||||
{ uuid: space.uuid },
|
|
||||||
{
|
|
||||||
spaceModel: null,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
// Unlink subspaces and tags if they exist
|
|
||||||
if (space.subspaces || space.tags) {
|
if (space.subspaces || space.tags) {
|
||||||
if (space.tags) {
|
if (space.tags) {
|
||||||
await this.spaceProductAllocationService.unlinkModels(
|
await this.spaceProductAllocationService.unlinkModels(
|
||||||
|
|||||||
Reference in New Issue
Block a user