refactor: removed unnecessary functions from attachment

This commit is contained in:
2026-07-08 11:15:20 +03:30
parent 8348692481
commit 95c947a587
3 changed files with 4 additions and 49 deletions
@@ -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<TMAttachment[]> {
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<TMAttachment> {
return this.attachmentService.findOneOrFail(id);
}
@Post()
@ApiOperation({ summary: 'Create a new attachment' })
@ApiResponse({ status: 201, description: 'Attachment created', type: TMAttachment })
@@ -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<TMAttachment[]> {
return this.attachmentRepository.findAll();
}
findByTask(taskId: string): Promise<TMAttachment[]> {
return this.attachmentRepository.findByTask(taskId);
}
async findOneOrFail(id: string): Promise<TMAttachment> {
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;
}
@@ -10,23 +10,4 @@ export class AttachmentRepository extends Repository<TMAttachment>{
) {
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'],
});
}
}