diff --git a/functions/api/inactivity/new.ts b/functions/api/inactivity/new.ts index 50334eb..199ea8e 100644 --- a/functions/api/inactivity/new.ts +++ b/functions/api/inactivity/new.ts @@ -48,6 +48,34 @@ export async function onRequestPost(context: RequestContext) { .bind(Date.now(), inactivityId, context.data.current_user.id) .run(); + const departmentsToNotify = []; + const { env } = context; + + for (const department of departments) + departmentsToNotify.push(env[`${department}_INACTIVITY_WEBHOOK`]); + + const webhookPromises = []; + for (const departmentWebhook of departmentsToNotify) + webhookPromises.push( + await fetch(departmentWebhook, { + body: JSON.stringify({ + embeds: [ + { + title: "Inactivity Notice Submitted", + color: 3756250, + description: `View this notice at https://carcrushers.cc/mod-queue?id=${inactivityId}&type=inactivity`, + }, + ], + }), + headers: { + "content-type": "application/json", + }, + method: "POST", + }), + ); + + await Promise.allSettled(webhookPromises); + return new Response(null, { status: 204, });