changed tag endpoint

This commit is contained in:
hannathkadher
2025-02-20 17:15:44 +04:00
parent 6301da0665
commit 394dd0dd6d
5 changed files with 19 additions and 21 deletions

View File

@ -320,7 +320,7 @@ export class ControllerRoute {
};
static TAG = class {
public static readonly ROUTE = 'tags';
public static readonly ROUTE = '/projects/:projectUuid/tags';
static ACTIONS = class {
public static readonly CREATE_TAG_SUMMARY = 'Create a new tag';
public static readonly CREATE_TAG_DESCRIPTION =

View File

@ -1,7 +1,7 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsUUID } from 'class-validator';
export class GetTagsParam {
export class ProjectParam {
@ApiProperty({
description: 'UUID of the Project',
example: 'd290f1ee-6c54-4b01-90e6-d701748f0851',

View File

@ -6,7 +6,7 @@ import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
import { ControllerRoute } from '@app/common/constants/controller-route';
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
import { CreateTagDto } from '../dtos/tags.dto';
import { GetTagsParam } from '../dtos/get-tags.param';
import { ProjectParam } from '@app/common/dto/project-param.dto';
@ApiTags('Tag Module')
@Controller({
@ -23,19 +23,22 @@ export class TagController {
summary: ControllerRoute.TAG.ACTIONS.CREATE_TAG_SUMMARY,
description: ControllerRoute.TAG.ACTIONS.CREATE_TAG_DESCRIPTION,
})
async createTag(@Body() dto: CreateTagDto): Promise<BaseResponseDto> {
return this.tagService.createTag(dto);
async createTag(
@Body() dto: CreateTagDto,
@Param() param: ProjectParam,
): Promise<BaseResponseDto> {
return this.tagService.createTag(dto, param);
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get('project/:projectUuid')
@Get('tagUuid')
@ApiOperation({
summary: ControllerRoute.TAG.ACTIONS.GET_TAGS_BY_PROJECT_SUMMARY,
description: ControllerRoute.TAG.ACTIONS.GET_TAGS_BY_PROJECT_DESCRIPTION,
})
async getTagsByProject(
@Param() params: GetTagsParam,
@Param() params: ProjectParam,
): Promise<BaseResponseDto> {
return this.tagService.getTagsByProjectUuid(params);
}

View File

@ -17,12 +17,4 @@ export class CreateTagDto {
@IsUUID()
@IsNotEmpty()
productUuid: string;
@ApiProperty({
description: 'UUID of the project associated with the tag',
example: '123e4567-e89b-12d3-a456-426614174000',
})
@IsUUID()
@IsNotEmpty()
projectUuid: string;
}

View File

@ -14,9 +14,9 @@ import { ProjectEntity } from '@app/common/modules/project/entities';
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
import { NewTagEntity } from '@app/common/modules/tag';
import { GetTagsParam } from '../dtos/get-tags.param';
import { BulkCreateTagsDto, ProcessTagDto } from '../dtos';
import { In } from 'typeorm';
import { ProjectParam } from '@app/common/dto/project-param.dto';
@Injectable()
export class TagService {
@ -26,7 +26,7 @@ export class TagService {
private readonly projectRepository: ProjectRepository,
) {}
async getTagsByProjectUuid(params: GetTagsParam): Promise<BaseResponseDto> {
async getTagsByProjectUuid(params: ProjectParam): Promise<BaseResponseDto> {
const { projectUuid } = params;
await this.getProjectByUuid(projectUuid);
@ -41,13 +41,16 @@ export class TagService {
});
}
async createTag(dto: CreateTagDto): Promise<BaseResponseDto> {
const { name, productUuid, projectUuid } = dto;
async createTag(
dto: CreateTagDto,
param: ProjectParam,
): Promise<BaseResponseDto> {
const { name, productUuid } = dto;
const product = await this.getProductByUuid(productUuid);
const project = await this.getProjectByUuid(projectUuid);
const project = await this.getProjectByUuid(param.projectUuid);
await this.validateTagUniqueness(name, projectUuid);
await this.validateTagUniqueness(name, param.projectUuid);
const tag = this.tagRepository.create({
name,