Added route Get task by ID

This commit is contained in:
Nikolay Tarasov 2025-03-02 11:07:47 +03:00
parent 489184b841
commit a0d87692ea
2 changed files with 21 additions and 0 deletions

View File

@ -84,6 +84,20 @@ export class TasksController {
return this.tasksService.findOneById(id);
}
@ApiOperation({ summary: 'Get tasks by project ID' })
@ApiParam({ name: 'projectId', type: 'number' })
@ApiResponse({
status: 200,
description: 'List of tasks for the specified project',
type: Task,
isArray: true,
})
@Get('project/:projectId')
async findByProject(@Param('projectId') projectId: number): Promise<Task[]> {
return this.tasksService.findByProjectId(projectId);
}
@ApiOperation({ summary: 'Update task' })
@ApiParam({ name: 'id', type: 'number' })
@ApiBody({

View File

@ -42,6 +42,13 @@ export class TasksService {
return this.tasksRepository.findOne({ where: { id } });
}
async findByProjectId(projectId: number): Promise<Task[]> {
return this.tasksRepository.find({
where: { project: { id: projectId } },
relations: ['assigned_user'], // Загружаем связанные данные о назначенном пользователе
});
}
async update(id: number, data: { title?: string; status?: string; deadline?: Date; assignedUserId?: number }) {
const task = await this.findOneById(id);
if (!task) throw new NotFoundException('Task not found');