Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Delete FCM token from KV on report action
  • Loading branch information
regalijan committed Oct 19, 2023
1 parent 53b05e2 commit b054d4c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions functions/api/reports/[id]/action.ts
Expand Up @@ -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(
Expand All @@ -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,
});
Expand Down

0 comments on commit b054d4c

Please sign in to comment.