31 lines
866 B
TypeScript
31 lines
866 B
TypeScript
import { create } from 'axios';
|
|
import { ref } from 'vue';
|
|
import HistoryData = App.Features.History.Data.HistoryData;
|
|
|
|
export default function useHistoryViewModel() {
|
|
const isLoading = ref<boolean>(false);
|
|
const error = ref<string>();
|
|
const historyData = ref<HistoryData>();
|
|
|
|
function getHistoryData(date: string) {
|
|
isLoading.value = true;
|
|
|
|
const client = create();
|
|
client
|
|
.get<HistoryData>('/api/history', {
|
|
params: {
|
|
date,
|
|
},
|
|
})
|
|
.then((res) => {
|
|
historyData.value = res.data;
|
|
})
|
|
.catch((err) => {
|
|
error.value = err.response.data.message;
|
|
})
|
|
.finally(() => (isLoading.value = false));
|
|
}
|
|
|
|
return { isLoading, historyData, error, getHistoryData };
|
|
}
|