Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add post handler for event-by-id
  • Loading branch information
regalijan committed Feb 20, 2024
1 parent 708a821 commit 6c37808
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions functions/api/events-team/events/[id].ts
Expand Up @@ -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,
});
}

0 comments on commit 6c37808

Please sign in to comment.