diff --git a/functions/api/events-team/events/[id].ts b/functions/api/events-team/events/[id].ts index 91f2515..8071ab8 100644 --- a/functions/api/events-team/events/[id].ts +++ b/functions/api/events-team/events/[id].ts @@ -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, + }); +}