Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Send push notifications on report process
  • Loading branch information
regalijan committed Oct 19, 2023
1 parent fbe054b commit e2d1739
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions functions/api/reports/[id]/action.ts
Expand Up @@ -2,13 +2,12 @@ import { getBanList, setBanList } from "../../../roblox-open-cloud.js";
import { insertLogs } from "../../../gcloud.js";
import { jsonError } from "../../../common.js";
import sendEmail from "../../../email.js";
import { sendPushNotification } from "../../../gcloud.js";

export async function onRequestPost(context: RequestContext) {
const reportId = context.params.id as string;
const reportData: ReportCardProps | null = await context.env.DATA.get(
`report_${reportId}`,
{ type: "json" },
);
const reportData: (ReportCardProps & { fcm_token?: string }) | null =
await context.env.DATA.get(`report_${reportId}`, { type: "json" });

if (!reportData) return jsonError("Report does not exist", 404);

Expand Down Expand Up @@ -49,7 +48,7 @@ export async function onRequestPost(context: RequestContext) {
.bind(reportId)
.run();

if (user?.email)
if (user?.email && !reportData.fcm_token)
await sendEmail(
user.email,
context.env.MAILGUN_API_KEY,
Expand All @@ -59,6 +58,12 @@ export async function onRequestPost(context: RequestContext) {
username: reportData.user?.username as string,
},
);
else if (reportData.fcm_token)
await sendPushNotification(
context.env,
"Report Processed",
`Your report for ${reportData.target_usernames.toString()} has been reviewed.`,
);

return new Response(null, {
status: 204,
Expand Down

0 comments on commit e2d1739

Please sign in to comment.