mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-09 23:48:36 +01:00
fix csv endpoint
This commit is contained in:
8
TODO
8
TODO
@@ -1,10 +1,8 @@
|
|||||||
|
|
||||||
|
|
||||||
- Fix devices Dashboard card, replace empty with "unkwnwn"
|
- Reactivity on project delete (update dropdown) + test guest
|
||||||
- Component first interaction must make the request inside
|
|
||||||
- Reactivity on project delete (update dropdown)
|
- Devices remove empty (Fix devices Dashboard card, replace empty with "unkwnwn")
|
||||||
- Fix CSV Endpoint
|
|
||||||
- Devices remove empty
|
|
||||||
- docs vertical navigation not wfull
|
- docs vertical navigation not wfull
|
||||||
- project creation
|
- project creation
|
||||||
- Event funnel / metadata analyzer / user flow
|
- Event funnel / metadata analyzer / user flow
|
||||||
|
|||||||
@@ -28,9 +28,9 @@ const itemsPerPage = 50;
|
|||||||
const totalItems = computed(() => metricsInfo.value);
|
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}`, {
|
`/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 () => {
|
onMounted(async () => {
|
||||||
@@ -42,7 +42,9 @@ const creatingCsv = ref<boolean>(false);
|
|||||||
|
|
||||||
async function downloadCSV() {
|
async function downloadCSV() {
|
||||||
creatingCsv.value = true;
|
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 blob = new Blob([result as any], { type: 'text/csv' });
|
||||||
const url = window.URL.createObjectURL(blob);
|
const url = window.URL.createObjectURL(blob);
|
||||||
const a = document.createElement('a');
|
const a = document.createElement('a');
|
||||||
|
|||||||
@@ -1,74 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
|
|
||||||
definePageMeta({ layout: 'dashboard' });
|
|
||||||
|
|
||||||
const activeProject = useActiveProject();
|
|
||||||
|
|
||||||
const router = useRouter();
|
|
||||||
|
|
||||||
const newProjectName = ref<string>(activeProject.value?.name || "");
|
|
||||||
|
|
||||||
async function deleteProject(projectId: string, projectName: string) {
|
|
||||||
const sure = confirm(`Are you sure to delete the project ${projectName} ?`);
|
|
||||||
if (!sure) return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
await $fetch('/api/project/delete', {
|
|
||||||
method: 'DELETE',
|
|
||||||
...signHeaders({ 'Content-Type': 'application/json' }),
|
|
||||||
body: JSON.stringify({ project_id: projectId })
|
|
||||||
});
|
|
||||||
// await refresh();
|
|
||||||
// setActiveProject(0);
|
|
||||||
router.push('/')
|
|
||||||
} catch (ex: any) {
|
|
||||||
alert(ex.message);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
|
||||||
<template>
|
|
||||||
|
|
||||||
<div class="settings w-full">
|
|
||||||
|
|
||||||
<div class="flex flex-col justify-center mt-16 gap-10 px-10">
|
|
||||||
|
|
||||||
<div class="text-text font-bold text-[1.5rem]"> Settings </div>
|
|
||||||
|
|
||||||
<div class="flex gap-4 items-center text-[1.2rem] text-text-sub">
|
|
||||||
<div class="font-semibold"> Name: </div>
|
|
||||||
<div>
|
|
||||||
<input v-model="newProjectName" type="text" class="px-4 py-1 rounded-lg">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="flex mt-10">
|
|
||||||
<div @click="deleteProject(((activeProject?._id || '') as string), (activeProject?.name || ''))"
|
|
||||||
class="bg-[#bd4747] hover:bg-[#c94b4b] rounded-lg px-6 py-2 text-white text-[.9rem] font-semibold inter cursor-pointer">
|
|
||||||
Delete
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</template>
|
|
||||||
|
|
||||||
|
|
||||||
<style scoped lang="scss">
|
|
||||||
input:focus {
|
|
||||||
outline: none;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -34,9 +34,9 @@ const itemsPerPage = 50;
|
|||||||
const totalItems = computed(() => metricsInfo.value);
|
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=0&orderBy=${sort.value.column}&order=${sort.value.direction}&page=${page.value}&limit=${itemsPerPage}`, {
|
`/api/metrics/${project.value?._id}/query?type=0&orderBy=${sort.value.column}&order=${sort.value.direction}&page=${page.value}&limit=${itemsPerPage}`, {
|
||||||
...signHeaders(),
|
...signHeaders(), lazy: true
|
||||||
})
|
})
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
@@ -49,7 +49,9 @@ const creatingCsv = ref<boolean>(false);
|
|||||||
|
|
||||||
async function downloadCSV() {
|
async function downloadCSV() {
|
||||||
creatingCsv.value = true;
|
creatingCsv.value = true;
|
||||||
const result = await $fetch(`/api/project/generate_csv?mode=visits&slice=${options.indexOf(selectedTimeFrom.value)}`, signHeaders());
|
const result = await $fetch(`/api/project/generate_csv?mode=visits&slice=${options.indexOf(selectedTimeFrom.value)}`, {
|
||||||
|
headers: useComputedHeaders({ useSnapshotDates: false }).value
|
||||||
|
});
|
||||||
const blob = new Blob([result as any], { type: 'text/csv' });
|
const blob = new Blob([result as any], { type: 'text/csv' });
|
||||||
const url = window.URL.createObjectURL(blob);
|
const url = window.URL.createObjectURL(blob);
|
||||||
const a = document.createElement('a');
|
const a = document.createElement('a');
|
||||||
|
|||||||
@@ -85,7 +85,8 @@ const showDashboard = computed(() => project.value && firstInteraction.data.valu
|
|||||||
<FirstInteraction v-if="!justLogged" :refresh-interaction="firstInteraction.refresh"
|
<FirstInteraction v-if="!justLogged" :refresh-interaction="firstInteraction.refresh"
|
||||||
:first-interaction="(firstInteraction.data.value || false)"></FirstInteraction>
|
:first-interaction="(firstInteraction.data.value || false)"></FirstInteraction>
|
||||||
|
|
||||||
<div class="text-text/85 mt-8 ml-8 poppis text-[1.2rem]" v-if="projectList && projectList.length == 0 && !justLogged">
|
<div class="text-text/85 mt-8 ml-8 poppis text-[1.2rem]"
|
||||||
|
v-if="projectList && projectList.length == 0 && !justLogged">
|
||||||
Create your first project...
|
Create your first project...
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
|
|
||||||
import { ProjectModel } from "@schema/ProjectSchema";
|
|
||||||
import { UserModel } from "@schema/UserSchema";
|
import { UserModel } from "@schema/UserSchema";
|
||||||
import { UserSettingsModel } from "@schema/UserSettings";
|
|
||||||
import { EventModel } from '@schema/metrics/EventSchema';
|
|
||||||
import { VisitModel } from "@schema/metrics/VisitSchema";
|
import { VisitModel } from "@schema/metrics/VisitSchema";
|
||||||
|
|
||||||
import { google } from 'googleapis';
|
import { google } from 'googleapis';
|
||||||
@@ -60,16 +58,10 @@ async function exportToGoogle(data: string, user_id: string) {
|
|||||||
|
|
||||||
export default defineEventHandler(async event => {
|
export default defineEventHandler(async event => {
|
||||||
|
|
||||||
const userData = getRequestUser(event);
|
const data = await getRequestData(event, { requireSchema: false });
|
||||||
if (!userData?.logged) return setResponseStatus(event, 400, 'NotLogged');
|
if (!data) return;
|
||||||
|
|
||||||
const currentActiveProject = await UserSettingsModel.findOne({ user_id: userData.id });
|
const { project, project_id, user } = data;
|
||||||
if (!currentActiveProject) return setResponseStatus(event, 400, 'You need to select a project');
|
|
||||||
|
|
||||||
const project_id = currentActiveProject.active_project_id;
|
|
||||||
|
|
||||||
const project = await ProjectModel.findById(project_id);
|
|
||||||
if (!project) return setResponseStatus(event, 400, 'Project not found');
|
|
||||||
|
|
||||||
const PREMIUM_TYPE = project.premium_type;
|
const PREMIUM_TYPE = project.premium_type;
|
||||||
|
|
||||||
@@ -127,7 +119,7 @@ export default defineEventHandler(async event => {
|
|||||||
const isGoogle = getHeader(event, 'x-google-export');
|
const isGoogle = getHeader(event, 'x-google-export');
|
||||||
|
|
||||||
if (isGoogle === 'true') {
|
if (isGoogle === 'true') {
|
||||||
const data = await exportToGoogle(result, userData.id);
|
const data = await exportToGoogle(result, user.id);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
import { AuthContext, AuthContextLogged } from "~/server/middleware/01-authorization";
|
|
||||||
import { ProjectModel } from "@schema/ProjectSchema";
|
|
||||||
import { UserSettingsModel } from "@schema/UserSettings";
|
|
||||||
|
|
||||||
export default defineEventHandler(async event => {
|
|
||||||
|
|
||||||
const userData = getRequestUser(event);
|
|
||||||
if (!userData?.logged) return;
|
|
||||||
|
|
||||||
const userSettings = await UserSettingsModel.findOne({ user_id: userData.id }, {
|
|
||||||
active_project_id: 1
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!userSettings) {
|
|
||||||
const projectOwned = await ProjectModel.findOne({ owner: userData.id }, { _id: 1 });
|
|
||||||
return projectOwned?._id.toString();
|
|
||||||
}
|
|
||||||
return userSettings?.active_project_id.toString();
|
|
||||||
});
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
|
|
||||||
import { ProjectModel } from "@schema/ProjectSchema";
|
|
||||||
|
|
||||||
import { UserSettingsModel } from "@schema/UserSettings";
|
|
||||||
import { hasAccessToProject } from "~/server/utils/hasAccessToProject";
|
|
||||||
|
|
||||||
export default defineEventHandler(async event => {
|
|
||||||
|
|
||||||
if (!event.context) return;
|
|
||||||
|
|
||||||
const userData = getRequestUser(event);
|
|
||||||
if (!userData?.logged) return;
|
|
||||||
|
|
||||||
const { project_id } = getQuery(event);
|
|
||||||
|
|
||||||
const [hasAccess] = await hasAccessToProject(userData.id, project_id as string);
|
|
||||||
|
|
||||||
if (!hasAccess) return setResponseStatus(event, 400, 'No access to project');
|
|
||||||
|
|
||||||
await UserSettingsModel.updateOne({ user_id: userData.id }, { active_project_id: project_id }, { upsert: true });
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user