Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add inactivity deletion endpoint
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}); | ||
} |