Files
car-crushers-portal/functions/api/game-bans/notes/[id].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

52 lines
1.3 KiB
TypeScript

import { jsonError, jsonResponse } from "../../../common.js";
export async function onRequestDelete(context: RequestContext) {
const noteId = context.params.id as string;
const creatorIdResult = await context.data.prisma.gameModNote.findUnique({
select: {
created_by: true,
},
where: {
id: noteId,
},
});
try {
await context.data.prisma.gameModNote.delete({
select: {
id: true,
},
where: {
created_by: context.data.current_user.id,
id: noteId,
},
});
} catch {
return jsonError("Cannot delete notes that are not your own", 403);
}
return new Response(null, { status: 204 });
}
export async function onRequestGet(context: RequestContext) {
const noteId = context.params.id as string;
const result = await context.data.prisma.gameModNote.findUnique({
where: {
id: noteId,
},
});
if (!result) return jsonError("Note not found", 404);
let noteData = structuredClone(result);
const gmeEntry: null | { time: number; user: string; name: string } =
await context.env.DATA.get(`gamemod_${result.created_by}`, "json");
if (gmeEntry)
noteData = Object.defineProperty(noteData, "creator_name", {
value: gmeEntry.name,
});
return jsonResponse(JSON.stringify(noteData));
}