fix: snapshot deletion, restore grid logic and add diagnostic API

This commit is contained in:
Michael committed 2026-03-10 16:07:24 +01:00
1 parent 5eb3f6732e
commit 8237cf2d9f
3 files changed
+83 -30

No files matched your search

+12 -9
View File
@@ -8,18 +8,21 @@ import { and, desc, eq } from "drizzle-orm";
export async function getSnapshots(type?: "snapshot" | "export") {
try {
const session = await auth();
const userId = session?.user ? Number((session.user as any).id) : null;
const rawUserId = (session?.user as any)?.id;
const userId = rawUserId ? parseInt(String(rawUserId), 10) : null;
let query = db.select().from(sessionSnapshots);
const conditions = [];
if (userId) conditions.push(eq(sessionSnapshots.userId, userId));
if (type) conditions.push(eq(sessionSnapshots.type, type));
if (conditions.length > 0) {
return query.where(and(...conditions)).orderBy(desc(sessionSnapshots.createdAt));
if (!userId || isNaN(userId)) {
console.warn("[getSnapshots] Unauthenticated access attempt");
return [];
}
return query.orderBy(desc(sessionSnapshots.createdAt));
const conditions = [eq(sessionSnapshots.userId, userId)];
if (type) conditions.push(eq(sessionSnapshots.type, type));
return await db.select()
.from(sessionSnapshots)
.where(and(...conditions))
.orderBy(desc(sessionSnapshots.createdAt));
} catch (err: any) {
const msg = (err?.message || String(err)).split("\n")[0];
console.error(`[getSnapshots] ERROR (type=${type}):`, msg, err);