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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user