|
|
|
|
@ -17,6 +17,8 @@ export const GET: RequestHandler = async (event) => {
|
|
|
|
|
const status = (url.searchParams.get('status') || 'open').trim().toLowerCase();
|
|
|
|
|
const page = clamp(parseInt(url.searchParams.get('page') || '1', 10) || 1, 1, 100000);
|
|
|
|
|
const limit = clamp(parseInt(url.searchParams.get('limit') || '20', 10) || 20, 1, 100);
|
|
|
|
|
const orderParam = (url.searchParams.get('order') || 'due').trim().toLowerCase();
|
|
|
|
|
const order = orderParam === 'group_then_due' ? 'group_then_due' : 'due';
|
|
|
|
|
const dueBeforeParam = (url.searchParams.get('dueBefore') || '').trim();
|
|
|
|
|
const soonDaysParam = parseInt(url.searchParams.get('soonDays') || '', 10);
|
|
|
|
|
const soonDays = Number.isFinite(soonDaysParam) && soonDaysParam >= 0 ? Math.min(soonDaysParam, 365) : null;
|
|
|
|
|
@ -159,16 +161,19 @@ export const GET: RequestHandler = async (event) => {
|
|
|
|
|
const total = Number(totalRow?.cnt || 0);
|
|
|
|
|
|
|
|
|
|
// Items
|
|
|
|
|
const orderBy =
|
|
|
|
|
order === 'group_then_due'
|
|
|
|
|
? `(t.group_id IS NULL) ASC, g.name COLLATE NOCASE ASC, CASE WHEN t.due_date IS NULL THEN 1 ELSE 0 END, t.due_date ASC, t.id ASC`
|
|
|
|
|
: `CASE WHEN t.due_date IS NULL THEN 1 ELSE 0 END, t.due_date ASC, t.id ASC`;
|
|
|
|
|
|
|
|
|
|
const itemsRows = db
|
|
|
|
|
.prepare(
|
|
|
|
|
`SELECT t.id, t.description, t.due_date, t.group_id, t.display_code
|
|
|
|
|
FROM tasks t
|
|
|
|
|
LEFT JOIN groups g ON g.id = t.group_id
|
|
|
|
|
INNER JOIN task_assignments a ON a.task_id = t.id
|
|
|
|
|
WHERE ${whereParts.join(' AND ')}
|
|
|
|
|
ORDER BY
|
|
|
|
|
CASE WHEN t.due_date IS NULL THEN 1 ELSE 0 END,
|
|
|
|
|
t.due_date ASC,
|
|
|
|
|
t.id ASC
|
|
|
|
|
ORDER BY ${orderBy}
|
|
|
|
|
LIMIT ? OFFSET ?`
|
|
|
|
|
)
|
|
|
|
|
.all(...params, limit, offset) as any[];
|
|
|
|
|
|