|
|
|
|
@ -16,6 +16,11 @@ export const GET: RequestHandler = async (event) => {
|
|
|
|
|
const url = new URL(event.request.url);
|
|
|
|
|
const unassignedFirst =
|
|
|
|
|
(url.searchParams.get('unassignedFirst') || '').trim().toLowerCase() === 'true';
|
|
|
|
|
const onlyUnassigned =
|
|
|
|
|
(url.searchParams.get('onlyUnassigned') || '').trim().toLowerCase() === 'true';
|
|
|
|
|
let limit = parseInt(url.searchParams.get('limit') || '', 10);
|
|
|
|
|
if (!Number.isFinite(limit) || limit <= 0) limit = 0;
|
|
|
|
|
if (limit > 100) limit = 100;
|
|
|
|
|
|
|
|
|
|
const db = await getDb();
|
|
|
|
|
|
|
|
|
|
@ -45,16 +50,28 @@ export const GET: RequestHandler = async (event) => {
|
|
|
|
|
`t.id ASC`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const rows = db
|
|
|
|
|
.prepare(
|
|
|
|
|
`SELECT t.id, t.description, t.due_date, t.group_id, t.display_code
|
|
|
|
|
const whereParts = [
|
|
|
|
|
`t.group_id = ?`,
|
|
|
|
|
`COALESCE(t.completed, 0) = 0`,
|
|
|
|
|
`t.completed_at IS NULL`
|
|
|
|
|
];
|
|
|
|
|
if (onlyUnassigned) {
|
|
|
|
|
whereParts.push(
|
|
|
|
|
`NOT EXISTS (SELECT 1 FROM task_assignments a WHERE a.task_id = t.id)`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const params: any[] = [groupId];
|
|
|
|
|
|
|
|
|
|
const sql = `
|
|
|
|
|
SELECT t.id, t.description, t.due_date, t.group_id, t.display_code
|
|
|
|
|
FROM tasks t
|
|
|
|
|
WHERE t.group_id = ?
|
|
|
|
|
AND COALESCE(t.completed, 0) = 0
|
|
|
|
|
AND t.completed_at IS NULL
|
|
|
|
|
ORDER BY ${orderParts.join(', ')}`
|
|
|
|
|
)
|
|
|
|
|
.all(groupId) as any[];
|
|
|
|
|
WHERE ${whereParts.join(' AND ')}
|
|
|
|
|
ORDER BY ${orderParts.join(', ')}${limit > 0 ? ' LIMIT ?' : ''}`;
|
|
|
|
|
|
|
|
|
|
if (limit > 0) params.push(limit);
|
|
|
|
|
|
|
|
|
|
const rows = db.prepare(sql).all(...params) as any[];
|
|
|
|
|
|
|
|
|
|
let items = rows.map((r) => ({
|
|
|
|
|
id: Number(r.id),
|
|
|
|
|
@ -66,7 +83,7 @@ export const GET: RequestHandler = async (event) => {
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
// Cargar asignados
|
|
|
|
|
if (items.length > 0) {
|
|
|
|
|
if (items.length > 0 && !onlyUnassigned) {
|
|
|
|
|
const ids = items.map((it) => it.id);
|
|
|
|
|
const placeholders = ids.map(() => '?').join(',');
|
|
|
|
|
const assignRows = db
|
|
|
|
|
|