Kaynağa Gözat

[feat] Add getTopicList endpoint

Sergio Mattei 2 yıl önce
ebeveyn
işleme
65fa04d741
5 değiştirilmiş dosya ile 231 ekleme ve 18 silme
  1. 2
    0
      config.ts
  2. 2
    13
      lib/notion.ts
  3. 202
    0
      package-lock.json
  4. 1
    0
      package.json
  5. 24
    5
      pages/api/getTopicList.ts

+ 2
- 0
config.ts Dosyayı Görüntüle

@@ -1 +1,3 @@
1 1
 export const NOTION_KEY = process.env.NOTION_KEY;
2
+export const LAWS_BLOCK_ID =
3
+  process.env.LAWS_BLOCK_ID ?? "d02fa51eda254c9fa4b97e5f9beb1a86";

+ 2
- 13
lib/notion.ts Dosyayı Görüntüle

@@ -1,16 +1,5 @@
1 1
 import { NOTION_KEY } from "../config";
2 2
 
3
-interface NotionAuth {}
3
+const { Client } = require("@notionhq/client");
4 4
 
5
-/**
6
- * Returns authentication configuration for a Notion API `fetch` call.
7
- * @returns
8
- */
9
-export function notionCall(): Partial<RequestInit> {
10
-  return {
11
-    headers: {
12
-      "Notion-Version": "2022-06-28",
13
-      Authorization: `Bearer ${NOTION_KEY}`,
14
-    },
15
-  };
16
-}
5
+export const notion = new Client({ auth: NOTION_KEY });

+ 202
- 0
package-lock.json Dosyayı Görüntüle

@@ -8,6 +8,7 @@
8 8
       "name": "renacer-api",
9 9
       "version": "0.1.0",
10 10
       "dependencies": {
11
+        "@notionhq/client": "^2.2.2",
11 12
         "@types/node": "18.11.11",
12 13
         "@types/react": "18.0.26",
13 14
         "@types/react-dom": "18.0.9",
@@ -334,6 +335,18 @@
334 335
         "node": ">= 8"
335 336
       }
336 337
     },
338
+    "node_modules/@notionhq/client": {
339
+      "version": "2.2.2",
340
+      "resolved": "https://registry.npmjs.org/@notionhq/client/-/client-2.2.2.tgz",
341
+      "integrity": "sha512-L7TB+UyhnWTSv1ek7xzGr9+mS9o76qMKnZ8Ag8H2q6QgvywAiPOFcE3ulWI/1AnMewGVRqwb30agPHMVRY/K/w==",
342
+      "dependencies": {
343
+        "@types/node-fetch": "^2.5.10",
344
+        "node-fetch": "^2.6.1"
345
+      },
346
+      "engines": {
347
+        "node": ">=12"
348
+      }
349
+    },
337 350
     "node_modules/@pkgr/utils": {
338 351
       "version": "2.3.1",
339 352
       "resolved": "https://registry.npmjs.org/@pkgr/utils/-/utils-2.3.1.tgz",
@@ -376,6 +389,15 @@
376 389
       "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.11.tgz",
377 390
       "integrity": "sha512-KJ021B1nlQUBLopzZmPBVuGU9un7WJd/W4ya7Ih02B4Uwky5Nja0yGYav2EfYIk0RR2Q9oVhf60S2XR1BCWJ2g=="
378 391
     },
392
+    "node_modules/@types/node-fetch": {
393
+      "version": "2.6.2",
394
+      "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.2.tgz",
395
+      "integrity": "sha512-DHqhlq5jeESLy19TYhLakJ07kNumXWjcDdxXsLUMJZ6ue8VZJj4kLPQVE/2mdHh3xZziNF1xppu5lwmS53HR+A==",
396
+      "dependencies": {
397
+        "@types/node": "*",
398
+        "form-data": "^3.0.0"
399
+      }
400
+    },
379 401
     "node_modules/@types/prop-types": {
380 402
       "version": "15.7.5",
381 403
       "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.5.tgz",
@@ -650,6 +672,11 @@
650 672
       "resolved": "https://registry.npmjs.org/ast-types-flow/-/ast-types-flow-0.0.7.tgz",
651 673
       "integrity": "sha512-eBvWn1lvIApYMhzQMsu9ciLfkBY499mFZlNqG+/9WR7PVlroQw0vG30cOQQbaKz3sCEc44TAOu2ykzqXSNnwag=="
652 674
     },
675
+    "node_modules/asynckit": {
676
+      "version": "0.4.0",
677
+      "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
678
+      "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
679
+    },
653 680
     "node_modules/axe-core": {
654 681
       "version": "4.5.2",
655 682
       "resolved": "https://registry.npmjs.org/axe-core/-/axe-core-4.5.2.tgz",
@@ -759,6 +786,17 @@
759 786
       "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
760 787
       "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
761 788
     },
789
+    "node_modules/combined-stream": {
790
+      "version": "1.0.8",
791
+      "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
792
+      "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
793
+      "dependencies": {
794
+        "delayed-stream": "~1.0.0"
795
+      },
796
+      "engines": {
797
+        "node": ">= 0.8"
798
+      }
799
+    },
762 800
     "node_modules/concat-map": {
763 801
       "version": "0.0.1",
764 802
       "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
@@ -841,6 +879,14 @@
841 879
         "url": "https://github.com/sponsors/ljharb"
842 880
       }
843 881
     },
882
+    "node_modules/delayed-stream": {
883
+      "version": "1.0.0",
884
+      "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
885
+      "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
886
+      "engines": {
887
+        "node": ">=0.4.0"
888
+      }
889
+    },
844 890
     "node_modules/dir-glob": {
845 891
       "version": "3.0.1",
846 892
       "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz",
@@ -1486,6 +1532,19 @@
1486 1532
       "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.7.tgz",
1487 1533
       "integrity": "sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ=="
1488 1534
     },
1535
+    "node_modules/form-data": {
1536
+      "version": "3.0.1",
1537
+      "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz",
1538
+      "integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==",
1539
+      "dependencies": {
1540
+        "asynckit": "^0.4.0",
1541
+        "combined-stream": "^1.0.8",
1542
+        "mime-types": "^2.1.12"
1543
+      },
1544
+      "engines": {
1545
+        "node": ">= 6"
1546
+      }
1547
+    },
1489 1548
     "node_modules/fs.realpath": {
1490 1549
       "version": "1.0.0",
1491 1550
       "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
@@ -2122,6 +2181,25 @@
2122 2181
         "node": ">=8.6"
2123 2182
       }
2124 2183
     },
2184
+    "node_modules/mime-db": {
2185
+      "version": "1.52.0",
2186
+      "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
2187
+      "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
2188
+      "engines": {
2189
+        "node": ">= 0.6"
2190
+      }
2191
+    },
2192
+    "node_modules/mime-types": {
2193
+      "version": "2.1.35",
2194
+      "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
2195
+      "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
2196
+      "dependencies": {
2197
+        "mime-db": "1.52.0"
2198
+      },
2199
+      "engines": {
2200
+        "node": ">= 0.6"
2201
+      }
2202
+    },
2125 2203
     "node_modules/minimatch": {
2126 2204
       "version": "3.1.2",
2127 2205
       "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
@@ -2213,6 +2291,25 @@
2213 2291
         }
2214 2292
       }
2215 2293
     },
2294
+    "node_modules/node-fetch": {
2295
+      "version": "2.6.7",
2296
+      "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz",
2297
+      "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==",
2298
+      "dependencies": {
2299
+        "whatwg-url": "^5.0.0"
2300
+      },
2301
+      "engines": {
2302
+        "node": "4.x || >=6.0.0"
2303
+      },
2304
+      "peerDependencies": {
2305
+        "encoding": "^0.1.0"
2306
+      },
2307
+      "peerDependenciesMeta": {
2308
+        "encoding": {
2309
+          "optional": true
2310
+        }
2311
+      }
2312
+    },
2216 2313
     "node_modules/object-assign": {
2217 2314
       "version": "4.1.1",
2218 2315
       "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
@@ -2889,6 +2986,11 @@
2889 2986
         "node": ">=8.0"
2890 2987
       }
2891 2988
     },
2989
+    "node_modules/tr46": {
2990
+      "version": "0.0.3",
2991
+      "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
2992
+      "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw=="
2993
+    },
2892 2994
     "node_modules/tsconfig-paths": {
2893 2995
       "version": "3.14.1",
2894 2996
       "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.14.1.tgz",
@@ -2980,6 +3082,20 @@
2980 3082
         "punycode": "^2.1.0"
2981 3083
       }
2982 3084
     },
3085
+    "node_modules/webidl-conversions": {
3086
+      "version": "3.0.1",
3087
+      "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
3088
+      "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="
3089
+    },
3090
+    "node_modules/whatwg-url": {
3091
+      "version": "5.0.0",
3092
+      "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
3093
+      "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",
3094
+      "dependencies": {
3095
+        "tr46": "~0.0.3",
3096
+        "webidl-conversions": "^3.0.0"
3097
+      }
3098
+    },
2983 3099
     "node_modules/which": {
2984 3100
       "version": "2.0.2",
2985 3101
       "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
@@ -3207,6 +3323,15 @@
3207 3323
         "fastq": "^1.6.0"
3208 3324
       }
3209 3325
     },
3326
+    "@notionhq/client": {
3327
+      "version": "2.2.2",
3328
+      "resolved": "https://registry.npmjs.org/@notionhq/client/-/client-2.2.2.tgz",
3329
+      "integrity": "sha512-L7TB+UyhnWTSv1ek7xzGr9+mS9o76qMKnZ8Ag8H2q6QgvywAiPOFcE3ulWI/1AnMewGVRqwb30agPHMVRY/K/w==",
3330
+      "requires": {
3331
+        "@types/node-fetch": "^2.5.10",
3332
+        "node-fetch": "^2.6.1"
3333
+      }
3334
+    },
3210 3335
     "@pkgr/utils": {
3211 3336
       "version": "2.3.1",
3212 3337
       "resolved": "https://registry.npmjs.org/@pkgr/utils/-/utils-2.3.1.tgz",
@@ -3243,6 +3368,15 @@
3243 3368
       "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.11.tgz",
3244 3369
       "integrity": "sha512-KJ021B1nlQUBLopzZmPBVuGU9un7WJd/W4ya7Ih02B4Uwky5Nja0yGYav2EfYIk0RR2Q9oVhf60S2XR1BCWJ2g=="
3245 3370
     },
3371
+    "@types/node-fetch": {
3372
+      "version": "2.6.2",
3373
+      "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.2.tgz",
3374
+      "integrity": "sha512-DHqhlq5jeESLy19TYhLakJ07kNumXWjcDdxXsLUMJZ6ue8VZJj4kLPQVE/2mdHh3xZziNF1xppu5lwmS53HR+A==",
3375
+      "requires": {
3376
+        "@types/node": "*",
3377
+        "form-data": "^3.0.0"
3378
+      }
3379
+    },
3246 3380
     "@types/prop-types": {
3247 3381
       "version": "15.7.5",
3248 3382
       "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.5.tgz",
@@ -3424,6 +3558,11 @@
3424 3558
       "resolved": "https://registry.npmjs.org/ast-types-flow/-/ast-types-flow-0.0.7.tgz",
3425 3559
       "integrity": "sha512-eBvWn1lvIApYMhzQMsu9ciLfkBY499mFZlNqG+/9WR7PVlroQw0vG30cOQQbaKz3sCEc44TAOu2ykzqXSNnwag=="
3426 3560
     },
3561
+    "asynckit": {
3562
+      "version": "0.4.0",
3563
+      "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
3564
+      "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
3565
+    },
3427 3566
     "axe-core": {
3428 3567
       "version": "4.5.2",
3429 3568
       "resolved": "https://registry.npmjs.org/axe-core/-/axe-core-4.5.2.tgz",
@@ -3502,6 +3641,14 @@
3502 3641
       "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
3503 3642
       "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
3504 3643
     },
3644
+    "combined-stream": {
3645
+      "version": "1.0.8",
3646
+      "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
3647
+      "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
3648
+      "requires": {
3649
+        "delayed-stream": "~1.0.0"
3650
+      }
3651
+    },
3505 3652
     "concat-map": {
3506 3653
       "version": "0.0.1",
3507 3654
       "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
@@ -3559,6 +3706,11 @@
3559 3706
         "object-keys": "^1.1.1"
3560 3707
       }
3561 3708
     },
3709
+    "delayed-stream": {
3710
+      "version": "1.0.0",
3711
+      "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
3712
+      "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ=="
3713
+    },
3562 3714
     "dir-glob": {
3563 3715
       "version": "3.0.1",
3564 3716
       "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz",
@@ -4047,6 +4199,16 @@
4047 4199
       "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.7.tgz",
4048 4200
       "integrity": "sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ=="
4049 4201
     },
4202
+    "form-data": {
4203
+      "version": "3.0.1",
4204
+      "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz",
4205
+      "integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==",
4206
+      "requires": {
4207
+        "asynckit": "^0.4.0",
4208
+        "combined-stream": "^1.0.8",
4209
+        "mime-types": "^2.1.12"
4210
+      }
4211
+    },
4050 4212
     "fs.realpath": {
4051 4213
       "version": "1.0.0",
4052 4214
       "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
@@ -4484,6 +4646,19 @@
4484 4646
         "picomatch": "^2.3.1"
4485 4647
       }
4486 4648
     },
4649
+    "mime-db": {
4650
+      "version": "1.52.0",
4651
+      "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
4652
+      "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg=="
4653
+    },
4654
+    "mime-types": {
4655
+      "version": "2.1.35",
4656
+      "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
4657
+      "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
4658
+      "requires": {
4659
+        "mime-db": "1.52.0"
4660
+      }
4661
+    },
4487 4662
     "minimatch": {
4488 4663
       "version": "3.1.2",
4489 4664
       "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
@@ -4537,6 +4712,14 @@
4537 4712
         "styled-jsx": "5.1.0"
4538 4713
       }
4539 4714
     },
4715
+    "node-fetch": {
4716
+      "version": "2.6.7",
4717
+      "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz",
4718
+      "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==",
4719
+      "requires": {
4720
+        "whatwg-url": "^5.0.0"
4721
+      }
4722
+    },
4540 4723
     "object-assign": {
4541 4724
       "version": "4.1.1",
4542 4725
       "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
@@ -4974,6 +5157,11 @@
4974 5157
         "is-number": "^7.0.0"
4975 5158
       }
4976 5159
     },
5160
+    "tr46": {
5161
+      "version": "0.0.3",
5162
+      "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
5163
+      "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw=="
5164
+    },
4977 5165
     "tsconfig-paths": {
4978 5166
       "version": "3.14.1",
4979 5167
       "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.14.1.tgz",
@@ -5042,6 +5230,20 @@
5042 5230
         "punycode": "^2.1.0"
5043 5231
       }
5044 5232
     },
5233
+    "webidl-conversions": {
5234
+      "version": "3.0.1",
5235
+      "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
5236
+      "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="
5237
+    },
5238
+    "whatwg-url": {
5239
+      "version": "5.0.0",
5240
+      "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
5241
+      "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",
5242
+      "requires": {
5243
+        "tr46": "~0.0.3",
5244
+        "webidl-conversions": "^3.0.0"
5245
+      }
5246
+    },
5045 5247
     "which": {
5046 5248
       "version": "2.0.2",
5047 5249
       "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",

+ 1
- 0
package.json Dosyayı Görüntüle

@@ -9,6 +9,7 @@
9 9
     "lint": "next lint"
10 10
   },
11 11
   "dependencies": {
12
+    "@notionhq/client": "^2.2.2",
12 13
     "@types/node": "18.11.11",
13 14
     "@types/react": "18.0.26",
14 15
     "@types/react-dom": "18.0.9",

+ 24
- 5
pages/api/getTopicList.ts Dosyayı Görüntüle

@@ -1,13 +1,32 @@
1 1
 // Next.js API route support: https://nextjs.org/docs/api-routes/introduction
2 2
 import type { NextApiRequest, NextApiResponse } from "next";
3
+import { LAWS_BLOCK_ID } from "../../config";
4
+import { notion } from "../../lib/notion";
3 5
 
4
-type Data = {
6
+interface Topic {
7
+  blockId: string;
5 8
   name: string;
6
-};
9
+}
10
+
11
+function getTopicsInDatabase(notionResp: any): Topic[] {
12
+  return notionResp.results.map((block: any) => ({
13
+    blockId: block.id,
14
+    name: block.properties.Name.title[0].plain_text,
15
+  }));
16
+}
7 17
 
8
-export default function handler(
18
+export default async function handler(
9 19
   req: NextApiRequest,
10
-  res: NextApiResponse<Data>
20
+  res: NextApiResponse<Topic[]>
11 21
 ) {
12
-  res.status(200).json({ name: "John Doe" });
22
+  const resp = await notion.databases.query({
23
+    database_id: LAWS_BLOCK_ID,
24
+    sorts: [
25
+      {
26
+        property: "Created",
27
+        direction: "ascending",
28
+      },
29
+    ],
30
+  });
31
+  res.status(200).json(getTopicsInDatabase(resp));
13 32
 }