Add post handler for event-by-id

This commit is contained in:
Regalijan 2024-02-20 17:02:48 -05:00
parent 708a8219a6
commit 6c378080cc
Signed by: regalijan
GPG Key ID: 5D4196DA269EF520

View File

@ -60,3 +60,25 @@ export async function onRequestPatch(context: RequestContext) {
status: 204,
});
}
export async function onRequestPost(context: RequestContext) {
const eventId = context.params.id as string;
const eventData = await context.env.D1.prepare(
"SELECT approved, performed FROM events WHERE id = ?;",
)
.bind(eventId)
.first();
if (!eventData) return jsonError("No event exists with that ID", 404);
if (!eventData.approved)
return jsonError("Cannot perform unapproved event", 403);
await context.env.D1.prepare("UPDATE events SET performed = 1 WHERE id = ?;")
.bind(eventId)
.run();
return new Response(null, {
status: 204,
});
}