mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 15:17:41 +00:00
Merge branch 'dev' of https://github.com/SyncrowIOT/backend into dev
This commit is contained in:
@ -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<SubspaceEntity> {
|
||||
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(
|
||||
|
@ -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<TagEntity[]> {
|
||||
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<string, boolean>();
|
||||
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user