Files
fotospiel-app/resources/js/guest-v2/services/tasksApi.ts
2026-02-02 13:01:20 +01:00

27 lines
824 B
TypeScript

import { fetchJson } from './apiClient';
import { getDeviceId } from '../lib/device';
export type TaskItem = Record<string, unknown>;
type TaskResponse = {
data?: TaskItem[];
};
export async function fetchTasks(eventToken: string, options: { locale?: string; page?: number; perPage?: number } = {}) {
const params = new URLSearchParams();
if (options.locale) params.set('locale', options.locale);
if (options.page) params.set('page', String(options.page));
if (options.perPage) params.set('per_page', String(options.perPage));
const response = await fetchJson<TaskResponse>(
`/api/v1/events/${encodeURIComponent(eventToken)}/tasks${params.toString() ? `?${params.toString()}` : ''}`,
{
headers: {
'X-Device-Id': getDeviceId(),
},
}
);
return response.data?.data ?? [];
}