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

export async function onRequestPost(context: RequestContext) {
  if (typeof context.data.body.approved !== "boolean")
    return jsonError("Decision type must be a boolean", 400);

  await context.env.D1.prepare(
    "UPDATE events SET approved = ?, pending = 0 WHERE id = ?;",
  )
    .bind(Number(context.data.body.approved), context.data.event.id)
    .run();

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