From fcf389bf292b2d8168d5bd59441be193752b7d77 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Tue, 18 Feb 2025 01:21:03 +0100 Subject: [PATCH] Lib: Add seasonpickedusers fetcher --- src/lib/fetch.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/lib/fetch.ts b/src/lib/fetch.ts index d7bef97..c1d95a2 100644 --- a/src/lib/fetch.ts +++ b/src/lib/fetch.ts @@ -7,6 +7,7 @@ import type { RacePick, RaceResult, SeasonPick, + SeasonPickedUser, Substitution, Team, User, @@ -183,3 +184,23 @@ export const fetch_currentpickedusers = async ( return currentpickedusers; }; + +/** + * Fetch all [Users] (with the extra field "picked" that is truthy + * if the user already picked for the season) with file URLs for the avatars + */ +export const fetch_seasonpickedusers = async ( + fetch: (_: any) => Promise, +): Promise => { + const seasonpickedusers: SeasonPickedUser[] = await pb + .collection("seasonpickedusers") + .getFullList({ fetch: fetch }); + + seasonpickedusers.map((seasonpickeduser: SeasonPickedUser) => { + if (seasonpickeduser.avatar) { + seasonpickeduser.avatar_url = pb.files.getURL(seasonpickeduser, seasonpickeduser.avatar); + } + }); + + return seasonpickedusers; +};