kgroad-frontend2/src/widgets/StatisticsSection/statisticsSection.store.ts
Vladislav Khorev e0e2f5470d renamed folders
2024-02-14 08:04:02 +00:00

36 lines
711 B
TypeScript

import { apiInstance } from "@/shared/config/apiConfig";
import { AxiosError } from "axios";
interface IStatsCount {
category: number;
count: number;
}
export const statiscsSectionStore = () => {
let errorMessage = "";
async function getStatsCount() {
try {
const response = await apiInstance.get<IStatsCount[]>(
"/report/category_count/"
);
return response.data;
} catch (error: unknown) {
if (error instanceof AxiosError) {
errorMessage = error.message;
} else {
errorMessage = "An error ocured";
}
}
}
function getErrorMessage() {
return errorMessage;
}
return {
getStatsCount,
getErrorMessage,
};
};