Migrate the rest of the easy stuff
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user