KV to D1 migration (this is totally gonna break something)
This commit is contained in:
@ -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: [
|
||||
|
Reference in New Issue
Block a user