removed log

This commit is contained in:
hannathkadher
2025-03-11 12:34:53 +04:00
parent 3367ca8fab
commit eb42948d8e
3 changed files with 52 additions and 36 deletions

View File

@ -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,10 +30,11 @@ 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 [];
}
const processedTags = await this.tagService.processTags( const processedTags = await this.tagService.processTags(
tags, tags,
@ -81,6 +81,7 @@ export class SpaceModelProductAllocationService {
) )
) { ) {
isTagNeeded = true; isTagNeeded = true;
break; break;
} }
} }
@ -93,7 +94,9 @@ export class SpaceModelProductAllocationService {
spaceModel, spaceModel,
); );
if (hasTags) continue; if (hasTags) {
continue;
}
let allocation = existingAllocations.get(tag.product.uuid); let allocation = existingAllocations.get(tag.product.uuid);
if (!allocation) { if (!allocation) {
@ -120,9 +123,11 @@ export class SpaceModelProductAllocationService {
if (productAllocations.length > 0) { if (productAllocations.length > 0) {
await this.saveAllocations(productAllocations, queryRunner); await this.saveAllocations(productAllocations, queryRunner);
} }
return productAllocations; return productAllocations;
} catch (error) { } catch (error) {
console.error(
`[ERROR] Failed to create product allocations: ${error.message}`,
);
throw this.handleError(error, 'Failed to create product allocations'); throw this.handleError(error, 'Failed to create product allocations');
} }
} }
@ -133,7 +138,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 +188,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 +202,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 +218,6 @@ export class SpaceModelProductAllocationService {
addDtos, addDtos,
queryRunner, queryRunner,
modifySubspaceModels, modifySubspaceModels,
spaces,
); );
} }
} }
@ -298,8 +293,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) {
@ -409,7 +402,7 @@ export class SpaceModelProductAllocationService {
(allocation) => allocation.tags, (allocation) => allocation.tags,
); );
// Check if the tag is already assigned to the same product in this subspace // Check if the tag is already assigned to the same product in this space
const isDuplicateTag = existingTagsForProduct.some( const isDuplicateTag = existingTagsForProduct.some(
(existingTag) => existingTag.uuid === tag.uuid, (existingTag) => existingTag.uuid === tag.uuid,
); );

View File

@ -481,7 +481,6 @@ export class SpaceModelService {
await this.subspaceRepository.save(subspace); await this.subspaceRepository.save(subspace);
} }
const subspaceAllocations = subspaceModel.productAllocations.map( const subspaceAllocations = subspaceModel.productAllocations.map(
(modelAllocation) => (modelAllocation) =>
this.subspaceProductAllocationRepository.create({ this.subspaceProductAllocationRepository.create({

View File

@ -157,6 +157,7 @@ export class SubSpaceModelService {
deleteDtos, deleteDtos,
queryRunner, queryRunner,
spaceModel, spaceModel,
spaceTagUpdateDtos,
); );
return [ return [
createdSubspaces ?? [], createdSubspaces ?? [],
@ -182,6 +183,7 @@ export class SubSpaceModelService {
deleteDtos: ModifySubspaceModelDto[], deleteDtos: ModifySubspaceModelDto[],
queryRunner: QueryRunner, queryRunner: QueryRunner,
spaceModel: SpaceModelEntity, spaceModel: SpaceModelEntity,
spaceTagUpdateDtos?: ModifyTagModelDto[],
): Promise<ISingleSubspaceModel[]> { ): Promise<ISingleSubspaceModel[]> {
try { try {
if (!deleteDtos || deleteDtos.length === 0) { if (!deleteDtos || deleteDtos.length === 0) {
@ -208,12 +210,14 @@ export class SubSpaceModelService {
{ disabled: true }, { disabled: true },
); );
const allocationsToRemove = subspaces.flatMap( const allocationsToRemove = subspaces.flatMap((subspace) =>
(subspace) => subspace.productAllocations, (subspace.productAllocations || []).map((allocation) => ({
...allocation,
subspaceModel: subspace,
})),
); );
const relocatedAllocationsMap = new Map<string, IRelocatedAllocation[]>(); const relocatedAllocationsMap = new Map<string, IRelocatedAllocation[]>();
if (allocationsToRemove.length > 0) { if (allocationsToRemove.length > 0) {
const spaceAllocationsMap = new Map< const spaceAllocationsMap = new Map<
string, string,
@ -224,7 +228,6 @@ export class SubSpaceModelService {
const product = allocation.product; const product = allocation.product;
const tags = allocation.tags; const tags = allocation.tags;
const subspaceUuid = allocation.subspaceModel.uuid; const subspaceUuid = allocation.subspaceModel.uuid;
const spaceAllocationKey = `${spaceModel.uuid}-${product.uuid}`; const spaceAllocationKey = `${spaceModel.uuid}-${product.uuid}`;
if (!spaceAllocationsMap.has(spaceAllocationKey)) { if (!spaceAllocationsMap.has(spaceAllocationKey)) {
@ -261,9 +264,28 @@ export class SubSpaceModelService {
allocation: spaceAllocation, allocation: spaceAllocation,
}); });
spaceAllocation.tags.push(...newTags); spaceAllocation.tags.push(...newTags);
await queryRunner.manager.save(spaceAllocation); await queryRunner.manager.save(spaceAllocation);
} }
} else { } else {
let tagsToAdd = [...tags];
if (spaceTagUpdateDtos && spaceTagUpdateDtos.length > 0) {
const spaceTagDtosToAdd = spaceTagUpdateDtos.filter(
(dto) => dto.action === ModifyAction.ADD,
);
tagsToAdd = tagsToAdd.filter(
(tag) =>
!spaceTagDtosToAdd.some(
(addDto) =>
(addDto.name && addDto.name === tag.name) ||
(addDto.newTagUuid && addDto.newTagUuid === tag.uuid),
),
);
}
if (tagsToAdd.length > 0) {
const newSpaceAllocation = queryRunner.manager.create( const newSpaceAllocation = queryRunner.manager.create(
SpaceModelProductAllocationEntity, SpaceModelProductAllocationEntity,
{ {
@ -272,12 +294,14 @@ export class SubSpaceModelService {
tags: tags, tags: tags,
}, },
); );
movedToAlreadyExistingSpaceAllocations.push({ movedToAlreadyExistingSpaceAllocations.push({
allocation: newSpaceAllocation, allocation: newSpaceAllocation,
tags: tags, tags: tags,
}); });
await queryRunner.manager.save(newSpaceAllocation); await queryRunner.manager.save(newSpaceAllocation);
} }
}
if (movedToAlreadyExistingSpaceAllocations.length > 0) { if (movedToAlreadyExistingSpaceAllocations.length > 0) {
if (!relocatedAllocationsMap.has(subspaceUuid)) { if (!relocatedAllocationsMap.has(subspaceUuid)) {