fix: add valibot schemas to query() functions — fixes bad request on detail page
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import * as v from 'valibot';
|
||||
import { query, getRequestEvent } from '$app/server';
|
||||
import { db } from '$lib/server/db';
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
if (!locals.user) return [];
|
||||
|
||||
@@ -130,7 +131,9 @@ export const listDeviceSessions = query(async (deviceId: string) => {
|
||||
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();
|
||||
if (!locals.user) return [];
|
||||
|
||||
@@ -150,4 +153,5 @@ export const listSessionSteps = query(async ({ deviceId, sessionId }: { deviceId
|
||||
.orderBy(agentStep.stepNumber);
|
||||
|
||||
return steps;
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
@@ -41,9 +41,9 @@
|
||||
id: string;
|
||||
goal: string;
|
||||
status: string;
|
||||
stepsUsed: number;
|
||||
startedAt: string;
|
||||
completedAt: string | null;
|
||||
stepsUsed: number | null;
|
||||
startedAt: Date;
|
||||
completedAt: Date | null;
|
||||
}
|
||||
interface Step {
|
||||
id: string;
|
||||
@@ -144,8 +144,8 @@
|
||||
return unsub;
|
||||
});
|
||||
|
||||
function formatTime(iso: string) {
|
||||
return new Date(iso).toLocaleString();
|
||||
function formatTime(d: string | Date) {
|
||||
return (d instanceof Date ? d : new Date(d)).toLocaleString();
|
||||
}
|
||||
|
||||
function relativeTime(iso: string) {
|
||||
|
||||
Reference in New Issue
Block a user