42 lines
1009 B
TypeScript
42 lines
1009 B
TypeScript
import { getDeviceId } from '../lib/device';
|
|
|
|
export interface EventData {
|
|
id: number;
|
|
slug: string;
|
|
name: string;
|
|
default_locale: string;
|
|
created_at: string;
|
|
updated_at: string;
|
|
type?: {
|
|
slug: string;
|
|
name: string;
|
|
icon: string;
|
|
};
|
|
}
|
|
|
|
export interface EventStats {
|
|
onlineGuests: number;
|
|
tasksSolved: number;
|
|
latestPhotoAt: string | null;
|
|
}
|
|
|
|
export async function fetchEvent(slug: string): Promise<EventData> {
|
|
const res = await fetch(`/api/v1/events/${slug}`);
|
|
if (!res.ok) throw new Error('Event fetch failed');
|
|
return await res.json();
|
|
}
|
|
|
|
export async function fetchStats(slug: string): Promise<EventStats> {
|
|
const res = await fetch(`/api/v1/events/${slug}/stats`, {
|
|
headers: {
|
|
'X-Device-Id': getDeviceId(),
|
|
},
|
|
});
|
|
if (!res.ok) throw new Error('Stats fetch failed');
|
|
const json = await res.json();
|
|
return {
|
|
onlineGuests: json.onlineGuests ?? 0,
|
|
tasksSolved: json.tasksSolved ?? 0,
|
|
latestPhotoAt: json.latestPhotoAt ?? null,
|
|
};
|
|
} |