fix: add valibot schemas to query() functions — fixes bad request on detail page

This commit is contained in:
Sanju Sivalingam
2026-02-17 21:16:58 +05:30
parent 423cd7af01
commit 5b73e89217
2 changed files with 29 additions and 25 deletions

View File

@@ -1,3 +1,4 @@
import * as v from 'valibot';
import { query, getRequestEvent } from '$app/server'; import { query, getRequestEvent } from '$app/server';
import { db } from '$lib/server/db'; import { db } from '$lib/server/db';
import { device, agentSession, agentStep } from '$lib/server/db/schema'; import { device, agentSession, agentStep } from '$lib/server/db/schema';
@@ -59,7 +60,7 @@ export const listDevices = query(async () => {
}); });
}); });
export const getDevice = query(async (deviceId: string) => { export const getDevice = query(v.string(), async (deviceId) => {
const { locals } = getRequestEvent(); const { locals } = getRequestEvent();
if (!locals.user) return null; if (!locals.user) return null;
@@ -88,7 +89,7 @@ export const getDevice = query(async (deviceId: string) => {
}; };
}); });
export const getDeviceStats = query(async (deviceId: string) => { export const getDeviceStats = query(v.string(), async (deviceId) => {
const { locals } = getRequestEvent(); const { locals } = getRequestEvent();
if (!locals.user) return null; if (!locals.user) return null;
@@ -116,7 +117,7 @@ export const getDeviceStats = query(async (deviceId: string) => {
} }
}); });
export const listDeviceSessions = query(async (deviceId: string) => { export const listDeviceSessions = query(v.string(), async (deviceId) => {
const { locals } = getRequestEvent(); const { locals } = getRequestEvent();
if (!locals.user) return []; if (!locals.user) return [];
@@ -130,7 +131,9 @@ export const listDeviceSessions = query(async (deviceId: string) => {
return sessions; return sessions;
}); });
export const listSessionSteps = query(async ({ deviceId, sessionId }: { deviceId: string; sessionId: string }) => { export const listSessionSteps = query(
v.object({ deviceId: v.string(), sessionId: v.string() }),
async ({ deviceId, sessionId }) => {
const { locals } = getRequestEvent(); const { locals } = getRequestEvent();
if (!locals.user) return []; if (!locals.user) return [];
@@ -150,4 +153,5 @@ export const listSessionSteps = query(async ({ deviceId, sessionId }: { deviceId
.orderBy(agentStep.stepNumber); .orderBy(agentStep.stepNumber);
return steps; return steps;
}); }
);

View File

@@ -41,9 +41,9 @@
id: string; id: string;
goal: string; goal: string;
status: string; status: string;
stepsUsed: number; stepsUsed: number | null;
startedAt: string; startedAt: Date;
completedAt: string | null; completedAt: Date | null;
} }
interface Step { interface Step {
id: string; id: string;
@@ -144,8 +144,8 @@
return unsub; return unsub;
}); });
function formatTime(iso: string) { function formatTime(d: string | Date) {
return new Date(iso).toLocaleString(); return (d instanceof Date ? d : new Date(d)).toLocaleString();
} }
function relativeTime(iso: string) { function relativeTime(iso: string) {