From b60f211d7b8c6f981e713f840d496bdde52994f8 Mon Sep 17 00:00:00 2001 From: Regalijan Date: Sat, 11 Apr 2026 04:29:15 -0400 Subject: [PATCH] Migrate report recall endpoint --- functions/api/reports/recall.ts | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/functions/api/reports/recall.ts b/functions/api/reports/recall.ts index 9a69106..226d301 100644 --- a/functions/api/reports/recall.ts +++ b/functions/api/reports/recall.ts @@ -15,26 +15,27 @@ export async function onRequestPost(context: RequestContext) { ) return jsonError("No processing report with that ID found", 404); - const data: Record | null = await context.env.D1.prepare( - "SELECT attachments FROM reports WHERE id = ?;", - ) - .bind(id) - .first(); + const data = await context.data.prisma.report.findUnique({ + select: { + attachments: true, + }, + where: { + id, + }, + }); if (!data) return jsonError("No report with that ID found", 404); - data.attachments = JSON.parse(data.attachments); - const accessToken = await GetAccessToken(context.env); const attachmentDeletePromises = []; - const existingAttachments = [...data.attachments]; + const existingAttachments = [...(data.attachments as string[])]; - for (const attachment of existingAttachments) { - if (!attachment.startsWith("t/")) data.attachments.push(`t/${attachment}`); - else data.attachments.push(attachment.replace("t/", "")); + for (let i = 0; i < existingAttachments.length; i++) { + if (!existingAttachments[i].startsWith("t/")) + existingAttachments[i] = existingAttachments[i].replace("t/", ""); } - for (const attachment of data.attachments) + for (const attachment of existingAttachments) attachmentDeletePromises.push( fetch( `https://storage.googleapis.com/storage/v1/b/portal-carcrushers-cc/o/${encodeURIComponent( @@ -50,9 +51,11 @@ export async function onRequestPost(context: RequestContext) { ); await Promise.allSettled(attachmentDeletePromises); - await context.env.D1.prepare("DELETE FROM reports WHERE id = ?;") - .bind(id) - .run(); + await context.data.prisma.report.delete({ + where: { + id, + }, + }); return new Response(null, { status: 204,