diff --git a/src/lib/ldb/staff/fetch.ts b/src/lib/ldb/staff/fetch.ts index c1d64ac..c58ddcf 100644 --- a/src/lib/ldb/staff/fetch.ts +++ b/src/lib/ldb/staff/fetch.ts @@ -1,10 +1,38 @@ // Fetches StaffLDB Data, correctly formats DATE fields and returns the data import { getApiUrl } from "$lib/scripts/upstream"; +import { uuid } from "$lib/stores/uuid"; import type { ApiResponse, StaffLdb } from "@owlboard/ts-types"; // Fetch StaffLDB Data, and returns the data after hydration (convert date types etc.) -export async function fetchStaffLdb(station: string, auth: string): Promise> { - const url = `${getApiUrl()}//api/v2/live/station/${station}/staff`; +export async function fetchStaffLdb(station: string): Promise> { + const url = `${getApiUrl()}/api/v2/live/station/${station}/staff`; + let uuid_value: string = ''; + const unsubscribe = uuid.subscribe((value) => { + uuid_value = value; + }); + + const fetchOpts = { + method: 'GET', + headers: { + uuid: uuid_value, + }, + }; + const res = await fetch(url, fetchOpts) + unsubscribe(); + const resJs = await res.json() + return parseFormat(JSON.stringify(resJs)) +} + +function parseFormat(jsonString: any): ApiResponse { + return JSON.parse(jsonString, (key, value) => { + if (typeof value === 'string') { + const dateRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/; + if (dateRegex.test(value)) { + return new Date(value); + } + } + return value + }); } \ No newline at end of file diff --git a/src/lib/ldb/staff/staff-ldb.svelte b/src/lib/ldb/staff/staff-ldb.svelte index b5cab68..f914932 100644 --- a/src/lib/ldb/staff/staff-ldb.svelte +++ b/src/lib/ldb/staff/staff-ldb.svelte @@ -1,11 +1,10 @@ @@ -56,7 +39,7 @@ {/if} {/key} -{#await fetchStaffLdb(station)} +{#await callFetch(station)} {:then data} {#if data} diff --git a/src/lib/ldb/staff/table/table-generator.svelte b/src/lib/ldb/staff/table/table-generator.svelte index 675bcad..268b057 100644 --- a/src/lib/ldb/staff/table/table-generator.svelte +++ b/src/lib/ldb/staff/table/table-generator.svelte @@ -89,6 +89,13 @@ plat: platArr.join(' ') }; } + + function fmtTime(date: Date | undefined): string | false { + if (!date) return false; // Handle null or undefined dates + const hours = date.getHours().toString().padStart(2, '0'); + const minutes = date.getMinutes().toString().padStart(2, '0'); + return `${hours}:${minutes}`; + }

Your display is too small to view this data

@@ -120,13 +127,13 @@ {#await formatLocations(service.origin) then origin}{origin}{/await} {#await formatLocations(service.destination) then dest}{dest}{/await} {service.platform || '-'} - {service?.sta || '-'} + {fmtTime(service?.sta) || '-'} - {service.eta || service.ata || '-'} + {fmtTime(service.eta) || fmtTime(service.ata) || '-'} - {service.std || '-'} + {fmtTime(service.std) || '-'} - {service.etd || service.atd || '-'} + {fmtTime(service.etd) || fmtTime(service.atd) || '-'} {/await} @@ -144,9 +151,6 @@ {/if} - - Unable to display service - {/each}