Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add GET endpoint for inactivity-notice-by-id
  • Loading branch information
regalijan committed Jan 23, 2025
1 parent bde4727 commit 84e7df6
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions functions/api/inactivity/[id].ts
Expand Up @@ -29,6 +29,32 @@ export async function onRequestDelete(context: RequestContext) {
});
}

export async function onRequestGet(context: RequestContext) {
const { current_user: currentUser } = context.data;

if (
![1 << 0, 1 << 2, 1 << 3, 1 << 9, 1 << 10].find(
(p) => currentUser.permissions & p,
)
)
return jsonError("Forbidden", 403);

const result: Record<
string,
string | number | { [k: string]: string }
> | null = await context.env.D1.prepare(
"SELECT * FROM inactivity_notices WHERE id = ?;",
)
.bind(context.params.id)
.first();

if (!result) return jsonError("Inactivity notice does not exist", 404);

result.user = JSON.parse(result.user as string);

return result;
}

export async function onRequestPost(context: RequestContext) {
const { accepted }: { accepted?: boolean } = context.data.body;

Expand Down

0 comments on commit 84e7df6

Please sign in to comment.