The form is built once to the settled field set, and a valid send is saved before anyone is emailed. Co-authored-by: Cursor <cursoragent@cursor.com>
25 lines
1.0 KiB
TypeScript
25 lines
1.0 KiB
TypeScript
import { NextRequest } from "next/server";
|
|
import { apiRoute } from "../../../../lib/server/apiRoute";
|
|
import { NextResponse } from "next/server";
|
|
import { isDatabaseConfigured } from "../../../../lib/server/env";
|
|
import { dbUnavailable, notFound, unauthorized } from "../../../../lib/server/responses";
|
|
import { workshopInquiryPurgeToken } from "../../../../lib/server/workshopInquiryAdmin";
|
|
import {
|
|
purgeExpiredWorkshopInquiries,
|
|
retryPendingWorkshopInquiryMail,
|
|
} from "../../../../lib/server/workshopSignup";
|
|
|
|
export const POST = apiRoute("workshop-inquiries.purge", async (request: NextRequest) => {
|
|
const token = workshopInquiryPurgeToken();
|
|
if (!token) return notFound();
|
|
|
|
const header = request.headers.get("authorization") ?? "";
|
|
if (header !== `Bearer ${token}`) return unauthorized();
|
|
if (!isDatabaseConfigured()) return dbUnavailable();
|
|
|
|
const retried = await retryPendingWorkshopInquiryMail();
|
|
const deleted = await purgeExpiredWorkshopInquiries();
|
|
|
|
return NextResponse.json({ ok: true, retried, deleted });
|
|
});
|