Endpoint GET /api/tasks/comments
Endpoint Cloudflare Pages Function que devuelve comentarios de todas las tareas del workspace con soporte de filtros y paginación. Introducido en s77 (b07fd73, 2026-05-20).
Ruta: GET /api/tasks/comments
Archivo: functions/api/tasks/comments.ts
Runtime: Cloudflare Pages Functions
Base de datos: D1 (env.DB)
Autenticación: heredada del middleware de Pages (sin auth propia en el handler)
Respuesta
{
"results": [CommentRow],
"total": 128
}
Patrón { results, total } igual que GET /api/activity, para reutilizar los helpers de paginación del frontend.
Parámetros de query
| Parámetro | Tipo | Default | Descripción |
|---|---|---|---|
author | string | — | Filtra por autor exacto (Edu, Dani, Txell) |
target_user | string | — | Match dentro del JSON array target_user_ids |
task_id | int | — | Filtra por tarea exacta |
task_title | string | — | LIKE %valor% en tasks.title |
q | string | — | LIKE %valor% en task_comments.body |
start_date | YYYY-MM-DD | — | created_at >= start_date |
end_date | YYYY-MM-DD | — | created_at <= end_date + ' 23:59:59' |
limit | int | 50 | Máximo 200 |
offset | int | 0 | Paginación |
Schema de respuesta por ítem (CommentRow)
interface CommentRow {
id: number;
task_id: number;
author: string;
body: string;
target_user_ids: string | null; // JSON array serializado, ej: '["Edu","Dani"]'
created_at: string; // ISO 8601
task_title: string | null; // NULL si la tarea fue borrada
task_status: string | null;
task_assignee: string | null;
}
Query SQL base
SELECT c.id, c.task_id, c.author, c.body, c.target_user_ids, c.created_at,
t.title AS task_title, t.status AS task_status, t.assignee AS task_assignee
FROM task_comments c
LEFT JOIN tasks t ON t.id = c.task_id
[WHERE ...]
ORDER BY c.created_at DESC
LIMIT ? OFFSET ?
Se ejecuta también una segunda query COUNT(*) con los mismos filtros para devolver total sin traer todos los registros.
Detalle del filtro target_user
target_user_ids se almacena como texto JSON (ej. '["Edu","Dani"]'). El filtro usa:
c.target_user_ids LIKE '%"Edu"%'
Las comillas dobles en el patrón evitan falsos positivos con nombres que sean prefijos de otros (ej. buscar "Ed" no matchearía "Edu").
Frontend consumidor
TaskCommentsView (src/components/tasks/TaskCommentsView.tsx) es el componente principal que consume este endpoint. Se monta en TaskManager cuando view === 'comments', accesible via ?view=comments en la URL.
Tablas D1 referenciadas
| Tabla | Rol |
|---|---|
task_comments | Tabla principal — comentarios de tareas |
tasks | JOIN para enriquecer con título, estado y asignado |
Véase también
- [[feature—tasks—s77-mejoras-gestor]]
- [[workspace—tareas-notas]]
- [[workspace—que-es-workspace]]