fix ProcessTagDto dto issues

This commit is contained in:
faris Aljohari
2025-03-03 10:05:11 +03:00
parent e17a3fdda8
commit 95ecbab165
2 changed files with 21 additions and 21 deletions

View File

@ -2,7 +2,6 @@ import { BaseResponseDto } from '@app/common/dto/base.response.dto';
import { HttpException, HttpStatus, Injectable } from '@nestjs/common'; import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { import {
AddSubspaceDto, AddSubspaceDto,
DeleteSubspaceDto,
GetSpaceParam, GetSpaceParam,
GetSubSpaceParam, GetSubSpaceParam,
ModifySubspaceDto, ModifySubspaceDto,
@ -418,7 +417,7 @@ export class SubSpaceService {
): Promise<SubspaceEntity> { ): Promise<SubspaceEntity> {
const createTagDtos: ProcessTagDto[] = const createTagDtos: ProcessTagDto[] =
subspace.tags?.map((tag) => ({ subspace.tags?.map((tag) => ({
tag: tag.name as string, name: tag.name as string,
uuid: tag.tagUuid, uuid: tag.tagUuid,
productUuid: tag.productUuid as string, productUuid: tag.productUuid as string,
})) || []; })) || [];
@ -477,7 +476,7 @@ export class SubSpaceService {
const modifyTagDtos: ProcessTagDto[] = subspace.tags.map((tag) => ({ const modifyTagDtos: ProcessTagDto[] = subspace.tags.map((tag) => ({
uuid: tag.uuid, uuid: tag.uuid,
action: ModifyAction.ADD, action: ModifyAction.ADD,
tag: tag.tag, name: tag.tag,
productUuid: tag.product.uuid, productUuid: tag.product.uuid,
})); }));
await this.tagService.moveTags( await this.tagService.moveTags(

View File

@ -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 { TagEntity } from '@app/common/modules/space/entities/tag.entity';
import { HttpException, HttpStatus, Injectable } from '@nestjs/common'; import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { ProductService } from 'src/product/services'; 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 { ModifyTagDto } from 'src/space/dtos/tag/modify-tag.dto';
import { ProcessTagDto } from 'src/tags/dtos';
import { QueryRunner } from 'typeorm'; import { QueryRunner } from 'typeorm';
@Injectable() @Injectable()
@ -18,11 +19,11 @@ export class TagService {
) {} ) {}
async createTags( async createTags(
tags: CreateTagDto[], tags: ProcessTagDto[],
queryRunner: QueryRunner, queryRunner: QueryRunner,
space?: SpaceEntity, space?: SpaceEntity,
subspace?: SubspaceEntity, subspace?: SubspaceEntity,
additionalTags?: CreateTagDto[], additionalTags?: ProcessTagDto[],
tagsToDelete?: ModifyTagDto[], tagsToDelete?: ModifyTagDto[],
): Promise<TagEntity[]> { ): Promise<TagEntity[]> {
this.validateTagsInput(tags); this.validateTagsInput(tags);
@ -55,7 +56,7 @@ export class TagService {
} }
async bulkSaveTags( async bulkSaveTags(
tags: CreateTagDto[], tags: ProcessTagDto[],
queryRunner: QueryRunner, queryRunner: QueryRunner,
space?: SpaceEntity, space?: SpaceEntity,
subspace?: SubspaceEntity, subspace?: SubspaceEntity,
@ -92,7 +93,7 @@ export class TagService {
} }
async moveTags( async moveTags(
tags: CreateTagDto[], tags: ProcessTagDto[],
queryRunner: QueryRunner, queryRunner: QueryRunner,
space?: SpaceEntity, space?: SpaceEntity,
subspace?: SubspaceEntity, subspace?: SubspaceEntity,
@ -297,7 +298,7 @@ export class TagService {
await this.createTags( await this.createTags(
[ [
{ {
tag: tag.name, name: tag.name,
productUuid: tag.productUuid, productUuid: tag.productUuid,
uuid: tag.tagUuid, uuid: tag.tagUuid,
}, },
@ -342,14 +343,14 @@ export class TagService {
} }
} }
private findDuplicateTags(tags: CreateTagDto[]): string[] { private findDuplicateTags(tags: ProcessTagDto[]): string[] {
const seen = new Map<string, boolean>(); const seen = new Map<string, boolean>();
const duplicates: string[] = []; const duplicates: string[] = [];
tags.forEach((tagDto) => { tags.forEach((tagDto) => {
const key = `${tagDto.productUuid}-${tagDto.tag}`; const key = `${tagDto.productUuid}-${tagDto.name}`;
if (seen.has(key)) { if (seen.has(key)) {
duplicates.push(`${tagDto.tag} for Product: ${tagDto.productUuid}`); duplicates.push(`${tagDto.name} for Product: ${tagDto.productUuid}`);
} else { } else {
seen.set(key, true); seen.set(key, true);
} }
@ -396,7 +397,7 @@ export class TagService {
} }
private async prepareTagEntity( private async prepareTagEntity(
tagDto: CreateTagDto, tagDto: ProcessTagDto,
queryRunner: QueryRunner, queryRunner: QueryRunner,
space?: SpaceEntity, space?: SpaceEntity,
subspace?: SubspaceEntity, subspace?: SubspaceEntity,
@ -414,14 +415,14 @@ export class TagService {
if (space) { if (space) {
await this.checkTagReuse( await this.checkTagReuse(
tagDto.tag, tagDto.name,
tagDto.productUuid, tagDto.productUuid,
space, space,
tagsToDelete, tagsToDelete,
); );
} else if (subspace && subspace.space) { } else if (subspace && subspace.space) {
await this.checkTagReuse( await this.checkTagReuse(
tagDto.tag, tagDto.name,
tagDto.productUuid, tagDto.productUuid,
subspace.space, subspace.space,
); );
@ -433,7 +434,7 @@ export class TagService {
} }
return queryRunner.manager.create(TagEntity, { return queryRunner.manager.create(TagEntity, {
tag: tagDto.tag, tag: tagDto.name,
product: product.data, product: product.data,
space: space, space: space,
subspace: subspace, subspace: subspace,
@ -476,13 +477,13 @@ export class TagService {
} }
private combineTags( private combineTags(
primaryTags: CreateTagDto[], primaryTags: ProcessTagDto[],
additionalTags?: CreateTagDto[], additionalTags?: ProcessTagDto[],
): CreateTagDto[] { ): ProcessTagDto[] {
return additionalTags ? [...primaryTags, ...additionalTags] : primaryTags; return additionalTags ? [...primaryTags, ...additionalTags] : primaryTags;
} }
private ensureNoDuplicateTags(tags: CreateTagDto[]): void { private ensureNoDuplicateTags(tags: ProcessTagDto[]): void {
const duplicates = this.findDuplicateTags(tags); const duplicates = this.findDuplicateTags(tags);
if (duplicates.length > 0) { if (duplicates.length > 0) {
@ -493,7 +494,7 @@ export class TagService {
} }
} }
private validateTagsInput(tags: CreateTagDto[]): void { private validateTagsInput(tags: ProcessTagDto[]): void {
if (!tags?.length) { if (!tags?.length) {
return; return;
} }