|
|
|
|
@ -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
|
|
|
|
|
)
|
|
|
|
|
|