From 2fc73a62cc5d598584da59114f4f28871816bce1 Mon Sep 17 00:00:00 2001 From: regalijan Date: Thu, 19 Oct 2023 16:50:52 -0400 Subject: [PATCH] Maybe fix inactivity notices? --- functions/api/inactivity/[id].ts | 41 ++++++++++++++------------------ 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/functions/api/inactivity/[id].ts b/functions/api/inactivity/[id].ts index 5a09f99..c1963e5 100644 --- a/functions/api/inactivity/[id].ts +++ b/functions/api/inactivity/[id].ts @@ -3,7 +3,7 @@ import validateInactivityNotice from "./validate.js"; export async function onRequestDelete(context: RequestContext) { const kvResult = await context.env.DATA.get( - `inactivity_${context.params.id}`, + `inactivity_${context.params.id}` ); if (!kvResult) return jsonError("No inactivity notice with that ID", 404); @@ -14,7 +14,7 @@ export async function onRequestDelete(context: RequestContext) { ) return jsonError( "You do not have permission to delete this inactivity notice", - 403, + 403 ); await context.env.DATA.delete(`inactivity_${context.params.id}`); @@ -23,7 +23,7 @@ export async function onRequestDelete(context: RequestContext) { .run(); return new Response(null, { - status: 204, + status: 204 }); } @@ -37,11 +37,11 @@ export async function onRequestPost(context: RequestContext) { DM: 1 << 11, ET: 1 << 4, FM: 1 << 7, - WM: 1 << 6, + WM: 1 << 6 }; const userAdminDepartments = Object.keys(adminDepartments).filter( - (dept) => context.data.current_user.permissions & adminDepartments[dept], + (dept) => context.data.current_user.permissions & adminDepartments[dept] ); if (!userAdminDepartments.length) @@ -49,7 +49,7 @@ export async function onRequestPost(context: RequestContext) { const requestedNotice: { [k: string]: any } | null = await context.env.DATA.get(`inactivity_${context.params.id as string}`, { - type: "json", + type: "json" }); if (!requestedNotice) @@ -57,31 +57,26 @@ export async function onRequestPost(context: RequestContext) { const decisions: { [dept: string]: boolean } = {}; - userAdminDepartments.forEach((dept) => - Object.defineProperty(decisions, dept, { - value: accepted, - }), - ); + for (const department of userAdminDepartments) + decisions[department] = accepted; - Object.defineProperty(requestedNotice, "decisions", { - value: decisions, - }); + requestedNotice.decisions = decisions; await context.env.DATA.put( `inactivity_${context.params.id as string}`, JSON.stringify(requestedNotice), - { expirationTtl: 63072000 }, + { expirationTtl: 63072000 } ); return new Response(null, { - status: 204, + status: 204 }); } export async function onRequestPut(context: RequestContext) { const kvResult: InactivityNoticeProps | null = await context.env.DATA.get( `inactivity_${context.params.id}`, - { type: "json" }, + { type: "json" } ); if (!kvResult) return jsonError("No inactivity notice with that ID", 404); @@ -89,11 +84,11 @@ export async function onRequestPut(context: RequestContext) { if (kvResult.user.id !== context.data.current_user.id) return jsonError( "You do not have permission to modify this inactivity notice", - 403, + 403 ); const d1entry = await context.env.D1.prepare( - "SELECT open FROM inactivity_notices WHERE id = ?;", + "SELECT open FROM inactivity_notices WHERE id = ?;" ) .bind(context.params.id) .run(); @@ -108,7 +103,7 @@ export async function onRequestPut(context: RequestContext) { end, reason, start, - context.data.departments, + context.data.departments ); if (validationFailureResponse) return validationFailureResponse; @@ -122,11 +117,11 @@ export async function onRequestPut(context: RequestContext) { `inactivity_${context.params.id}`, JSON.stringify(kvResult), { - expirationTtl: 63072000, - }, + expirationTtl: 63072000 + } ); return new Response(null, { - status: 204, + status: 204 }); }