export type GetApiApiV1JobsArgs = {take?: number | undefined, skip?: number | undefined, order?: ('ASC' | 'DESC') | undefined, status: Array, type: Array}; export type GetApiApiV1JobsOptions = {baseUrl: string, LocalUserJWT?: string | undefined, fetch?: typeof fetch | undefined}; /** * 🛡️ Fetch server jobs. * * GET /api/v1/jobs */ export const getApiApiV1Jobs = async (args: GetApiApiV1JobsArgs, options: GetApiApiV1JobsOptions) => { const {baseUrl, fetch: fetchFn = fetch, LocalUserJWT} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.take != null) query.append("take", String(args.take)) if (args.skip != null) query.append("skip", String(args.skip)) if (args.order != null) query.append("order", String(args.order)) for (const item of args.status ?? []) query.append("status", String(item)) for (const item of args.type ?? []) query.append("type", String(item)) if (LocalUserJWT !== undefined) headers.set('authorization', `Bearer ${LocalUserJWT}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/jobs${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };