Migrate the rest of the easy stuff
All checks were successful
Test, Build, Deploy / Test, Build, and Deploy (push) Successful in 58s
Test, Build, Deploy / Create Sentry Release (push) Successful in 6s

This commit is contained in:
2026-04-11 04:32:09 -04:00
parent 48631e32be
commit 5c17f87f89
13 changed files with 244 additions and 177 deletions

View File

@@ -1,4 +1,8 @@
import { jsonError } from "../../../common.js";
import {
Appeal,
PushNotification,
} from "../../../../generated/prisma/client.js";
export async function onRequestPost(context: RequestContext) {
const { pathname } = new URL(context.request.url);
@@ -20,22 +24,23 @@ export async function onRequestPost(context: RequestContext) {
context.data.targetId = id;
if (!pathname.endsWith("/ban")) {
const appeal: Record<string, any> | null = await context.env.D1.prepare(
"SELECT * FROM appeals WHERE id = ?;",
)
.bind(id)
.first();
const appeal: Appeal | null = await context.data.prisma.appeal.findUnique({
where: {
id: id,
},
});
if (!appeal) return jsonError("No appeal with that ID exists", 404);
appeal.user = JSON.parse(appeal.user);
context.data.appeal = appeal;
const pushNotificationData = await context.env.D1.prepare(
"SELECT token FROM push_notifications WHERE event_id = ? AND event_type = 'appeal';",
)
.bind(id)
.first();
const pushNotificationData: PushNotification | null =
await context.data.prisma.pushNotification.findUnique({
where: {
event_id: id,
event_type: "appeal",
},
});
if (pushNotificationData)
context.data.fcm_token = pushNotificationData.token;

View File

@@ -13,11 +13,12 @@ export async function onRequestPost(context: RequestContext) {
fcm_token,
);
await context.env.D1.prepare(
"DELETE FROM push_notifications WHERE event_id = ? AND event_type = 'appeal';",
)
.bind(appeal.id)
.run();
await context.data.prisma.pushNotification.delete({
where: {
event_id: appeal.id,
event_type: "appeal",
},
});
} else {
const emailResponse = await sendEmail(
appeal.user.email,
@@ -37,11 +38,8 @@ export async function onRequestPost(context: RequestContext) {
const { current_user: currentUser } = context.data;
await context.env.D1.prepare(
"UPDATE appeals SET approved = 1, user = json_remove(user, '$.email') WHERE id = ?;",
)
.bind(context.params.id)
.run();
await context.data.prisma
.$executeRaw`UPDATE appeals SET approved = TRUE, user = json_remove(user, '$.id') WHERE id = ${appeal.id};`;
await fetch(
`https://discord.com/api/v10/guilds/242263977986359297/bans/${appeal.user.id}`,

View File

@@ -6,9 +6,11 @@ export async function onRequestDelete(context: RequestContext) {
if (targetId.search(/^\d{16.19}$/) === -1)
return jsonError("Invalid target id", 400);
await context.env.D1.prepare("DELETE FROM appeal_bans WHERE user = ?;")
.bind(targetId)
.run();
await context.data.prisma.appealBan.delete({
where: {
user: targetId,
},
});
const { current_user: currentUser } = context.data;
@@ -46,11 +48,12 @@ export async function onRequestPost(context: RequestContext) {
if (targetId.search(/^\d{16,19}$/) === -1)
return jsonError("Invalid target id", 400);
await context.env.D1.prepare(
"INSERT INTO appeal_bans (created_at, created_by, user) VALUES (?, ?, ?);",
)
.bind(Date.now(), context.data.current_user.id, targetId)
.run();
await context.data.prisma.appealBan.create({
data: {
created_by: context.data.current_user.id,
user: targetId,
},
});
await fetch(context.env.APPEALS_WEBHOOK, {
body: JSON.stringify({