Make POST handler for existing inactivity notice

This commit is contained in:
regalijan 2023-10-19 16:50:48 -04:00
parent dd2d9f2672
commit 0559877ca4
Signed by: regalijan
GPG Key ID: 5D4196DA269EF520

View File

@ -40,20 +40,42 @@ export async function onRequestPost(context: RequestContext) {
WM: 1 << 6, WM: 1 << 6,
}; };
const userAdminDepartments = Object.values(adminDepartments).filter( const userAdminDepartments = Object.keys(adminDepartments).filter(
(dept) => context.data.current_user.permissions & dept, (dept) => context.data.current_user.permissions & adminDepartments[dept],
); );
if (!userAdminDepartments.length) if (!userAdminDepartments.length)
return jsonError("You are not a manager of any departments", 403); return jsonError("You are not a manager of any departments", 403);
const requestedNotice = await context.env.DATA.get( const requestedNotice: { [k: string]: any } | null =
`inactivity_${context.params.id as string}`, await context.env.DATA.get(`inactivity_${context.params.id as string}`, {
{ type: "json" }, type: "json",
); });
if (!requestedNotice) if (!requestedNotice)
return jsonError("Inactivity notices does not exist", 404); 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) { export async function onRequestPut(context: RequestContext) {