diff --git a/src/modules/task-manager/controllers/attachment.controller.ts b/src/modules/task-manager/controllers/attachment.controller.ts index 8a4fe1d..ec5f554 100644 --- a/src/modules/task-manager/controllers/attachment.controller.ts +++ b/src/modules/task-manager/controllers/attachment.controller.ts @@ -1,5 +1,5 @@ -import { Controller, Get, Post, Patch, Delete, Param, Body, Query } from '@nestjs/common'; -import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiQuery } from '@nestjs/swagger'; +import { Controller, Post, Patch, Delete, Param, Body } from '@nestjs/common'; +import { ApiTags, ApiOperation, ApiResponse, ApiParam } from '@nestjs/swagger'; import { AttachmentService } from '../providers/attachment.service'; import { CreateAttachmentDto } from '../dto/attachment/create-attachment.dto'; import { UpdateAttachmentDto } from '../dto/attachment/update-attachment.dto'; @@ -14,24 +14,6 @@ import { AdminRoute } from '../../../common/decorators/admin.decorator'; export class AttachmentController { constructor(private readonly attachmentService: AttachmentService) {} - @Get() - @ApiOperation({ summary: 'Get all attachments, optionally filtered by task' }) - @ApiQuery({ name: 'taskId', required: false, description: 'Filter attachments by task ID' }) - @ApiResponse({ status: 200, description: 'List of attachments', type: [TMAttachment] }) - findAll(@Query('taskId') taskId?: string): Promise { - if (taskId) return this.attachmentService.findByTask(taskId); - return this.attachmentService.findAll(); - } - - @Get(':id') - @ApiOperation({ summary: 'Get an attachment by ID' }) - @ApiParam({ name: 'id', description: 'Attachment ID' }) - @ApiResponse({ status: 200, description: 'Attachment found', type: TMAttachment }) - @ApiResponse({ status: 404, description: 'Attachment not found' }) - findOne(@Param('id') id: string): Promise { - return this.attachmentService.findOneOrFail(id); - } - @Post() @ApiOperation({ summary: 'Create a new attachment' }) @ApiResponse({ status: 201, description: 'Attachment created', type: TMAttachment }) diff --git a/src/modules/task-manager/providers/attachment.service.ts b/src/modules/task-manager/providers/attachment.service.ts index 6854d30..72166ab 100644 --- a/src/modules/task-manager/providers/attachment.service.ts +++ b/src/modules/task-manager/providers/attachment.service.ts @@ -4,7 +4,7 @@ import { TMAttachment } from "../entities/attachment.entity"; import { CreateAttachmentDto } from "../dto/attachment/create-attachment.dto"; import { UpdateAttachmentDto } from "../dto/attachment/update-attachment.dto"; import { attachmentMessage } from "../../../common/enums/message.enum"; -import { TaskService } from './task.service'; +import { TaskService } from "./task.service"; @Injectable() export class AttachmentService { @@ -13,16 +13,8 @@ export class AttachmentService { private readonly taskService: TaskService, ) {} - findAll(): Promise { - return this.attachmentRepository.findAll(); - } - - findByTask(taskId: string): Promise { - return this.attachmentRepository.findByTask(taskId); - } - async findOneOrFail(id: string): Promise { - const attachment = await this.attachmentRepository.findOneById(id); + const attachment = await this.attachmentRepository.findOne({ where: { id }, relations: { task: true } }); if (!attachment) throw new NotFoundException(attachmentMessage.ATTACHMENT_NOT_FOUND); return attachment; } diff --git a/src/modules/task-manager/repositories/attachment.repository.ts b/src/modules/task-manager/repositories/attachment.repository.ts index c8b2c9d..a27d990 100644 --- a/src/modules/task-manager/repositories/attachment.repository.ts +++ b/src/modules/task-manager/repositories/attachment.repository.ts @@ -10,23 +10,4 @@ export class AttachmentRepository extends Repository{ ) { super(attachmentRepository.target, attachmentRepository.manager, attachmentRepository.queryRunner); } - - findAll() { - return this.find({ - relations: ['task'], - }); - } - - findByTask(taskId: string) { - return this.find({ - where: { taskId }, - }); - } - - findOneById(id: string) { - return this.findOne({ - where: { id }, - relations: ['task'], - }); - } } \ No newline at end of file