export type PatchApiPromocodesIdArgs = {id: number, body: {name?: string | undefined, promocode_type?: ('other' | 'first_ticket') | undefined, discount_type?: ('fixed' | 'percent') | undefined, discount_value?: number | undefined, user_email?: number | undefined, usage_limit?: number | undefined, expires_at?: string | undefined}}; export type PatchApiPromocodesIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Update promocode * * PATCH /promocodes/{id} */ export const patchApiPromocodesId = async (args: PatchApiPromocodesIdArgs, options?: PatchApiPromocodesIdOptions) => { const {baseUrl = "http://api.gostarmartbus.com/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/x-www-form-urlencoded") const url = `${baseUrl.replace(/\/+$/, '')}/promocodes/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: new URLSearchParams(Object.entries(args.body).flatMap(([key, value]) => (value == null ? [] : [[key, String(value)]])))}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };