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 { insertLogs } from "../../../gcloud.js";
|
||||||
import { jsonError } from "../../../common.js";
|
import { jsonError } from "../../../common.js";
|
||||||
import sendEmail from "../../../email.js";
|
import sendEmail from "../../../email.js";
|
||||||
|
import { sendPushNotification } from "../../../gcloud.js";
|
||||||
|
|
||||||
export async function onRequestPost(context: RequestContext) {
|
export async function onRequestPost(context: RequestContext) {
|
||||||
const reportId = context.params.id as string;
|
const reportId = context.params.id as string;
|
||||||
const reportData: ReportCardProps | null = await context.env.DATA.get(
|
const reportData: (ReportCardProps & { fcm_token?: string }) | null =
|
||||||
`report_${reportId}`,
|
await context.env.DATA.get(`report_${reportId}`, { type: "json" });
|
||||||
{ type: "json" },
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!reportData) return jsonError("Report does not exist", 404);
|
if (!reportData) return jsonError("Report does not exist", 404);
|
||||||
|
|
||||||
@ -49,7 +48,7 @@ export async function onRequestPost(context: RequestContext) {
|
|||||||
.bind(reportId)
|
.bind(reportId)
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
if (user?.email)
|
if (user?.email && !reportData.fcm_token)
|
||||||
await sendEmail(
|
await sendEmail(
|
||||||
user.email,
|
user.email,
|
||||||
context.env.MAILGUN_API_KEY,
|
context.env.MAILGUN_API_KEY,
|
||||||
@ -59,6 +58,12 @@ export async function onRequestPost(context: RequestContext) {
|
|||||||
username: reportData.user?.username as string,
|
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, {
|
return new Response(null, {
|
||||||
status: 204,
|
status: 204,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user