feat: Add server-side function getSnapshots to retrieve session snapshots from the database.

This commit is contained in:
Michael committed 2026-02-22 14:39:42 +01:00
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 [];
}
} }