-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathroute.ts
More file actions
33 lines (31 loc) · 1 KB
/
route.ts
File metadata and controls
33 lines (31 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { getServerSession } from "next-auth";
import { NextRequest, NextResponse } from "next/server";
import { NotionAPI } from "notion-client";
import { authOptions } from "../../../lib/auth";
export async function POST(req: NextRequest) {
const session = await getServerSession(authOptions);
if (!session?.user?.admin) {
return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
}
const body = await req.json();
const notionId = body.notionId;
const notion = new NotionAPI();
try {
const recordMap = await notion.getPage(notionId);
const data = Object.keys(recordMap.block).filter((key) => {
const block = recordMap.block[key];
return block?.role !== "none"
}).map((key) => {
const block = recordMap.block[key];
return {
notionDocId: block?.value.id,
title: block?.value?.properties?.title[0][0],
};
});
data.shift();
data.pop();
return NextResponse.json(data);
} catch (e) {
return NextResponse.json(e);
}
}