feat: added task controller

This commit is contained in:
2026-07-01 15:54:35 +03:30
parent ff4a8dedba
commit 31e3b5f00d
@@ -0,0 +1,67 @@
import { Controller, Get, Post, Patch, Delete, Param, Body, Query } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiQuery } from '@nestjs/swagger';
import { TaskService } from '../providers/task.service';
import { CreateTaskDto } from '../dto/task/create-task.dto';
import { UpdateTaskDto } from '../dto/task/update-task.dto';
import { ChangeTaskPhaseDto } from '../dto/task/change-task-phase.dto';
import { TMTask } from '../entities/task.entity';
@ApiTags('Task Manager - Tasks')
@Controller('task-manager/tasks')
export class TaskController {
constructor(private readonly taskService: TaskService) {}
@Get()
@ApiOperation({ summary: 'Get all tasks, optionally filtered by phase' })
@ApiQuery({ name: 'taskPhaseId', required: false, description: 'Filter tasks by task phase ID' })
@ApiResponse({ status: 200, description: 'List of tasks', type: [TMTask] })
findAll(@Query('taskPhaseId') taskPhaseId?: string): Promise<TMTask[]> {
if (taskPhaseId) return this.taskService.findByPhase(taskPhaseId);
return this.taskService.findAll();
}
@Get(':id')
@ApiOperation({ summary: 'Get a task by ID' })
@ApiParam({ name: 'id', description: 'Task ID' })
@ApiResponse({ status: 200, description: 'Task found', type: TMTask })
@ApiResponse({ status: 404, description: 'Task not found' })
findOne(@Param('id') id: string): Promise<TMTask> {
return this.taskService.findOne(id);
}
@Post()
@ApiOperation({ summary: 'Create a new task' })
@ApiResponse({ status: 201, description: 'Task created', type: TMTask })
@ApiResponse({ status: 404, description: 'TaskPhase not found' })
create(@Body() body: CreateTaskDto): Promise<TMTask> {
return this.taskService.create(body);
}
@Patch(':id')
@ApiOperation({ summary: 'Update a task' })
@ApiParam({ name: 'id', description: 'Task ID' })
@ApiResponse({ status: 200, description: 'Task updated', type: TMTask })
@ApiResponse({ status: 404, description: 'Task or TaskPhase not found' })
update(@Param('id') id: string, @Body() body: UpdateTaskDto): Promise<TMTask> {
return this.taskService.update(id, body);
}
@Patch(':id/change-phase')
@ApiOperation({ summary: 'Move a task to a different phase within the same project' })
@ApiParam({ name: 'id', description: 'Task ID' })
@ApiResponse({ status: 200, description: 'Task phase changed', type: TMTask })
@ApiResponse({ status: 400, description: 'Target phase belongs to a different project' })
@ApiResponse({ status: 404, description: 'Task or TaskPhase not found' })
changePhase(@Param('id') id: string, @Body() body: ChangeTaskPhaseDto): Promise<TMTask> {
return this.taskService.changePhase(id, body);
}
@Delete(':id')
@ApiOperation({ summary: 'Delete a task' })
@ApiParam({ name: 'id', description: 'Task ID' })
@ApiResponse({ status: 200, description: 'Task deleted' })
@ApiResponse({ status: 404, description: 'Task not found' })
remove(@Param('id') id: string): Promise<void> {
return this.taskService.remove(id);
}
}