export type PromocodesPayloadDto = {promocodes: Array, expirationDate: string, discount: number, type?: string | undefined, inUse?: boolean | undefined}; export type CreateApiApiV1PromocodesArgs = {expirationDate?: string | undefined, discount?: string | undefined, type?: string | undefined, inUse?: boolean | undefined, body: PromocodesPayloadDto}; export type CreateApiApiV1PromocodesOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Upload promotional codes * * POST /api/v1/promocodes */ export const createApiApiV1Promocodes = async (args: CreateApiApiV1PromocodesArgs, options?: CreateApiApiV1PromocodesOptions) => { const {baseUrl = "https://api.reteno.com", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args.expirationDate != null) query.append("expirationDate", String(args.expirationDate)) if (args.discount != null) query.append("discount", String(args.discount)) if (args.type != null) query.append("type", String(args.type)) if (args.inUse != null) query.append("inUse", String(args.inUse)) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/promocodes${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };