fix(web): workflow org visibility issues
This commit is contained in:
@@ -1,10 +1,35 @@
|
||||
import { db } from "@/db/db";
|
||||
import { workflowTable, workflowVersionTable } from "@/db/schema";
|
||||
import { desc, eq } from "drizzle-orm";
|
||||
import { auth } from "@clerk/nextjs";
|
||||
import { and, desc, eq, isNull } from "drizzle-orm";
|
||||
|
||||
export async function findFirstTableWithVersion(workflow_id: string) {
|
||||
const { userId, orgId } = auth();
|
||||
if (!userId) throw new Error("No auth");
|
||||
return await db.query.workflowTable.findFirst({
|
||||
with: { versions: { orderBy: desc(workflowVersionTable.version) } },
|
||||
where: eq(workflowTable.id, workflow_id),
|
||||
where: and(
|
||||
eq(workflowTable.id, workflow_id),
|
||||
orgId
|
||||
? eq(workflowTable.org_id, orgId)
|
||||
: and(eq(workflowTable.user_id, userId), isNull(workflowTable.org_id))
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
export function findWorkflowById(workflow_id: string) {
|
||||
const { userId, orgId } = auth();
|
||||
if (!userId) throw new Error("No auth");
|
||||
|
||||
return db.query.workflowTable.findFirst({
|
||||
columns: {
|
||||
id: true,
|
||||
},
|
||||
where: and(
|
||||
eq(workflowTable.id, workflow_id),
|
||||
orgId
|
||||
? eq(workflowTable.org_id, orgId)
|
||||
: and(eq(workflowTable.user_id, userId), isNull(workflowTable.org_id))
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user