adds zod API validation

This commit is contained in:
Christian Beutel
2024-12-27 01:56:35 +01:00
parent 1f81779a64
commit 75c94a3ce4
80 changed files with 847 additions and 559 deletions

View File

@@ -1,7 +1,7 @@
import { Comment } from "$lib/models/comment";
import type { Trail } from "$lib/models/trail";
import { pb } from "$lib/pocketbase";
import { ClientResponseError } from "pocketbase";
import { ClientResponseError, type ListResult } from "pocketbase";
import { writable, type Writable } from "svelte/store";
export const comments: Writable<Comment[]> = writable([])
@@ -9,6 +9,7 @@ export const comments: Writable<Comment[]> = writable([])
export async function comments_index(trail: Trail) {
let r = await fetch('/api/v1/comment?' + new URLSearchParams({
filter: `trail="${trail.id}"`,
sort: "-created"
}), {
method: 'GET',
})
@@ -17,11 +18,11 @@ export async function comments_index(trail: Trail) {
throw new ClientResponseError(await r.json())
}
const fetchedComments: Comment[] = await r.json();
const fetchedComments: ListResult<Comment> = await r.json();
comments.set(fetchedComments);
comments.set(fetchedComments.items);
return fetchedComments;
return fetchedComments.items;
}
export async function comments_create(comment: Comment) {