export type CreateApiWorksitesArgs = {body: {name: string, address: string, city?: string | undefined, state?: string | undefined, postal_code?: string | undefined, phone1?: string | undefined, incident: number, location: {type?: 'Point' | undefined, coordinates?: Array | undefined}, work_types?: (Array<{work_type?: string | undefined, status?: string | undefined}>) | undefined}}; export type CreateApiWorksitesOptions = {baseUrl?: string | undefined, Token?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create worksite * * POST /worksites */ export const createApiWorksites = async (args: CreateApiWorksitesArgs, options?: CreateApiWorksitesOptions) => { const {baseUrl = "https://crisiscleanup-3-api-production.up.railway.app", fetch: fetchFn = fetch, Token} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (Token !== undefined) headers.set("Authorization", Token) const url = `${baseUrl.replace(/\/+$/, '')}/worksites${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 };