From 8db2b634d38df93130f3407601399e75624164fd Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Mon, 3 Feb 2025 21:31:21 +0100 Subject: [PATCH] Lib: Add helpers to obtain certain template graphics --- src/lib/database.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/lib/database.ts b/src/lib/database.ts index 6e6aacb..349069a 100644 --- a/src/lib/database.ts +++ b/src/lib/database.ts @@ -1,3 +1,5 @@ +import type { Graphic } from "$lib/schema"; + /** * Select an element from an [objects] array where [key] matches [value]. * Supposed to be used on collections returned by the [PocketBase] client. @@ -9,3 +11,15 @@ export const get_by_value = ( ): T | undefined => { return objects.find((o: T) => (key in o ? o[key] === value : false)); }; + +export const get_team_banner_template = (graphics: Graphic[]) => + get_by_value(graphics, "name", "team_banner_template")?.file_url ?? "Invalid"; + +export const get_team_logo_template = (graphics: Graphic[]) => + get_by_value(graphics, "name", "team_logo_template")?.file_url ?? "Invalid"; + +export const get_driver_headshot_template = (graphics: Graphic[]) => + get_by_value(graphics, "name", "driver_headshot_template")?.file_url ?? "Invalid"; + +export const get_race_pictogram_template = (graphics: Graphic[]) => + get_by_value(graphics, "name", "race_pictogram_template")?.file_url ?? "Invalid";