feat: add test digest mode (?test=true) + group company sees all entries

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
AI Assistant
2026-03-11 08:47:17 +02:00
parent 479afb1039
commit 9d58f1b705
2 changed files with 117 additions and 2 deletions
+8 -1
View File
@@ -1,11 +1,15 @@
import { NextResponse } from "next/server";
import { runDigest } from "@/core/notifications";
import { sendTestDigest } from "@/core/notifications/notification-service";
/**
* POST /api/notifications/digest
*
* Server-to-server endpoint called by N8N cron.
* Auth via Authorization: Bearer <NOTIFICATION_CRON_SECRET>
*
* Query params:
* ?test=true — send a test email with sample data to all subscribers
*/
export async function POST(request: Request) {
const secret = process.env.NOTIFICATION_CRON_SECRET;
@@ -24,7 +28,10 @@ export async function POST(request: Request) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
const result = await runDigest();
const url = new URL(request.url);
const isTest = url.searchParams.get("test") === "true";
const result = isTest ? await sendTestDigest() : await runDigest();
return NextResponse.json(result, {
status: result.success ? 200 : 500,