export type GetApiApiGrantsSearchArgs = {keyword?: string | undefined, prefecture?: string | undefined, municipality_code?: string | undefined, open_only?: boolean | undefined, min_amount?: number | undefined, sort?: ('relevance' | 'deadline_asc' | 'amount_desc' | 'newest') | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiApiGrantsSearchOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * 補助金を検索 * * GET /api/grants/search */ export const getApiApiGrantsSearch = async (args: GetApiApiGrantsSearchArgs, options?: GetApiApiGrantsSearchOptions) => { const {baseUrl = "https://localgov.jp", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.keyword != null) query.append("keyword", String(args.keyword)) if (args.prefecture != null) query.append("prefecture", String(args.prefecture)) if (args.municipality_code != null) query.append("municipality_code", String(args.municipality_code)) if (args.open_only != null) query.append("open_only", String(args.open_only)) if (args.min_amount != null) query.append("min_amount", String(args.min_amount)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) const url = `${baseUrl.replace(/\/+$/, '')}/api/grants/search${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 };