Add inactivity deletion endpoint
This commit is contained in:
parent
ad5505b857
commit
c295f3e4df
26
functions/api/inactivity/[id].ts
Normal file
26
functions/api/inactivity/[id].ts
Normal file
@ -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,
|
||||
});
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user