Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make POST handler for existing inactivity notice
  • Loading branch information
regalijan committed Oct 19, 2023
1 parent dd2d9f2 commit 0559877
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions functions/api/inactivity/[id].ts
Expand Up @@ -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) {
Expand Down

0 comments on commit 0559877

Please sign in to comment.