job ordering

This commit is contained in:
Jun-te Kim 2026-05-15 10:13:09 +00:00
parent cd47aef985
commit 41891a4540
2 changed files with 4 additions and 4 deletions

View file

@ -1,7 +1,7 @@
import { db } from "@/app/db/db";
import { tasks } from "@/app/db/schema/tasks/tasks";
import { subTasks } from "@/app/db/schema/tasks/subtask";
import { eq, desc, count, sql } from "drizzle-orm";
import { eq, count, sql } from "drizzle-orm";
import { NextRequest, NextResponse } from "next/server";
export async function GET(
@ -31,7 +31,7 @@ export async function GET(
.leftJoin(subTasks, eq(subTasks.taskId, tasks.id))
.where(eq(tasks.sourceId, portfolioId))
.groupBy(tasks.id)
.orderBy(desc(tasks.jobStarted))
.orderBy(sql`${tasks.jobStarted} desc nulls last`)
.limit(limit)
.offset(offset);

View file

@ -1,6 +1,6 @@
import { db } from "@/app/db/db";
import { subTasks } from "@/app/db/schema/tasks/subtask";
import { eq } from "drizzle-orm";
import { eq, sql } from "drizzle-orm";
import { NextRequest, NextResponse } from "next/server";
export async function GET(
@ -13,7 +13,7 @@ export async function GET(
.select()
.from(subTasks)
.where(eq(subTasks.taskId, taskId))
.orderBy(subTasks.jobStarted);
.orderBy(sql`${subTasks.jobStarted} asc nulls last`);
return NextResponse.json(taskSubTasks);
} catch (error) {