Skip to content
Permalink
c295f3e4df
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
26 lines (23 sloc) 731 Bytes
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,
});
}