Send push notifs on appeal action
This commit is contained in:
parent
ffe70100ac
commit
161862712c
@ -1,8 +1,18 @@
|
||||
import { jsonError } from "../../../common.js";
|
||||
import sendEmail from "../../../email.js";
|
||||
import { sendPushNotification } from "../../../gcloud.js";
|
||||
|
||||
export async function onRequestPost(context: RequestContext) {
|
||||
const { appeal } = context.data;
|
||||
|
||||
if (appeal.fcm_token) {
|
||||
await sendPushNotification(
|
||||
context.env,
|
||||
"Appeal Accepted",
|
||||
context.data.body.feedback || "No additional details to display",
|
||||
appeal.fcm_token,
|
||||
);
|
||||
} else {
|
||||
const emailResponse = await sendEmail(
|
||||
appeal.user.email,
|
||||
context.env.MAILGUN_API_KEY,
|
||||
@ -17,10 +27,13 @@ export async function onRequestPost(context: RequestContext) {
|
||||
console.log(await emailResponse.json());
|
||||
return jsonError("Failed to accept appeal", 500);
|
||||
}
|
||||
}
|
||||
|
||||
const { current_user: currentUser } = context.data;
|
||||
|
||||
await context.env.D1.prepare("UPDATE appeals SET approved = 1, open = 0 WHERE id = ?;")
|
||||
await context.env.D1.prepare(
|
||||
"UPDATE appeals SET approved = 1, open = 0 WHERE id = ?;",
|
||||
)
|
||||
.bind(context.params.id)
|
||||
.run();
|
||||
|
||||
|
@ -1,9 +1,19 @@
|
||||
import { jsonError } from "../../../common.js";
|
||||
import sendEmail from "../../../email.js";
|
||||
import { sendPushNotification } from "../../../gcloud.js";
|
||||
|
||||
export async function onRequestPost(context: RequestContext) {
|
||||
const { appeal } = context.data;
|
||||
|
||||
if (appeal.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,
|
||||
);
|
||||
} else {
|
||||
const emailResponse = await sendEmail(
|
||||
appeal.user.email,
|
||||
context.env.MAILGUN_API_KEY,
|
||||
@ -18,8 +28,11 @@ export async function onRequestPost(context: RequestContext) {
|
||||
console.log(await emailResponse.json());
|
||||
return jsonError("Failed to deny appeal", 500);
|
||||
}
|
||||
}
|
||||
|
||||
await context.env.D1.prepare("UPDATE appeals SET approved = 0, open = 0 WHERE id = ?;")
|
||||
await context.env.D1.prepare(
|
||||
"UPDATE appeals SET approved = 0, open = 0 WHERE id = ?;",
|
||||
)
|
||||
.bind(context.params.id)
|
||||
.run();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user