fix: añadir cabecera 'Tus tareas' y aplicar COALESCE en filtros

Co-authored-by: aider (openrouter/openai/gpt-5) <aider@aider.chat>
pull/1/head
borja 2 months ago
parent 6c4e85aa6c
commit a4c0d49991

@ -197,6 +197,9 @@ export class CommandService {
if (scope === 'todos') {
const sections: string[] = [];
// Encabezado fijo para la sección de tareas del usuario
sections.push('Tus tareas');
// Tus tareas (mis)
const myItems = TaskService.listUserPending(context.sender, LIMIT);
if (myItems.length > 0) {
@ -209,7 +212,6 @@ export class CommandService {
byGroup.set(key, arr);
}
sections.push('Tus tareas');
for (const [groupId, arr] of byGroup.entries()) {
const groupName =
(groupId && GroupSyncService.activeGroupsCache.get(groupId)) ||

@ -28,10 +28,19 @@ export class TaskService {
throw new Error('No se pudo asegurar created_by');
}
// Si el group_id no existe en la tabla groups, usar NULL para no violar la FK
let groupIdToInsert = task.group_id ?? null;
if (groupIdToInsert) {
const exists = this.dbInstance.prepare(`SELECT 1 FROM groups WHERE id = ?`).get(groupIdToInsert);
if (!exists) {
groupIdToInsert = null;
}
}
const runResult = insertTask.run(
task.description,
task.due_date ?? null,
task.group_id ?? null,
groupIdToInsert,
ensuredCreator
);
const taskId = Number((runResult as any).lastInsertRowid);
@ -76,7 +85,7 @@ export class TaskService {
SELECT id, description, due_date, group_id
FROM tasks
WHERE group_id = ?
AND (completed = 0 OR completed_at IS NULL)
AND COALESCE(completed, 0) = 0 AND completed_at IS NULL
ORDER BY
CASE WHEN due_date IS NULL THEN 1 ELSE 0 END,
due_date ASC,
@ -118,7 +127,7 @@ export class TaskService {
FROM tasks t
INNER JOIN task_assignments a ON a.task_id = t.id
WHERE a.user_id = ?
AND (t.completed = 0 OR t.completed_at IS NULL)
AND COALESCE(t.completed, 0) = 0 AND t.completed_at IS NULL
ORDER BY
CASE WHEN t.due_date IS NULL THEN 1 ELSE 0 END,
t.due_date ASC,
@ -153,7 +162,7 @@ export class TaskService {
SELECT COUNT(*) as cnt
FROM tasks
WHERE group_id = ?
AND (completed = 0 OR completed_at IS NULL)
AND COALESCE(completed, 0) = 0 AND completed_at IS NULL
`)
.get(groupId) as any;
return Number(row?.cnt || 0);
@ -167,7 +176,7 @@ export class TaskService {
FROM tasks t
INNER JOIN task_assignments a ON a.task_id = t.id
WHERE a.user_id = ?
AND (t.completed = 0 OR t.completed_at IS NULL)
AND COALESCE(t.completed, 0) = 0 AND t.completed_at IS NULL
`)
.get(userId) as any;
return Number(row?.cnt || 0);
@ -236,7 +245,7 @@ export class TaskService {
SELECT id, description, due_date, group_id
FROM tasks
WHERE group_id = ?
AND (completed = 0 OR completed_at IS NULL)
AND COALESCE(completed, 0) = 0 AND completed_at IS NULL
AND NOT EXISTS (
SELECT 1 FROM task_assignments ta WHERE ta.task_id = tasks.id
)
@ -264,7 +273,7 @@ export class TaskService {
SELECT COUNT(*) as cnt
FROM tasks t
WHERE t.group_id = ?
AND (t.completed = 0 OR t.completed_at IS NULL)
AND COALESCE(t.completed, 0) = 0 AND t.completed_at IS NULL
AND NOT EXISTS (
SELECT 1 FROM task_assignments a WHERE a.task_id = t.id
)

Loading…
Cancel
Save