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 }),