From 95ecbab1653d87774e58b45b3f18a324fb29acf6 Mon Sep 17 00:00:00 2001 From: faris Aljohari <83524184+farisaljohari@users.noreply.github.com> Date: Mon, 3 Mar 2025 10:05:11 +0300 Subject: [PATCH] fix ProcessTagDto dto issues --- .../services/subspace/subspace.service.ts | 5 +-- src/space/services/tag/tag.service.ts | 37 ++++++++++--------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/space/services/subspace/subspace.service.ts b/src/space/services/subspace/subspace.service.ts index efa5f3e..8c0fc34 100644 --- a/src/space/services/subspace/subspace.service.ts +++ b/src/space/services/subspace/subspace.service.ts @@ -2,7 +2,6 @@ import { BaseResponseDto } from '@app/common/dto/base.response.dto'; import { HttpException, HttpStatus, Injectable } from '@nestjs/common'; import { AddSubspaceDto, - DeleteSubspaceDto, GetSpaceParam, GetSubSpaceParam, ModifySubspaceDto, @@ -418,7 +417,7 @@ export class SubSpaceService { ): Promise { const createTagDtos: ProcessTagDto[] = subspace.tags?.map((tag) => ({ - tag: tag.name as string, + name: tag.name as string, uuid: tag.tagUuid, productUuid: tag.productUuid as string, })) || []; @@ -477,7 +476,7 @@ export class SubSpaceService { const modifyTagDtos: ProcessTagDto[] = subspace.tags.map((tag) => ({ uuid: tag.uuid, action: ModifyAction.ADD, - tag: tag.tag, + name: tag.tag, productUuid: tag.product.uuid, })); await this.tagService.moveTags( diff --git a/src/space/services/tag/tag.service.ts b/src/space/services/tag/tag.service.ts index edf6575..323e770 100644 --- a/src/space/services/tag/tag.service.ts +++ b/src/space/services/tag/tag.service.ts @@ -6,8 +6,9 @@ import { SubspaceEntity } from '@app/common/modules/space/entities/subspace/subs import { TagEntity } from '@app/common/modules/space/entities/tag.entity'; import { HttpException, HttpStatus, Injectable } from '@nestjs/common'; import { ProductService } from 'src/product/services'; -import { CreateTagDto, ModifySubspaceDto } from 'src/space/dtos'; +import { ModifySubspaceDto } from 'src/space/dtos'; import { ModifyTagDto } from 'src/space/dtos/tag/modify-tag.dto'; +import { ProcessTagDto } from 'src/tags/dtos'; import { QueryRunner } from 'typeorm'; @Injectable() @@ -18,11 +19,11 @@ export class TagService { ) {} async createTags( - tags: CreateTagDto[], + tags: ProcessTagDto[], queryRunner: QueryRunner, space?: SpaceEntity, subspace?: SubspaceEntity, - additionalTags?: CreateTagDto[], + additionalTags?: ProcessTagDto[], tagsToDelete?: ModifyTagDto[], ): Promise { this.validateTagsInput(tags); @@ -55,7 +56,7 @@ export class TagService { } async bulkSaveTags( - tags: CreateTagDto[], + tags: ProcessTagDto[], queryRunner: QueryRunner, space?: SpaceEntity, subspace?: SubspaceEntity, @@ -92,7 +93,7 @@ export class TagService { } async moveTags( - tags: CreateTagDto[], + tags: ProcessTagDto[], queryRunner: QueryRunner, space?: SpaceEntity, subspace?: SubspaceEntity, @@ -297,7 +298,7 @@ export class TagService { await this.createTags( [ { - tag: tag.name, + name: tag.name, productUuid: tag.productUuid, uuid: tag.tagUuid, }, @@ -342,14 +343,14 @@ export class TagService { } } - private findDuplicateTags(tags: CreateTagDto[]): string[] { + private findDuplicateTags(tags: ProcessTagDto[]): string[] { const seen = new Map(); const duplicates: string[] = []; tags.forEach((tagDto) => { - const key = `${tagDto.productUuid}-${tagDto.tag}`; + const key = `${tagDto.productUuid}-${tagDto.name}`; if (seen.has(key)) { - duplicates.push(`${tagDto.tag} for Product: ${tagDto.productUuid}`); + duplicates.push(`${tagDto.name} for Product: ${tagDto.productUuid}`); } else { seen.set(key, true); } @@ -396,7 +397,7 @@ export class TagService { } private async prepareTagEntity( - tagDto: CreateTagDto, + tagDto: ProcessTagDto, queryRunner: QueryRunner, space?: SpaceEntity, subspace?: SubspaceEntity, @@ -414,14 +415,14 @@ export class TagService { if (space) { await this.checkTagReuse( - tagDto.tag, + tagDto.name, tagDto.productUuid, space, tagsToDelete, ); } else if (subspace && subspace.space) { await this.checkTagReuse( - tagDto.tag, + tagDto.name, tagDto.productUuid, subspace.space, ); @@ -433,7 +434,7 @@ export class TagService { } return queryRunner.manager.create(TagEntity, { - tag: tagDto.tag, + tag: tagDto.name, product: product.data, space: space, subspace: subspace, @@ -476,13 +477,13 @@ export class TagService { } private combineTags( - primaryTags: CreateTagDto[], - additionalTags?: CreateTagDto[], - ): CreateTagDto[] { + primaryTags: ProcessTagDto[], + additionalTags?: ProcessTagDto[], + ): ProcessTagDto[] { return additionalTags ? [...primaryTags, ...additionalTags] : primaryTags; } - private ensureNoDuplicateTags(tags: CreateTagDto[]): void { + private ensureNoDuplicateTags(tags: ProcessTagDto[]): void { const duplicates = this.findDuplicateTags(tags); if (duplicates.length > 0) { @@ -493,7 +494,7 @@ export class TagService { } } - private validateTagsInput(tags: CreateTagDto[]): void { + private validateTagsInput(tags: ProcessTagDto[]): void { if (!tags?.length) { return; }