Browse Source

[feat] Move types to separate file

Sergio Mattei 1 year ago
parent
commit
89ee9da03b
3 changed files with 13 additions and 12 deletions
  1. 1
    2
      lib/notion.ts
  2. 2
    10
      pages/api/getTopicList.ts
  3. 10
    0
      types.ts

+ 1
- 2
lib/notion.ts View File

@@ -1,11 +1,10 @@
1 1
 import { NOTION_KEY } from "../config";
2
+import { DatabaseType } from "../types";
2 3
 
3 4
 const { Client } = require("@notionhq/client");
4 5
 
5 6
 export const notion = new Client({ auth: NOTION_KEY });
6 7
 
7
-export type DatabaseType = "laws" | "advice";
8
-
9 8
 /**
10 9
  * Translates incoming GET parameters into a valid block ID.
11 10
  * @param type

+ 2
- 10
pages/api/getTopicList.ts View File

@@ -1,15 +1,7 @@
1 1
 // Next.js API route support: https://nextjs.org/docs/api-routes/introduction
2 2
 import type { NextApiRequest, NextApiResponse } from "next";
3
-import { DatabaseType, getDatabaseId, notion } from "../../lib/notion";
4
-
5
-interface Topic {
6
-  blockId: string;
7
-  name: string;
8
-}
9
-
10
-interface Error {
11
-  status: string;
12
-}
3
+import { getDatabaseId, notion } from "../../lib/notion";
4
+import { DatabaseType, Error, Topic } from "../../types";
13 5
 
14 6
 function getTopicsInDatabase(notionResp: any): Topic[] {
15 7
   return notionResp.results.map((block: any) => ({

+ 10
- 0
types.ts View File

@@ -0,0 +1,10 @@
1
+export type DatabaseType = "laws" | "advice";
2
+
3
+export interface Topic {
4
+  blockId: string;
5
+  name: string;
6
+}
7
+
8
+export interface Error {
9
+  status: string;
10
+}