27 lines
824 B
TypeScript
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 ?? [];
|
|
}
|