35 lines
965 B
TypeScript
35 lines
965 B
TypeScript
import { NextResponse } from "next/server";
|
|
import { getSessionUser, requirePlatformRole } from "@/lib/session";
|
|
import { runReminderSweep } from "@/lib/cron";
|
|
import { safeError } from "@/lib/errors";
|
|
|
|
/**
|
|
* POST /api/admin/cron/send-reminders
|
|
*
|
|
* Admin-side manual trigger for the reminder sweep. Same logic
|
|
* as the machine path; session-based platform-role auth.
|
|
*/
|
|
export async function POST() {
|
|
let user;
|
|
try {
|
|
await requirePlatformRole();
|
|
user = await getSessionUser();
|
|
} catch {
|
|
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
|
}
|
|
if (!user) {
|
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
}
|
|
try {
|
|
const { runId, summary } = await runReminderSweep({
|
|
triggeredBy: user.id,
|
|
});
|
|
return NextResponse.json({ runId, ...summary });
|
|
} catch (e) {
|
|
return NextResponse.json(
|
|
{ error: safeError(e, "Reminder sweep failed.") },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|