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

@ -3,16 +3,22 @@ import sendEmail from "../../../email.js";
import { sendPushNotification } from "../../../gcloud.js";
export async function onRequestPost(context: RequestContext) {
const { appeal } = context.data;
if (appeal.fcm_token) {
const { appeal, fcm_token } = context.data;
if (fcm_token) {
await sendPushNotification(
context.env,
"Appeal Denied",
`Unfortunately, we have decided to deny your appeal for the following reason: ${
context.data.body.feedback || "No additional details"
}`,
appeal.fcm_token,
fcm_token,
);
await context.env.D1.prepare(
"DELETE FROM push_notifications WHERE event_id = ? AND event_type = 'appeal';",
)
.bind(appeal.id)
.run();
} else {
const emailResponse = await sendEmail(
appeal.user.email,
@ -31,22 +37,13 @@ export async function onRequestPost(context: RequestContext) {
}
await context.env.D1.prepare(
"UPDATE appeals SET approved = 0, open = 0 WHERE id = ?;",
"UPDATE appeals SET approved = 0, user = json_remove(user, '$.email') WHERE id = ?;",
)
.bind(context.params.id)
.run();
const { current_user: currentUser } = context.data;
delete appeal.user.email;
delete appeal.fcm_token;
appeal.open = false;
await context.env.DATA.put(`appeal_${appeal.id}`, JSON.stringify(appeal), {
expirationTtl: 94608000,
});
await fetch(context.env.APPEALS_WEBHOOK, {
body: JSON.stringify({
embeds: [