Add GET endpoint for inactivity-notice-by-id

This commit is contained in:
Regalijan 2025-01-23 15:47:30 -05:00
parent bde4727d9f
commit 84e7df6c30
Signed by: regalijan
GPG Key ID: 5D4196DA269EF520

View File

@ -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;