Migrate the rest of the easy stuff
This commit is contained in:
@@ -58,13 +58,14 @@ export async function onRequestGet(context: RequestContext) {
|
||||
} else if (banData.BanType === 2) current_status = "Banned";
|
||||
|
||||
const response = {
|
||||
history: (
|
||||
await context.env.D1.prepare(
|
||||
"SELECT * FROM game_mod_logs WHERE target = ? ORDER BY executed_at DESC;",
|
||||
)
|
||||
.bind(users[0].id)
|
||||
.all()
|
||||
).results,
|
||||
history: await context.data.prisma.gameModLog.findMany({
|
||||
orderBy: {
|
||||
executed_at: "desc",
|
||||
},
|
||||
where: {
|
||||
target: users[0].id,
|
||||
},
|
||||
}),
|
||||
user: {
|
||||
avatar: thumbnailRequest.ok
|
||||
? (
|
||||
|
||||
@@ -2,38 +2,50 @@ import { jsonError, jsonResponse } from "../../../common.js";
|
||||
|
||||
export async function onRequestDelete(context: RequestContext) {
|
||||
const noteId = context.params.id as string;
|
||||
const creatorIdResult: null | Record<string, string> =
|
||||
await context.env.D1.prepare(
|
||||
"SELECT created_by FROM game_mod_logs WHERE id = ?;",
|
||||
)
|
||||
.bind(noteId)
|
||||
.first();
|
||||
const creatorIdResult = await context.data.prisma.gameModNote.findUnique({
|
||||
select: {
|
||||
created_by: true,
|
||||
},
|
||||
where: {
|
||||
id: noteId,
|
||||
},
|
||||
});
|
||||
|
||||
if (creatorIdResult?.created_by !== context.data.current_user.id)
|
||||
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);
|
||||
|
||||
await context.env.D1.prepare("DELETE FROM game_mod_logs WHERE id = ?;")
|
||||
.bind(noteId)
|
||||
.first();
|
||||
}
|
||||
|
||||
return new Response(null, { status: 204 });
|
||||
}
|
||||
|
||||
export async function onRequestGet(context: RequestContext) {
|
||||
const noteId = context.params.id as string;
|
||||
const result = await context.env.D1.prepare(
|
||||
"SELECT * FROM game_mod_notes WHERE id = ?;",
|
||||
)
|
||||
.bind(noteId)
|
||||
.first();
|
||||
const result = await context.data.prisma.gameModNote.findUnique({
|
||||
where: {
|
||||
id: noteId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!result) return jsonError("Note not found", 404);
|
||||
|
||||
const noteData = structuredClone(result);
|
||||
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.creator_name = gmeEntry.name;
|
||||
if (gmeEntry)
|
||||
noteData = Object.defineProperty(noteData, "creator_name", {
|
||||
value: gmeEntry.name,
|
||||
});
|
||||
|
||||
return jsonResponse(JSON.stringify(noteData));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user