New-Thanasoft/thanasoft-front/src/stores/financialStatisticsStore.ts
2026-05-11 13:30:24 +03:00

51 lines
1.4 KiB
TypeScript

import { defineStore } from "pinia";
import { ref, computed } from "vue";
import FinancialStatisticsService from "@/services/financialStatistics";
import type { FinancialStatistics } from "@/services/financialStatistics";
export const useFinancialStatisticsStore = defineStore(
"financialStatistics",
() => {
const statistics = ref<FinancialStatistics | null>(null);
const loading = ref(false);
const error = ref<string | null>(null);
const isLoading = computed(() => loading.value);
const hasError = computed(() => error.value !== null);
const getError = computed(() => error.value);
const hasData = computed(() => statistics.value !== null);
async function fetchStatistics(): Promise<void> {
loading.value = true;
error.value = null;
try {
statistics.value = await FinancialStatisticsService.getStatistics();
} catch (err: unknown) {
error.value =
err instanceof Error
? err.message
: "Erreur lors du chargement des statistiques financières.";
} finally {
loading.value = false;
}
}
function clearStatistics(): void {
statistics.value = null;
error.value = null;
}
return {
statistics,
loading,
error,
isLoading,
hasError,
getError,
hasData,
fetchStatistics,
clearStatistics,
};
}
);