2026-06-23 20:36:07 -04:00
|
|
|
import { NextResponse } from "next/server"
|
|
|
|
|
import { getSessionUser } from "@/lib/session"
|
2026-07-02 13:42:34 -04:00
|
|
|
import { getEffectiveOwnerId } from "@/lib/account"
|
|
|
|
|
import { runFollowUpsForUser } from "@/lib/follow-ups"
|
2026-06-23 20:36:07 -04:00
|
|
|
|
|
|
|
|
export async function POST() {
|
|
|
|
|
const user = await getSessionUser()
|
|
|
|
|
if (!user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 })
|
|
|
|
|
|
2026-07-02 13:42:34 -04:00
|
|
|
const ownerId = await getEffectiveOwnerId(user.id)
|
2026-06-23 20:36:07 -04:00
|
|
|
|
2026-07-02 13:42:34 -04:00
|
|
|
const result = await runFollowUpsForUser(ownerId)
|
2026-06-23 20:36:07 -04:00
|
|
|
|
2026-07-02 13:42:34 -04:00
|
|
|
// Preserve the original response shape ({ sent, results }). The detailed
|
|
|
|
|
// per-follow-up rows now live only in follow_up_log; the client re-fetches
|
|
|
|
|
// rules for last_run_at and tolerates an empty results array.
|
|
|
|
|
return NextResponse.json({ sent: result.sent, results: [] })
|
2026-06-23 20:36:07 -04:00
|
|
|
}
|