Skip to content

Commit 165aac6

Browse files
committed
fix(teams): prevent duplicate tags in team creation
1 parent a67c894 commit 165aac6

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/modules/teams/dtos/team.dto.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { z } from 'zod/v4';
22
import { createZodDto } from 'nestjs-zod';
3-
import { createPaginationSchema } from '../../../shared/schemas';
3+
import { createPaginationSchema } from '@shared/schemas';
44

55
export const CreateTeamSchema = z.object({
66
name: z.string().min(2).max(100).describe('Название команды, отображаемое в интерфейсе'),
@@ -13,6 +13,9 @@ export const CreateTeamSchema = z.object({
1313
tags: z
1414
.array(z.string())
1515
.optional()
16+
.refine((items) => !items || new Set(items).size === items.length, {
17+
message: 'Теги в списке не должны повторяться',
18+
})
1619
.describe('Список строковых названий тегов для классификации'),
1720
});
1821

src/modules/teams/services/teams.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export class TeamsService {
5050
}
5151

5252
const { tags, ...teamData } = dto;
53+
const uniqueTags = tags ? [...new Set(tags)] : [];
5354

5455
try {
5556
const result = await this.teamsRepo.create(
@@ -58,7 +59,7 @@ export class TeamsService {
5859
...teamData,
5960
slug: baseSlug,
6061
},
61-
tags,
62+
uniqueTags,
6263
);
6364

6465
return {

0 commit comments

Comments
 (0)