diff --git a/functions/api/inactivity/[id].ts b/functions/api/inactivity/[id].ts index 7dfdcd4..5a09f99 100644 --- a/functions/api/inactivity/[id].ts +++ b/functions/api/inactivity/[id].ts @@ -40,20 +40,42 @@ export async function onRequestPost(context: RequestContext) { WM: 1 << 6, }; - const userAdminDepartments = Object.values(adminDepartments).filter( - (dept) => context.data.current_user.permissions & dept, + const userAdminDepartments = Object.keys(adminDepartments).filter( + (dept) => context.data.current_user.permissions & adminDepartments[dept], ); if (!userAdminDepartments.length) return jsonError("You are not a manager of any departments", 403); - const requestedNotice = await context.env.DATA.get( - `inactivity_${context.params.id as string}`, - { type: "json" }, - ); + const requestedNotice: { [k: string]: any } | null = + await context.env.DATA.get(`inactivity_${context.params.id as string}`, { + type: "json", + }); if (!requestedNotice) return jsonError("Inactivity notices does not exist", 404); + + const decisions: { [dept: string]: boolean } = {}; + + userAdminDepartments.forEach((dept) => + Object.defineProperty(decisions, dept, { + value: accepted, + }), + ); + + Object.defineProperty(requestedNotice, "decisions", { + value: decisions, + }); + + await context.env.DATA.put( + `inactivity_${context.params.id as string}`, + JSON.stringify(requestedNotice), + { expirationTtl: 63072000 }, + ); + + return new Response(null, { + status: 204, + }); } export async function onRequestPut(context: RequestContext) {