fix(tasks): support status query param in list API and use it in today-tasks widget
The dashboard widget was filtering with a broken filter=status!=done query param that the list API never interpreted, so completed tasks could appear. Add a status= todo,in_progress filter to GET /api/tasks and update the widget to use it (also fix domain badge to use domainId).
This commit is contained in:
@@ -34,6 +34,7 @@ export const GET = withAuth(async (request: NextRequest, _user) => {
|
|||||||
const page = Math.max(1, parseInt(searchParams.get('page') || '1'));
|
const page = Math.max(1, parseInt(searchParams.get('page') || '1'));
|
||||||
const perPage = Math.min(100, Math.max(1, parseInt(searchParams.get('perPage') || '50')));
|
const perPage = Math.min(100, Math.max(1, parseInt(searchParams.get('perPage') || '50')));
|
||||||
const filter = searchParams.get('filter') || undefined;
|
const filter = searchParams.get('filter') || undefined;
|
||||||
|
const status = searchParams.get('status');
|
||||||
const sort = searchParams.get('sort') || '-created';
|
const sort = searchParams.get('sort') || '-created';
|
||||||
const domainId = searchParams.get('domain') || undefined;
|
const domainId = searchParams.get('domain') || undefined;
|
||||||
|
|
||||||
@@ -54,6 +55,10 @@ export const GET = withAuth(async (request: NextRequest, _user) => {
|
|||||||
|
|
||||||
const conditions: any[] = [isNull(tasks.deletedAt)];
|
const conditions: any[] = [isNull(tasks.deletedAt)];
|
||||||
if (domainId) conditions.push(eq(tasks.domainId, domainId));
|
if (domainId) conditions.push(eq(tasks.domainId, domainId));
|
||||||
|
if (status) {
|
||||||
|
const statuses = status.split(',');
|
||||||
|
conditions.push(inArray(tasks.status, statuses as any));
|
||||||
|
}
|
||||||
if (filter) {
|
if (filter) {
|
||||||
conditions.push(
|
conditions.push(
|
||||||
or(
|
or(
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ interface Task {
|
|||||||
title: string;
|
title: string;
|
||||||
status: string;
|
status: string;
|
||||||
priority: string;
|
priority: string;
|
||||||
domain: string;
|
domainId?: string;
|
||||||
|
domain?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Domain { id: string; name: string; color: string; }
|
interface Domain { id: string; name: string; color: string; }
|
||||||
@@ -43,7 +44,7 @@ export function TodayTasksWidget() {
|
|||||||
async function fetchTasks() {
|
async function fetchTasks() {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
'/api/tasks?filter=status!%3D%22done%22&perPage=5&sort=-priority'
|
'/api/tasks?status=todo,in_progress&perPage=5&sort=-priority'
|
||||||
);
|
);
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
@@ -115,7 +116,7 @@ export function TodayTasksWidget() {
|
|||||||
{task.title}
|
{task.title}
|
||||||
</span>
|
</span>
|
||||||
<Badge variant="outline" className="text-xs">
|
<Badge variant="outline" className="text-xs">
|
||||||
{domainMap.get(task.domain) || task.domain}
|
{domainMap.get(task.domainId ?? task.domain ?? '') || task.domainId || task.domain}
|
||||||
</Badge>
|
</Badge>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|||||||
Reference in New Issue
Block a user