import { jsonError } from "../../../../common.js";

export async function onRequestPost(context: RequestContext) {
  if (context.data.event.reached_minimum_player_count)
    return jsonError("This event is already certified", 400);

  await context.env.D1.prepare(
    "UPDATE events SET reached_minimum_player_count = 1 WHERE id = ?;",
  )
    .bind(context.data.event.id)
    .run();

  return new Response(null, {
    status: 204,
  });
}
