Make POST handler for existing inactivity notice
This commit is contained in:
parent
dd2d9f2672
commit
0559877ca4
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user