Skip to content

Commit f86a399

Browse files
committed
fix snapshots
1 parent 36c4406 commit f86a399

File tree

7 files changed

+20
-37
lines changed

7 files changed

+20
-37
lines changed

dashboard/components/CVerticalNavigation.vue

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const { createAlert } = useAlert()
5656
async function deleteSnapshot(close: () => any) {
5757
await $fetch("/api/snapshot/delete", {
5858
method: 'DELETE',
59-
...signHeaders({ 'Content-Type': 'application/json' }),
59+
headers: useComputedHeaders({ useSnapshotDates: false }).value,
6060
body: JSON.stringify({
6161
id: snapshot.value._id.toString(),
6262
})
@@ -71,11 +71,7 @@ async function generatePDF() {
7171
7272
try {
7373
const res = await $fetch<Blob>('/api/project/generate_pdf', {
74-
...signHeaders({
75-
'x-snapshot-name': snapshot.value.name,
76-
'x-from': snapshot.value.from.toISOString(),
77-
'x-to': snapshot.value.to.toISOString(),
78-
}),
74+
headers: useComputedHeaders({ useSnapshotDates: false, custom: { 'x-snapshot-name': snapshot.value.name } }).value,
7975
responseType: 'blob'
8076
});
8177
@@ -149,8 +145,8 @@ const pricingDrawer = usePricingDrawer();
149145
</div>
150146
</LyxUiButton>
151147

152-
<LyxUiButton v-if="projectList && (projectList.length >= (maxProjects || 1))"
153-
type="outlined" class="w-full py-1 mt-2 text-[.7rem]">
148+
<LyxUiButton v-if="projectList && (projectList.length >= (maxProjects || 1))" type="outlined"
149+
class="w-full py-1 mt-2 text-[.7rem]">
154150
<div class="flex items-center gap-2 justify-center">
155151
<div><i class="text-lyx-text-darker far fa-lock"></i></div>
156152
<div class="text-lyx-text-darker"> Projects limit reached </div>

dashboard/components/dialog/CreateSnapshot.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const { createAlert } = useAlert()
4242
async function confirmSnapshot() {
4343
await $fetch("/api/snapshot/create", {
4444
method: 'POST',
45-
...signHeaders({ 'Content-Type': 'application/json' }),
45+
headers: useComputedHeaders({ useSnapshotDates: false }).value,
4646
body: JSON.stringify({
4747
name: snapshotName.value,
4848
color: currentColor.value,

dashboard/server/api/keys/create.post.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11

22
import { getUserProjectFromId } from "~/server/LIVE_DEMO_DATA";
33
import { ApiSettingsModel, TApiSettings } from "@schema/ApiSettingsSchema";
4-
import { UserSettingsModel } from "@schema/UserSettings";
54
import { ProjectModel } from "@schema/ProjectSchema";
65

76
import crypto from 'crypto';

dashboard/server/api/project/generate_pdf.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import pdfkit from 'pdfkit';
44
import { PassThrough } from 'node:stream';
55

66
import { ProjectModel } from "@schema/ProjectSchema";
7-
import { UserSettingsModel } from "@schema/UserSettings";
87
import { VisitModel } from '@schema/metrics/VisitSchema';
98
import { EventModel } from '@schema/metrics/EventSchema';
109

@@ -82,15 +81,13 @@ function createPdf(data: PDFGenerationData) {
8281

8382
export default defineEventHandler(async event => {
8483

84+
const data = await getRequestData(event, { requireSchema: false, allowGuests: true, requireRange: false });
85+
if (!data) return;
86+
8587
const userData = getRequestUser(event);
8688
if (!userData?.logged) return setResponseStatus(event, 400, 'NotLogged');
8789

88-
const currentActiveProject = await UserSettingsModel.findOne({ user_id: userData.id });
89-
if (!currentActiveProject) return setResponseStatus(event, 400, 'You need to select a project');
90-
91-
const project_id = currentActiveProject.active_project_id;
92-
93-
const project = await ProjectModel.findById(project_id);
90+
const project = await ProjectModel.findById(data.project_id);
9491
if (!project) return setResponseStatus(event, 400, 'Project not found');
9592

9693
const snapshotHeader = getHeader(event, 'x-snapshot-name');

dashboard/server/api/project/members/list.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { ProjectModel } from "@schema/ProjectSchema";
22
import { TeamMemberModel } from "@schema/TeamMemberSchema";
33
import { UserModel } from "@schema/UserSchema";
4-
import { UserSettingsModel } from "@schema/UserSettings";
5-
import StripeService from '~/server/services/StripeService';
4+
65

76
export default defineEventHandler(async event => {
87

dashboard/server/api/snapshot/create.post.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { ProjectModel } from "@schema/ProjectSchema";
22
import { ProjectSnapshotModel } from "@schema/ProjectSnapshot";
3-
import { UserSettingsModel } from "@schema/UserSettings";
43

54

65
export default defineEventHandler(async event => {
76

7+
const data = await getRequestData(event, { requireSchema: false, allowGuests: true, requireRange: false });
8+
if (!data) return;
9+
810
const body = await readBody(event);
911

1012
const { name: newSnapshotName, from, to, color: snapshotColor } = body;
@@ -19,13 +21,8 @@ export default defineEventHandler(async event => {
1921
const userData = getRequestUser(event);
2022
if (!userData?.logged) return setResponseStatus(event, 400, 'NotLogged');
2123

22-
const userSettings = await UserSettingsModel.findOne({ user_id: userData.id }, { active_project_id: 1 });
23-
24-
if (!userSettings) return setResponseStatus(event, 500, 'Unkwnown error');
25-
26-
const currentProjectId = userSettings.active_project_id;
2724

28-
const project = await ProjectModel.findById(currentProjectId);
25+
const project = await ProjectModel.findById(data.project_id);
2926
if (!project) return setResponseStatus(event, 400, 'Project not found');
3027

3128

@@ -34,7 +31,7 @@ export default defineEventHandler(async event => {
3431
from: new Date(from),
3532
to: new Date(to),
3633
color: snapshotColor,
37-
project_id: currentProjectId
34+
project_id: data.project_id
3835
});
3936

4037
return newSnapshot.id;

dashboard/server/api/snapshot/delete.delete.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { ProjectModel } from "@schema/ProjectSchema";
22
import { ProjectSnapshotModel } from "@schema/ProjectSnapshot";
3-
import { UserSettingsModel } from "@schema/UserSettings";
43

54

65
export default defineEventHandler(async event => {
76

7+
const data = await getRequestData(event, { requireSchema: false, allowGuests: false, requireRange: false });
8+
if (!data) return;
9+
810
const body = await readBody(event);
911

1012
const { id: snapshotId } = body;
@@ -14,18 +16,11 @@ export default defineEventHandler(async event => {
1416
const userData = getRequestUser(event);
1517
if (!userData?.logged) return setResponseStatus(event, 400, 'NotLogged');
1618

17-
const userSettings = await UserSettingsModel.findOne({ user_id: userData.id }, { active_project_id: 1 });
18-
19-
if (!userSettings) return setResponseStatus(event, 500, 'Unkwnown error');
20-
21-
const currentProjectId = userSettings.active_project_id;
22-
23-
const project = await ProjectModel.findById(currentProjectId);
19+
const project = await ProjectModel.findById(data.project_id);
2420
if (!project) return setResponseStatus(event, 400, 'Project not found');
2521

26-
2722
const deletation = await ProjectSnapshotModel.deleteOne({
28-
project_id: currentProjectId,
23+
project_id: data.project_id,
2924
_id: snapshotId
3025
});
3126

0 commit comments

Comments
 (0)