/** * convex/http.ts * * Öffentliche HTTP-Routen. /abmelden ist der frictionless Opt-out aus dem * Pflicht-Footer jeder Outreach-Mail (UWG/DSGVO). */ import { httpRouter } from "convex/server"; import { httpAction } from "./_generated/server"; import { internal } from "./_generated/api"; import type { Id } from "./_generated/dataModel"; const http = httpRouter(); http.route({ path: "/abmelden", method: "GET", handler: httpAction(async (ctx, req) => { const o = new URL(req.url).searchParams.get("o"); if (o) { try { const target = await ctx.runQuery(internal.outreach.getOptOutTarget, { outreachId: o as Id<"outreach">, }); if (target) { await ctx.runMutation(internal.outreach.recordOptOut, { orgId: target.orgId, email: target.email, domain: target.domain, outreachId: o as Id<"outreach">, }); } } catch { // ungültiger Link → trotzdem freundlich bestätigen } } return new Response( `
Sie erhalten keine weitere Nachricht. Entschuldigen Sie die Störung.
`, { headers: { "Content-Type": "text/html; charset=utf-8" } }, ); }), }); export default http;