(req: NextRequest)
| 4 | import { authOptions } from "../../../lib/auth"; |
| 5 | |
| 6 | export async function POST(req: NextRequest) { |
| 7 | const session = await getServerSession(authOptions); |
| 8 | |
| 9 | if (!session?.user?.admin) { |
| 10 | return NextResponse.json({ message: "Unauthorized" }, { status: 401 }); |
| 11 | } |
| 12 | const body = await req.json(); |
| 13 | const notionId = body.notionId; |
| 14 | const notion = getNotionClient(); |
| 15 | try { |
| 16 | const recordMap = await fetchNotionPage(notion, notionId); |
| 17 | if (!recordMap?.block) { |
| 18 | return NextResponse.json({ message: "Failed to load Notion page" }, { status: 502 }); |
| 19 | } |
| 20 | const data = Object.keys(recordMap.block).filter((key) => { |
| 21 | const block = recordMap.block[key]; |
| 22 | return block?.role !== "none" |
| 23 | }).map((key) => { |
| 24 | const block = recordMap.block[key]; |
| 25 | return { |
| 26 | notionDocId: block?.value.id, |
| 27 | title: block?.value?.properties?.title[0][0], |
| 28 | }; |
| 29 | }); |
| 30 | data.shift(); |
| 31 | data.pop(); |
| 32 | return NextResponse.json(data); |
| 33 | } catch (e) { |
| 34 | return NextResponse.json(e); |
| 35 | } |
| 36 | } |
nothing calls this directly
no outgoing calls
no test coverage detected