forked from Transparency/kgroad-frontend2
36 lines
711 B
TypeScript
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,
|
|
};
|
|
};
|