From 930128c0d4efda82013b91b6399b059b248939e3 Mon Sep 17 00:00:00 2001 From: Regalijan Date: Sat, 11 Apr 2026 03:50:41 -0400 Subject: [PATCH] Migrate reports submission --- functions/api/reports/submit.ts | 41 ++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/functions/api/reports/submit.ts b/functions/api/reports/submit.ts index a387eaa..fef6420 100644 --- a/functions/api/reports/submit.ts +++ b/functions/api/reports/submit.ts @@ -225,26 +225,31 @@ export async function onRequestPost(context: RequestContext) { attachments.push(new URL(urlResult.value).pathname.replace(/^\/?t?\//, "")); } - await context.env.D1.prepare( - "INSERT INTO reports (attachments, created_at, id, open, target_ids, target_usernames, type, user) VALUES (?, ?, ?, 1, ?, ?, ?, ?);", - ) - .bind( - JSON.stringify(attachments), - Date.now(), - reportId, - JSON.stringify(metaIDs), - JSON.stringify(metaNames), - submissionType, - currentUser ? JSON.stringify(currentUser) : null, - ) - .run(); + await context.data.prisma.report.create({ + data: { + attachments, + id: reportId, + target_ids: metaIDs, + target_usernames: metaNames, + type: submissionType, + user: currentUser + ? { + email: currentUser.email, + id: currentUser.id, + username: currentUser.username, + } + : undefined, + }, + }); if (typeof senderTokenId === "string") - await context.env.D1.prepare( - "INSERT INTO push_notifications (created_at, event_id, event_type, token) VALUES (?, ?, ?, ?);", - ) - .bind(Date.now(), reportId, "report", senderTokenId) - .run(); + await context.data.prisma.pushNotification.create({ + data: { + event_id: reportId, + event_type: reportId, + token: senderTokenId, + }, + }); return jsonResponse( JSON.stringify({ id: reportId, upload_urls: uploadUrls }),