From 02cac814da82a0879dd71a2b8dc236ea5ac0432b Mon Sep 17 00:00:00 2001 From: Regalijan Date: Sat, 11 Apr 2026 04:42:39 -0400 Subject: [PATCH] Use internally generated types for jsonobject and raw --- functions/api/mod-queue/[type]/[id].ts | 101 +++++++++++++------------ 1 file changed, 52 insertions(+), 49 deletions(-) diff --git a/functions/api/mod-queue/[type]/[id].ts b/functions/api/mod-queue/[type]/[id].ts index b5d641c..a4d1915 100644 --- a/functions/api/mod-queue/[type]/[id].ts +++ b/functions/api/mod-queue/[type]/[id].ts @@ -1,68 +1,71 @@ import { jsonError, jsonResponse } from "../../../common.js"; +import { JsonObject } from "@prisma/client/runtime/client"; export async function onRequestGet(context: RequestContext) { - const types: { - [k: string]: { permissions: number[]; table: string }; - } = { - appeal: { - permissions: [1 << 0, 1 << 11], - table: "appeals", - }, - gma: { - permissions: [1 << 5], - table: "game_appeals", - }, - inactivity: { - permissions: [1 << 0, 1 << 4, 1 << 6, 1 << 7, 1 << 11], - table: "inactivity_notices", - }, - report: { - permissions: [1 << 5], - table: "reports", - }, + const types: { [k: string]: number[] } = { + appeal: [1 << 0, 1 << 11], + gma: [1 << 5], + inactivity: [1 << 0, 1 << 4, 1 << 6, 1 << 7, 1 << 11], + report: [1 << 5], }; const type = context.params.type as string; const itemId = context.params.id as string; - if ( - !types[type]?.permissions.find( - (p) => context.data.current_user.permissions & p, - ) - ) + if (!types[type]?.find((p) => context.data.current_user.permissions & p)) return jsonError("You cannot use this filter", 403); - const item: Record | null = await context.env.D1.prepare( - `SELECT * - FROM ${types[type].table} - WHERE id = ?;`, - ) - .bind(itemId) - .first(); + let item; + + switch (type) { + case "appeal": + item = await context.data.prisma.appeal.findUnique({ + where: { + id: itemId, + }, + }); + + if (item) delete (item.user as JsonObject).email; + break; + + case "gma": + item = await context.data.prisma.gameAppeal.findUnique({ + where: { + id: itemId, + }, + }); + break; + + case "inactivity": + item = await context.data.prisma.inactivityNotice.findUnique({ + where: { + id: itemId, + }, + }); + + if (item) delete (item.user as JsonObject).email; + break; + + case "report": + item = await context.data.prisma.report.findUnique({ + where: { + id: itemId, + }, + }); + + if (item) delete (item.user as JsonObject).email; + break; + + default: + return jsonError("Unknown filter", 400); + } if (!item) return jsonError("Item not found", 404); if (type === "report") { if (await context.env.DATA.get(`reportprocessing_${itemId}`)) return jsonError("Report is processing", 409); - - item.attachments = JSON.parse(item.attachments); - item.target_ids = JSON.parse(item.target_ids); - item.target_usernames = JSON.parse(item.target_usernames); } - if (item.user) { - item.user = JSON.parse(item.user); - - delete item.user.email; - } - - if (type === "inactivity") { - item.decisions = JSON.parse(item.decisions); - item.departments = JSON.parse(item.departments); - } - - return item - ? jsonResponse(JSON.stringify(item)) - : jsonError("Not found", 404); + return jsonResponse(JSON.stringify(item)); }