Get almost everything else
This commit is contained in:
@@ -4,6 +4,7 @@ import sendEmail from "../../../email.js";
|
||||
import { sendPushNotification } from "../../../gcloud.js";
|
||||
|
||||
export async function onRequestPost(context: RequestContext) {
|
||||
const { prisma } = context.data;
|
||||
const reportId = context.params.id as string;
|
||||
const report: {
|
||||
[k: string]: any;
|
||||
@@ -83,12 +84,15 @@ export async function onRequestPost(context: RequestContext) {
|
||||
await setBanList(context, Object.assign(banList, newActions), etag);
|
||||
}
|
||||
|
||||
const pushNotificationData: Record<string, string> | null =
|
||||
await context.env.D1.prepare(
|
||||
"SELECT token FROM push_notifications WHERE event_id = ? AND event_type = 'report';",
|
||||
)
|
||||
.bind(reportId)
|
||||
.first();
|
||||
const pushNotificationData = await prisma.pushNotification.findUnique({
|
||||
select: {
|
||||
token: true,
|
||||
},
|
||||
where: {
|
||||
event_id: reportId,
|
||||
event_type: "report",
|
||||
},
|
||||
});
|
||||
|
||||
if (user?.email)
|
||||
await sendEmail(
|
||||
@@ -100,26 +104,33 @@ export async function onRequestPost(context: RequestContext) {
|
||||
username: user.username as string,
|
||||
},
|
||||
);
|
||||
else if (pushNotificationData)
|
||||
else if (pushNotificationData) {
|
||||
await sendPushNotification(
|
||||
context.env,
|
||||
"Report Processed",
|
||||
`Your report for ${JSON.parse(report.target_usernames).toString()} has been reviewed.`,
|
||||
pushNotificationData.token,
|
||||
);
|
||||
await prisma.pushNotification.delete({
|
||||
where: {
|
||||
event_id: reportId,
|
||||
event_type: "report",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
delete (report.user as { email?: string; id: string; username: string })
|
||||
?.email;
|
||||
|
||||
await context.env.D1.prepare("UPDATE reports SET open = 0 WHERE id = ?;")
|
||||
.bind(reportId)
|
||||
.run();
|
||||
|
||||
await context.env.D1.prepare(
|
||||
"DELETE FROM push_notifications WHERE event_id = ? AND event_type = 'report';",
|
||||
)
|
||||
.bind(reportId)
|
||||
.run();
|
||||
await prisma.report.update({
|
||||
data: {
|
||||
open: false,
|
||||
user: report.user,
|
||||
},
|
||||
where: {
|
||||
id: reportId,
|
||||
},
|
||||
});
|
||||
|
||||
return new Response(null, {
|
||||
status: 204,
|
||||
|
||||
Reference in New Issue
Block a user