115 lines
3.7 KiB
TypeScript
115 lines
3.7 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
HttpCode,
|
|
HttpStatus,
|
|
Param,
|
|
Patch,
|
|
Post,
|
|
Query,
|
|
} from '@nestjs/common';
|
|
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
|
import { TasksService } from './tasks.service';
|
|
import { CreateTaskDto } from './dto/create-task.dto';
|
|
import { UpdateTaskDto } from './dto/update-task.dto';
|
|
import { UpdateTaskStatusDto } from './dto/update-task-status.dto';
|
|
import { QueryTasksDto } from './dto/query-tasks.dto';
|
|
import { QueryRecurringDto } from './dto/query-recurring.dto';
|
|
import { BulkUpdateTasksDto, BulkDeleteTasksDto, CreateTasksFromTemplateDto } from './dto/bulk-tasks.dto';
|
|
import { Task } from './entities/task.entity';
|
|
import { PaginatedResponse } from '@common/pagination.dto';
|
|
import { RecurrenceService } from './recurrence.service';
|
|
|
|
@ApiTags('Tasks')
|
|
@Controller('tasks')
|
|
export class TasksController {
|
|
constructor(
|
|
private readonly tasksService: TasksService,
|
|
private readonly recurrenceService: RecurrenceService,
|
|
) {}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: 'List tasks with filters and pagination' })
|
|
findAll(@Query() query: QueryTasksDto): Promise<PaginatedResponse<Task>> {
|
|
return this.tasksService.findAll(query as QueryTasksDto & Record<string, unknown>);
|
|
}
|
|
|
|
@Post('bulk/update')
|
|
@ApiOperation({ summary: 'Bulk update tasks' })
|
|
bulkUpdate(@Body() dto: BulkUpdateTasksDto): Promise<{ affected: number }> {
|
|
return this.tasksService.bulkUpdate(dto.ids, dto.update as Partial<Task>);
|
|
}
|
|
|
|
@Post('bulk/delete')
|
|
@HttpCode(HttpStatus.OK)
|
|
@ApiOperation({ summary: 'Bulk soft-delete tasks' })
|
|
bulkDelete(@Body() dto: BulkDeleteTasksDto): Promise<{ affected: number }> {
|
|
return this.tasksService.bulkDelete(dto.ids);
|
|
}
|
|
|
|
@Post('template')
|
|
@ApiOperation({ summary: 'Create tasks from a named template' })
|
|
createFromTemplate(@Body() dto: CreateTasksFromTemplateDto): Promise<Task[]> {
|
|
return this.tasksService.createFromTemplate(dto.templateName, dto.domainId, dto.overrides);
|
|
}
|
|
|
|
@Get('recurring')
|
|
@ApiOperation({ summary: 'List all recurrence template tasks' })
|
|
findRecurring(@Query() query: QueryRecurringDto): Promise<PaginatedResponse<Task>> {
|
|
return this.recurrenceService.findRecurringTemplates(query);
|
|
}
|
|
|
|
@Get(':id/instances')
|
|
@ApiOperation({ summary: 'List spawned instances of a recurring task template' })
|
|
findInstances(
|
|
@Param('id') id: string,
|
|
@Query() query: QueryRecurringDto,
|
|
): Promise<PaginatedResponse<Task>> {
|
|
return this.recurrenceService.findInstances(id, query);
|
|
}
|
|
|
|
@Get(':id')
|
|
@ApiOperation({ summary: 'Get task by ID with subtasks' })
|
|
findOne(@Param('id') id: string): Promise<Task> {
|
|
return this.tasksService.findOneWithSubtasks(id);
|
|
}
|
|
|
|
@Post()
|
|
@ApiOperation({ summary: 'Create task' })
|
|
create(@Body() dto: CreateTaskDto): Promise<Task> {
|
|
return this.tasksService.createTask(dto);
|
|
}
|
|
|
|
@Patch(':id')
|
|
@ApiOperation({ summary: 'Update task' })
|
|
update(@Param('id') id: string, @Body() dto: UpdateTaskDto): Promise<Task> {
|
|
return this.tasksService.updateTask(id, dto);
|
|
}
|
|
|
|
@Patch(':id/status')
|
|
@ApiOperation({ summary: 'Quick status transition' })
|
|
updateStatus(
|
|
@Param('id') id: string,
|
|
@Body() dto: UpdateTaskStatusDto,
|
|
): Promise<Task> {
|
|
return this.tasksService.updateStatus(id, dto);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@HttpCode(HttpStatus.NO_CONTENT)
|
|
@ApiOperation({ summary: 'Soft delete task' })
|
|
remove(@Param('id') id: string): Promise<void> {
|
|
return this.tasksService.softDelete(id);
|
|
}
|
|
|
|
@Post(':id/reorder')
|
|
@ApiOperation({ summary: 'Update sort order' })
|
|
reorder(
|
|
@Param('id') id: string,
|
|
@Body('sortOrder') sortOrder: number,
|
|
): Promise<Task> {
|
|
return this.tasksService.reorder(id, sortOrder);
|
|
}
|
|
}
|