Send notifications on inactivity notice closure
This commit is contained in:
parent
6ea7fae377
commit
adde22804a
@ -1,4 +1,6 @@
|
|||||||
import { jsonError } from "../../common.js";
|
import { jsonError } from "../../common.js";
|
||||||
|
import sendEmail from "../../email.js";
|
||||||
|
import { sendPushNotification } from "../../gcloud.js";
|
||||||
import validateInactivityNotice from "./validate.js";
|
import validateInactivityNotice from "./validate.js";
|
||||||
|
|
||||||
export async function onRequestDelete(context: RequestContext) {
|
export async function onRequestDelete(context: RequestContext) {
|
||||||
@ -65,11 +67,34 @@ export async function onRequestPost(context: RequestContext) {
|
|||||||
if (Object.values(decisions).length === requestedNotice.departments.length) {
|
if (Object.values(decisions).length === requestedNotice.departments.length) {
|
||||||
requestedNotice.open = false;
|
requestedNotice.open = false;
|
||||||
|
|
||||||
|
const approved = !Object.values(decisions).find((d) => !d);
|
||||||
|
|
||||||
await context.env.D1.prepare(
|
await context.env.D1.prepare(
|
||||||
"UPDATE inactivity_notices SET open = 0 WHERE id = ?;",
|
"UPDATE inactivity_notices SET open = 0 WHERE id = ?;",
|
||||||
)
|
)
|
||||||
.bind(context.params.id)
|
.bind(context.params.id)
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
|
if (requestedNotice.fcm_token) {
|
||||||
|
await sendPushNotification(
|
||||||
|
context.env,
|
||||||
|
`Inactivity Request ${approved ? "Approved" : "Denied"}`,
|
||||||
|
accepted
|
||||||
|
? "Your inactivity request was approved."
|
||||||
|
: "Your inactivity request was denied, please reach to management if you require more details.",
|
||||||
|
requestedNotice.fcm_token,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
await sendEmail(
|
||||||
|
requestedNotice.user.email,
|
||||||
|
context.env.MAILGUN_API_KEY,
|
||||||
|
`Inactivity Request ${approved ? "Approved" : "Denied"}`,
|
||||||
|
`inactivity_${approved ? "approved" : "denied"}`,
|
||||||
|
{ username: requestedNotice.user.username },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete requestedNotice.user.email;
|
||||||
}
|
}
|
||||||
|
|
||||||
await context.env.DATA.put(
|
await context.env.DATA.put(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user