diff --git a/backend/routes/tasks/queries/metrics-queries.js b/backend/routes/tasks/queries/metrics-queries.js index 26cf399..ad18368 100644 --- a/backend/routes/tasks/queries/metrics-queries.js +++ b/backend/routes/tasks/queries/metrics-queries.js @@ -40,7 +40,11 @@ async function fetchTasksInProgress(visibleTasksWhere) { recurring_parent_id: null, }, include: getTaskIncludeConfig(), - order: [['priority', 'DESC']], + order: [ + ['priority', 'DESC'], + ['due_date', 'ASC'], + ['project_id', 'ASC'], + ], }); } @@ -67,7 +71,8 @@ async function fetchTodayPlanTasks(visibleTasksWhere) { include: getTaskIncludeConfig(), order: [ ['priority', 'DESC'], - ['created_at', 'ASC'], + ['due_date', 'ASC'], + ['project_id', 'ASC'], ], }); } diff --git a/frontend/utils/taskSortUtils.ts b/frontend/utils/taskSortUtils.ts index bc233d4..ecfe713 100644 --- a/frontend/utils/taskSortUtils.ts +++ b/frontend/utils/taskSortUtils.ts @@ -36,11 +36,19 @@ export const sortTasksByPriorityDueDateProject = ( return [...filteredTasks].sort((a, b) => { // 1. Priority (High → Medium → Low → None) - const priorityOrder = { high: 3, medium: 2, low: 1 }; - const aPriority = - priorityOrder[a.priority as keyof typeof priorityOrder] || 0; - const bPriority = - priorityOrder[b.priority as keyof typeof priorityOrder] || 0; + // Handle both string ('low', 'medium', 'high') and numeric (0, 1, 2) priority values + const getPriorityValue = (priority: any): number => { + if (typeof priority === 'number') { + // Backend numeric format: 0 = LOW, 1 = MEDIUM, 2 = HIGH + return priority; + } + // Frontend string format + const priorityOrder = { high: 2, medium: 1, low: 0 }; + return priorityOrder[priority as keyof typeof priorityOrder] ?? -1; + }; + + const aPriority = getPriorityValue(a.priority); + const bPriority = getPriorityValue(b.priority); if (aPriority !== bPriority) { return bPriority - aPriority; // Higher priority first }