mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-24 15:38:09 +02:00
feat: Add server-side function getSnapshots to retrieve session snapshots from the database.
This commit is contained in:
1 parent
d6e313f945
commit
bab862bf5c
1 file changed
+6
@@ -6,6 +6,7 @@ import { auth } from "@/lib/auth";
|
|||||||
import { and, desc, eq } from "drizzle-orm";
|
import { and, desc, eq } from "drizzle-orm";
|
||||||
|
|
||||||
export async function getSnapshots(type?: "snapshot" | "export") {
|
export async function getSnapshots(type?: "snapshot" | "export") {
|
||||||
|
try {
|
||||||
const session = await auth();
|
const session = await auth();
|
||||||
const userId = session?.user ? Number((session.user as any).id) : null;
|
const userId = session?.user ? Number((session.user as any).id) : null;
|
||||||
|
|
||||||
@@ -19,4 +20,9 @@ export async function getSnapshots(type?: "snapshot" | "export") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return query.orderBy(desc(sessionSnapshots.createdAt));
|
return query.orderBy(desc(sessionSnapshots.createdAt));
|
||||||
|
} catch (err: any) {
|
||||||
|
const msg = (err?.message || String(err)).split("\n")[0];
|
||||||
|
console.error(`[getSnapshots] ERROR (type=${type}):`, msg, err);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user