40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { create } from 'axios';
|
|
import { ref } from 'vue';
|
|
import HistoryData = App.Features.History.Data.HistoryData;
|
|
import moment from 'moment';
|
|
|
|
export default function useHistoryViewModel() {
|
|
const isLoading = ref<boolean>(false);
|
|
const historyData = ref<HistoryData>();
|
|
|
|
function getHistoryData(date: string) {
|
|
isLoading.value = true;
|
|
|
|
const client = create();
|
|
client
|
|
.get<HistoryData>('/api/history', {
|
|
params: {
|
|
date,
|
|
},
|
|
})
|
|
.then((res) => {
|
|
console.log(
|
|
res.data?.electricity.flatMap((e) => {
|
|
if (!e.totalPriceTaxIncluded) {
|
|
return;
|
|
}
|
|
|
|
return {
|
|
label: moment(e.startDate).format('DD-MM-YYYY'),
|
|
value: e.totalPriceTaxIncluded?.toPrecision(2),
|
|
};
|
|
}),
|
|
);
|
|
historyData.value = res.data;
|
|
})
|
|
.finally(() => (isLoading.value = false));
|
|
}
|
|
|
|
return { isLoading, historyData, getHistoryData };
|
|
}
|