fix csv endpoint

This commit is contained in:
Emily
2024-10-08 15:24:23 +02:00
parent 79e956e930
commit 62c72b3ff9
8 changed files with 24 additions and 146 deletions

View File

@@ -4,7 +4,7 @@ import type { MetricsCounts } from '~/server/api/metrics/[project_id]/counts';
definePageMeta({ layout: 'dashboard' });
const {project} = useProject();
const { project } = useProject();
const isPremium = computed(() => (project.value?.premium_type || 0) > 0);
@@ -28,9 +28,9 @@ const itemsPerPage = 50;
const totalItems = computed(() => metricsInfo.value);
const { data: tableData, pending: loadingData } = await useLazyFetch<any[]>(() =>
const { data: tableData, pending: loadingData } = await useFetch<any[]>(() =>
`/api/metrics/${project.value?._id}/query?type=1&orderBy=${sort.value.column}&order=${sort.value.direction}&page=${page.value}&limit=${itemsPerPage}`, {
...signHeaders(),
...signHeaders(), lazy: true
})
onMounted(async () => {
@@ -42,7 +42,9 @@ const creatingCsv = ref<boolean>(false);
async function downloadCSV() {
creatingCsv.value = true;
const result = await $fetch(`/api/project/generate_csv?mode=events&slice=${options.indexOf(selectedTimeFrom.value)}`, signHeaders());
const result = await $fetch(`/api/project/generate_csv?mode=events&slice=${options.indexOf(selectedTimeFrom.value)}`, {
headers: useComputedHeaders({ useSnapshotDates: false }).value
});
const blob = new Blob([result as any], { type: 'text/csv' });
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');