import { makeRequest } from "@frontend/kitui"; import { parseAxiosError } from "@utils/parse-error"; const apiUrl = process.env.REACT_APP_DOMAIN + "/squiz/statistic"; export type DevicesResponse = { device: Record; os: Record; browser: Record; }; export type GeneralResponse = { open: Record; result: Record; avtime: Record; conversation: Record; }; export type QuestionsResponse = { funnel: number[]; results: Record; questions: Record>; }; export const getDevices = async ( quizId: string, to: number, from: number, ): Promise<[DevicesResponse | null, string?]> => { try { const devicesResponse = await makeRequest({ method: "POST", url: `${apiUrl}/${quizId}/devices`, withCredentials: true, body: { to, from }, }); return [devicesResponse]; } catch (nativeError) { const [error] = parseAxiosError(nativeError); return [null, `Не удалось получить статистику о девайсах. ${error}`]; } }; export const getGeneral = async ( quizId: string, to: number, from: number, ): Promise<[GeneralResponse | null, string?]> => { try { const generalResponse = await makeRequest({ method: "POST", url: `${apiUrl}/${quizId}/general`, withCredentials: true, body: { to, from }, }); return [generalResponse]; } catch (nativeError) { const [error] = parseAxiosError(nativeError); return [null, `Не удалось получить ключевые метрики. ${error}`]; } }; export const getQuestions = async ( quizId: string, to: number, from: number, ): Promise<[QuestionsResponse | null, string?]> => { try { const questionsResponse = await makeRequest({ method: "POST", url: `${apiUrl}/${quizId}/questions`, withCredentials: true, body: { to, from }, }); return [questionsResponse]; } catch (nativeError) { const [error] = parseAxiosError(nativeError); return [null, `Не удалось получить статистику по результатам. ${error}`]; } };