export type GetApiUsersArgs = {username?: string | undefined, access_id?: number | undefined, counter_id?: number | undefined, role?: ('staff' | 'agent' | 'client') | undefined, q_select?: Array | undefined}; export type GetApiUsersOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get list of users. Need role: staff * * GET /users */ export const getApiUsers = async (args: GetApiUsersArgs, options?: GetApiUsersOptions) => { const {baseUrl = "http://api.gostarmartbus.com/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.username != null) query.append("username", String(args.username)) if (args.access_id != null) query.append("access_id", String(args.access_id)) if (args.counter_id != null) query.append("counter_id", String(args.counter_id)) if (args.role != null) query.append("role", String(args.role)) for (const item of args.q_select ?? []) query.append("q_select", String(item)) const url = `${baseUrl.replace(/\/+$/, '')}/users${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 };