Send push notifications on report process
This commit is contained in:
parent
fbe054b211
commit
e2d1739656
@ -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);
|
||||
|
||||
@ -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,
|
||||
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user