Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Create inactivity api middleware
  • Loading branch information
regalijan committed Oct 19, 2023
1 parent 769c47c commit c6c1297
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions functions/api/inactivity/_middleware.ts
@@ -0,0 +1,29 @@
function makeResponse(body: string, status: number): Response {
return new Response(body, {
headers: {
"content-type": "application/json",
},
status,
});
}

export async function onRequest(context: RequestContext) {
if (!context.data.current_user)
return makeResponse('{"error":"You are not logged in"}', 401);

const { permissions } = context.data.current_user;
const departments = {
DM: 1 << 2,
ET: 1 << 3,
FM: 1 << 10,
WM: 1 << 9,
};
const userDepartments = [];

for (const [dept, permission] of Object.entries(departments))
if (permissions & permission) userDepartments.push(dept);

context.data.departments = userDepartments;

return await context.next();
}

0 comments on commit c6c1297

Please sign in to comment.