From b054d4cf41536fbd8a32e2198083bc7cea8aef0b Mon Sep 17 00:00:00 2001 From: regalijan Date: Thu, 19 Oct 2023 16:51:20 -0400 Subject: [PATCH] Delete FCM token from KV on report action --- functions/api/reports/[id]/action.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/functions/api/reports/[id]/action.ts b/functions/api/reports/[id]/action.ts index e061265..b4ed1f9 100644 --- a/functions/api/reports/[id]/action.ts +++ b/functions/api/reports/[id]/action.ts @@ -43,10 +43,6 @@ export async function onRequestPost(context: RequestContext) { } reportData.open = false; - await context.env.DATA.put(`report_${reportId}`, JSON.stringify(reportData)); - await context.env.D1.prepare("UPDATE reports SET open = 0 WHERE id = ?;") - .bind(reportId) - .run(); if (user?.email && !reportData.fcm_token) await sendEmail( @@ -65,6 +61,15 @@ export async function onRequestPost(context: RequestContext) { `Your report for ${reportData.target_usernames.toString()} has been reviewed.`, ); + delete reportData.fcm_token; + delete (reportData.user as { email?: string; id: string; username: string }) + ?.email; + + await context.env.DATA.put(`report_${reportId}`, JSON.stringify(reportData)); + await context.env.D1.prepare("UPDATE reports SET open = 0 WHERE id = ?;") + .bind(reportId) + .run(); + return new Response(null, { status: 204, });