Files
car-crushers-portal/functions/api/appeals/[id]/_middleware.ts
Regalijan 5c17f87f89
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
Migrate the rest of the easy stuff
2026-04-11 04:32:09 -04:00

57 lines
1.4 KiB
TypeScript

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);
// Fix weirdo routing issue
if (pathname.endsWith("/submit") || pathname.endsWith("/toggle"))
return await context.next();
const { permissions } = context.data.current_user;
if (!(permissions & (1 << 0)) && !(permissions & (1 << 11)))
return jsonError("Forbidden", 403);
if (pathname.endsWith("/bans")) return await context.next();
const { body } = context.data;
const id = context.params.id as string;
context.data.targetId = id;
if (!pathname.endsWith("/ban")) {
const appeal: Appeal | null = await context.data.prisma.appeal.findUnique({
where: {
id: id,
},
});
if (!appeal) return jsonError("No appeal with that ID exists", 404);
context.data.appeal = appeal;
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;
}
if (
body.feedback &&
(typeof body.feedback !== "string" || body.feedback.length > 512)
)
return jsonError("Invalid feedback", 400);
return await context.next();
}