import { jsonError } from "../../../../common.js"; export async function onRequestPost(context: RequestContext) { const id = context.params.id as string; const { D1 } = context.env; await D1.exec("BEGIN TRANSACTION;"); try { const row = await D1.prepare( "UPDATE events SET performed_at = 0 WHERE id = ? RETURNING created_by;", ) .bind(id) .first(); if (!row) { await D1.exec("ROLLBACK;"); return jsonError("Nonexistent event cannot be marked as forgotten.", 404); } await D1.prepare("UPDATE et_members SET points = points - 5 WHERE id = ?;") .bind(row.created_by) .run(); } catch (e) { console.log(e); await D1.exec("ROLLBACK;"); return jsonError( "Failed to mark event as forgotten, points were not changed.", 500, ); } return new Response(null, { status: 204, }); }