Skip to content

Commit 2cd09da

Browse files
committed
fix(sortOrder): initial ordering must be deterministic
1 parent 45bd1e8 commit 2cd09da

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

apps/sim/app/api/workflows/route.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { db } from '@sim/db'
22
import { workflow } from '@sim/db/schema'
33
import { createLogger } from '@sim/logger'
4-
import { and, eq, isNull, max } from 'drizzle-orm'
4+
import { and, asc, eq, isNull, max } from 'drizzle-orm'
55
import { type NextRequest, NextResponse } from 'next/server'
66
import { z } from 'zod'
77
import { getSession } from '@/lib/auth'
@@ -64,10 +64,20 @@ export async function GET(request: Request) {
6464

6565
let workflows
6666

67+
const orderByClause = [asc(workflow.sortOrder), asc(workflow.createdAt), asc(workflow.id)]
68+
6769
if (workspaceId) {
68-
workflows = await db.select().from(workflow).where(eq(workflow.workspaceId, workspaceId))
70+
workflows = await db
71+
.select()
72+
.from(workflow)
73+
.where(eq(workflow.workspaceId, workspaceId))
74+
.orderBy(...orderByClause)
6975
} else {
70-
workflows = await db.select().from(workflow).where(eq(workflow.userId, userId))
76+
workflows = await db
77+
.select()
78+
.from(workflow)
79+
.where(eq(workflow.userId, userId))
80+
.orderBy(...orderByClause)
7181
}
7282

7383
return NextResponse.json({ data: workflows }, { status: 200 })

0 commit comments

Comments
 (0)