export type GetApiNewsTypesArgs = {tagresources?: number | undefined, location?: number | undefined, future?: number | undefined, ongoing?: number | undefined, search?: string | undefined, limit?: number | undefined, page?: number | undefined, order?: ('id' | 'motd' | 'datetimecreated' | 'datetimeremoved') | undefined, order_dir?: ('asc' | 'desc') | undefined}; export type GetApiNewsTypesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Display a listing of news article types * * GET /news/types */ export const getApiNewsTypes = async (args: GetApiNewsTypesArgs, options?: GetApiNewsTypesOptions) => { const {baseUrl = "https://www.rcac.purdue.edu/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.tagresources != null) query.append("tagresources", String(args.tagresources)) if (args.location != null) query.append("location", String(args.location)) if (args.future != null) query.append("future", String(args.future)) if (args.ongoing != null) query.append("ongoing", String(args.ongoing)) if (args.search != null) query.append("search", String(args.search)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.page != null) query.append("page", String(args.page)) if (args.order != null) query.append("order", String(args.order)) if (args.order_dir != null) query.append("order_dir", String(args.order_dir)) const url = `${baseUrl.replace(/\/+$/, '')}/news/types${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 (await res.json()) as unknown };