Use internally generated types for jsonobject and raw
Some checks failed
Test, Build, Deploy / Test, Build, and Deploy (push) Failing after 50s
Test, Build, Deploy / Create Sentry Release (push) Has been skipped

This commit is contained in:
2026-04-11 04:42:39 -04:00
parent f184389ffd
commit 02cac814da

View File

@@ -1,68 +1,71 @@
import { jsonError, jsonResponse } from "../../../common.js"; import { jsonError, jsonResponse } from "../../../common.js";
import { JsonObject } from "@prisma/client/runtime/client";
export async function onRequestGet(context: RequestContext) { export async function onRequestGet(context: RequestContext) {
const types: { const types: { [k: string]: number[] } = {
[k: string]: { permissions: number[]; table: string }; appeal: [1 << 0, 1 << 11],
} = { gma: [1 << 5],
appeal: { inactivity: [1 << 0, 1 << 4, 1 << 6, 1 << 7, 1 << 11],
permissions: [1 << 0, 1 << 11], report: [1 << 5],
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 type = context.params.type as string; const type = context.params.type as string;
const itemId = context.params.id as string; const itemId = context.params.id as string;
if ( if (!types[type]?.find((p) => context.data.current_user.permissions & p))
!types[type]?.permissions.find(
(p) => context.data.current_user.permissions & p,
)
)
return jsonError("You cannot use this filter", 403); return jsonError("You cannot use this filter", 403);
const item: Record<string, any> | null = await context.env.D1.prepare( let item;
`SELECT *
FROM ${types[type].table} switch (type) {
WHERE id = ?;`, case "appeal":
) item = await context.data.prisma.appeal.findUnique({
.bind(itemId) where: {
.first(); 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 (!item) return jsonError("Item not found", 404);
if (type === "report") { if (type === "report") {
if (await context.env.DATA.get(`reportprocessing_${itemId}`)) if (await context.env.DATA.get(`reportprocessing_${itemId}`))
return jsonError("Report is processing", 409); 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) { return jsonResponse(JSON.stringify(item));
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);
} }