Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add inactivity deletion endpoint
  • Loading branch information
regalijan committed Oct 19, 2023
1 parent ad5505b commit c295f3e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions functions/api/inactivity/[id].ts
@@ -0,0 +1,26 @@
export async function onRequestDelete(context: RequestContext) {
const kvResult = await context.env.DATA.get(
`inactivity_${context.params.id}`,
);

if (
!kvResult ||
(JSON.parse(kvResult).user.id !== context.data.current_user.id &&
!(context.data.current_user.permissions & (1 << 0)))
)
return new Response('{"error":"No inactivity notice with that ID"}', {
headers: {
"content-type": "application/json",
},
status: 404,
});

await context.env.DATA.delete(`inactivity_${context.params.id}`);
await context.env.D1.prepare("DELETE FROM inactivity_notices WHERE id = ?;")
.bind(context.params.id)
.run();

return new Response(null, {
status: 204,
});
}

0 comments on commit c295f3e

Please sign in to comment.