KV to D1 migration (this is totally gonna break something)

This commit is contained in:
2024-05-12 01:25:46 -04:00
parent a2b3391bda
commit e00b7e8c55
24 changed files with 1835 additions and 669 deletions

View File

@ -20,11 +20,25 @@ export async function onRequestPost(context: RequestContext) {
context.data.targetId = id;
if (!pathname.endsWith("/ban")) {
const key = await context.env.DATA.get(`appeal_${id}`);
const appeal: Record<string, any> | null = await context.env.D1.prepare(
"SELECT * FROM appeals WHERE id = ?;",
)
.bind(id)
.first();
if (!key) return jsonError("No appeal with that ID exists", 404);
if (!appeal) return jsonError("No appeal with that ID exists", 404);
context.data.appeal = JSON.parse(key);
appeal.user = JSON.parse(appeal.user);
context.data.appeal = appeal;
const pushNotificationData = await context.env.D1.prepare(
"SELECT token FROM push_notifications WHERE event_id = ? AND event_type = 'appeal';",
)
.bind(id)
.first();
if (pushNotificationData)
context.data.fcm_token = pushNotificationData.token;
}
if (