Skip to content

Commit 15f3c06

Browse files
committed
fix mail sends on moderator panel and remove all logs
1 parent b683402 commit 15f3c06

18 files changed

Lines changed: 283 additions & 122 deletions

File tree

convex/document.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { v } from "convex/values"
22
import { mutation, query } from "./_generated/server"
33
import { Doc, Id } from "./_generated/dataModel"
44
import { generateRandomId } from "./genId"
5-
import { limitCreateDocument } from "./rateLimits"
65

76
export const archive = mutation({
87
args: {
@@ -257,7 +256,6 @@ export const getById = query({
257256
alwaysView: v.optional(v.boolean())
258257
},
259258
handler: async (ctx, args) => {
260-
console.log("Fetching document with ID:", args.documentId)
261259
const identity = await ctx.auth.getUserIdentity()
262260

263261
if (args.documentId === null) {
@@ -305,7 +303,6 @@ export const getDocumentCount = query({
305303
const identity = await ctx.auth.getUserIdentity()
306304

307305
if (!identity || !args.userId){
308-
console.log("args non")
309306
return null
310307
}
311308

@@ -326,7 +323,6 @@ export const getPublicDocumentCount = query({
326323
const identity = await ctx.auth.getUserIdentity()
327324

328325
if (!identity || !args.userId){
329-
console.log("args non")
330326
return null
331327
}
332328

@@ -348,7 +344,6 @@ export const getVerifiedDocumentCount = query({
348344
const identity = await ctx.auth.getUserIdentity()
349345

350346
if (!identity || !args.userId){
351-
console.log("args non")
352347
return null
353348
}
354349

server/documents/api.ts

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
// api.ts
2+
3+
import { CreateDocument, UpdateDocument } from "./types";
4+
5+
const API_URL = "http://localhost:5000"; // Адрес вашего FastAPI сервера
6+
7+
// Создание нового документа
8+
export const createDocument = async (doc: CreateDocument) => {
9+
const response = await fetch(`${API_URL}/documents/`, {
10+
method: "POST",
11+
headers: {
12+
"Content-Type": "application/json",
13+
},
14+
body: JSON.stringify(doc),
15+
});
16+
17+
if (!response.ok) {
18+
throw new Error("Failed to create document");
19+
}
20+
21+
const data = await response.json();
22+
return data as Document;
23+
};
24+
25+
// Получение документа по ID
26+
export const getDocumentById = async (id: string) => {
27+
const response = await fetch(`${API_URL}/documents/${id}`);
28+
29+
if (!response.ok) {
30+
throw new Error("Failed to fetch document");
31+
}
32+
33+
const data = await response.json();
34+
return data as Document;
35+
};
36+
37+
// Обновление документа
38+
export const updateDocument = async (id: string, updates: UpdateDocument) => {
39+
const response = await fetch(`${API_URL}/documents/${id}`, {
40+
method: "PATCH",
41+
headers: {
42+
"Content-Type": "application/json",
43+
},
44+
body: JSON.stringify(updates),
45+
});
46+
47+
if (!response.ok) {
48+
throw new Error("Failed to update document");
49+
}
50+
51+
const data = await response.json();
52+
return data as Document;
53+
};
54+
55+
// Удаление документа
56+
export const deleteDocument = async (id: string) => {
57+
const response = await fetch(`${API_URL}/documents/${id}`, {
58+
method: "DELETE",
59+
});
60+
61+
if (!response.ok) {
62+
throw new Error("Failed to delete document");
63+
}
64+
65+
const data = await response.json();
66+
return data as Document;
67+
};
68+
69+
// Получение списка документов (например, для боковой панели)
70+
export const getSidebarDocuments = async (userId: string, parentDocument?: string, publicSorted: boolean = false) => {
71+
const url = new URL(`${API_URL}/documents/sidebar/`);
72+
const params = new URLSearchParams();
73+
params.append("userId", userId);
74+
if (parentDocument) params.append("parentDocument", parentDocument);
75+
if (publicSorted) params.append("publicSorted", "true");
76+
77+
url.search = params.toString();
78+
79+
const response = await fetch(url.toString());
80+
81+
if (!response.ok) {
82+
throw new Error("Failed to fetch sidebar documents");
83+
}
84+
85+
const data = await response.json();
86+
return data as Document[];
87+
};
88+
89+
// Архивировать документ
90+
export const archiveDocument = async (id: string, userId: string) => {
91+
const response = await fetch(`${API_URL}/documents/${id}/archive`, {
92+
method: "POST",
93+
headers: {
94+
"Content-Type": "application/json",
95+
},
96+
body: JSON.stringify({ userId }),
97+
});
98+
99+
if (!response.ok) {
100+
throw new Error("Failed to archive document");
101+
}
102+
103+
const data = await response.json();
104+
return data as Document;
105+
};
106+
107+
// Восстановить документ
108+
export const restoreDocument = async (id: string, userId: string) => {
109+
const response = await fetch(`${API_URL}/documents/${id}/restore`, {
110+
method: "POST",
111+
headers: {
112+
"Content-Type": "application/json",
113+
},
114+
body: JSON.stringify({ userId }),
115+
});
116+
117+
if (!response.ok) {
118+
throw new Error("Failed to restore document");
119+
}
120+
121+
const data = await response.json();
122+
return data as Document;
123+
};
124+
125+
// Получить корзину с архивированными документами
126+
export const getTrashDocuments = async (userId: string) => {
127+
const response = await fetch(`${API_URL}/documents/trash/?userId=${userId}`);
128+
129+
if (!response.ok) {
130+
throw new Error("Failed to fetch trash documents");
131+
}
132+
133+
const data = await response.json();
134+
return data as Document[];
135+
};
136+
137+
// Получить количество документов
138+
export const getDocumentCount = async (userId: string) => {
139+
const response = await fetch(`${API_URL}/documents/count/?userId=${userId}`);
140+
141+
if (!response.ok) {
142+
throw new Error("Failed to fetch document count");
143+
}
144+
145+
const count = await response.json();
146+
return count as number;
147+
};

server/documents/types.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
export interface DocumentProps {
2+
_id: string;
3+
title: string;
4+
userId: string;
5+
lastEditor: string;
6+
creatorName: string;
7+
isArchived: boolean;
8+
isPublished: boolean;
9+
shortId?: string;
10+
content?: string;
11+
coverImage?: string;
12+
icon?: string;
13+
verified?: boolean;
14+
isShort?: boolean;
15+
}
16+
17+
export interface CreateDocument {
18+
title: string;
19+
parentDocument?: string;
20+
userId: string;
21+
lastEditor: string;
22+
creatorName: string;
23+
}
24+
25+
export interface UpdateDocument {
26+
title?: string;
27+
content?: string;
28+
coverImage?: string;
29+
icon?: string;
30+
isPublished?: boolean;
31+
parentDocument?: string | null;
32+
isArchived?: boolean;
33+
shortId?: string;
34+
verified?: boolean;
35+
}

server/mail/mail.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export async function sendMail({
1616
});
1717
return response.data;
1818
} catch (error) {
19-
console.error("Error sending email:", error);
2019
return null;
2120
}
2221
};

server/order/order.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export async function createOrder(
1919
});
2020
return response.data;
2121
} catch (error) {
22-
console.error("Error creating order:", error);
2322
return null;
2423
}
2524
};
@@ -31,7 +30,6 @@ export async function success(
3130
const response = await axios.put(`${API_URL}/order/success/${_id}`);
3231
return response.data;
3332
} catch (error) {
34-
console.error("Error successing order:", error);
3533
return null;
3634
}
3735
};

server/orgs/org.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export async function createOrg(
2929
});
3030
return response.data;
3131
} catch (error) {
32-
console.error("Error creating user:", error);
3332
return null;
3433
}
3534
};
@@ -39,7 +38,6 @@ export async function getByUsername(username: string): Promise<Org | null>{
3938
const response = await axios.get(`${API_URL}/orgs/by_username/${username}`);
4039
return response.data;
4140
} catch (error) {
42-
console.error("Error fetching user by username:", error);
4341
return null;
4442
}
4543
};
@@ -49,7 +47,6 @@ export async function getById(_id: string): Promise<Org | null>{
4947
const response = await axios.get(`${API_URL}/orgs/by_id/${_id}`);
5048
return response.data;
5149
} catch (error) {
52-
console.error("Error fetching user by id:", error);
5350
return null;
5451
}
5552
};
@@ -86,7 +83,6 @@ export async function updateOrg(
8683
});
8784
return response.data;
8885
} catch (error) {
89-
console.error("Error updating user:", error);
9086
return null;
9187
}
9288
};
@@ -103,7 +99,6 @@ export async function updateOrgBadge(
10399
});
104100
return response.data;
105101
} catch (error) {
106-
console.error("Error updating user badge:", error);
107102
return null;
108103
}
109104
}

server/orgs/request.tsx

Lines changed: 38 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -26,57 +26,49 @@ export function useRequestOrg() {
2626
const { id, name, createdAt, imageUrl, slug } = organization;
2727
let adminId = null;
2828
const membersList: string[] = [];
29+
const memberships = await organization.getMemberships();
2930

30-
try {
31-
const memberships = await organization.getMemberships();
32-
33-
memberships.data.forEach((member) => {
34-
if (member.role === "org:admin") {
35-
adminId = member.publicUserData.userId;
36-
}
37-
membersList.push(member.publicUserData.userId as string);
38-
});
39-
40-
if (id === undefined) return null;
31+
memberships.data.forEach((member) => {
32+
if (member.role === "org:admin") {
33+
adminId = member.publicUserData.userId;
34+
}
35+
membersList.push(member.publicUserData.userId as string);
36+
});
4137

42-
const existingOrg = await getById(id);
43-
if (!existingOrg) {
44-
const createdOrg = await createOrg(
45-
id,
46-
slug,
47-
adminId,
48-
createdAt,
49-
name,
50-
membersList,
51-
imageUrl || null,
52-
documentCount,
53-
documentPublicCount,
54-
documentVerifiedCount
55-
);
38+
if (id === undefined) return null;
5639

57-
console.log("Создана организация:", createdOrg);
58-
} else {
59-
const updatedOrg = await updateOrg(
60-
id,
61-
slug,
62-
adminId,
63-
name,
64-
imageUrl || null,
65-
null,
66-
null,
67-
documentCount,
68-
documentPublicCount,
69-
membersList,
70-
null,
71-
null,
72-
documentVerifiedCount
73-
);
40+
const existingOrg = await getById(id);
41+
if (!existingOrg) {
42+
const createdOrg = await createOrg(
43+
id,
44+
slug,
45+
adminId,
46+
createdAt,
47+
name,
48+
membersList,
49+
imageUrl || null,
50+
documentCount,
51+
documentPublicCount,
52+
documentVerifiedCount
53+
);
7454

75-
console.log("Обновлена организация:", updatedOrg);
55+
} else {
56+
const updatedOrg = await updateOrg(
57+
id,
58+
slug,
59+
adminId,
60+
name,
61+
imageUrl || null,
62+
null,
63+
null,
64+
documentCount,
65+
documentPublicCount,
66+
membersList,
67+
null,
68+
null,
69+
documentVerifiedCount
70+
);
7671
}
77-
} catch (error) {
78-
console.error("Произошла ошибка при создании или обновлении организации:", error);
79-
}
8072
};
8173

8274
createOrUpdateOrg();

0 commit comments

Comments
 (0)