Lib: Move data fetching functions to library

This commit is contained in:
2025-02-17 20:59:50 +01:00
parent 37f4234c87
commit 8c8be5273b
4 changed files with 191 additions and 132 deletions

View File

@ -1,21 +1,8 @@
import { pb } from "$lib/pocketbase";
import type { User } from "$lib/schema";
import { fetch_users } from "$lib/fetch";
import type { PageLoad } from "../../$types";
export const load: PageLoad = async ({ fetch }) => {
const fetch_users = async (): Promise<User[]> => {
const users: User[] = await pb
.collection("users")
.getFullList({ fetch: fetch, sort: "+username" });
users.map((user: User) => {
user.avatar_url = pb.files.getURL(user, user.avatar);
});
return users;
};
return {
users: await fetch_users(),
users: await fetch_users(fetch),
};
};