Skip to content

Commit

Permalink
add-notion-logger
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroki0525 committed Nov 8, 2023
1 parent ebaa260 commit 1eb343c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"scripts": {
"build": "tsup --config ../../tsup.config.ts",
"init": "tsx init.ts",
"dev:miro": "tsx script/generateDandoriMiroCards.ts",
"dev:notion": "tsx script/generateDandoriNotionPages.ts",
"dev:miro": "tsx scripts/generateDandoriMiroCards.ts",
"dev:notion": "tsx scripts/generateDandoriNotionPages.ts",
"test": "vitest run"
},
"keywords": [],
Expand Down
15 changes: 11 additions & 4 deletions packages/ui/src/notion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import {
DandoriTaskRequiredProperty,
DandoriTaskStatus,
} from "@dandori/core";
import { Client } from "@notionhq/client";
import { runPromisesSequentially } from "@dandori/libs";
import { CreatePageParameters } from "@notionhq/client/build/src/api-endpoints";
import { Client, LogLevel } from "@notionhq/client";
import { getLogger, runPromisesSequentially } from "@dandori/libs";

type SupportNotionTaskOptionalProperty =
| Exclude<DandoriTaskOptionalProperty, "assignee">
Expand All @@ -24,7 +23,7 @@ export type GenerateDandoriNotionDatabaseItemsOptions = {
const createPageParams = (
task: DandoriTask,
options: GenerateDandoriNotionDatabaseItemsOptions,
): CreatePageParameters => {
): Parameters<InstanceType<typeof Client>["pages"]["create"]>[0] => {
const propsMap = options.databasePropertiesMap;
const { deadline, description, status, name } = task;
const {
Expand Down Expand Up @@ -89,8 +88,16 @@ export async function generateDandoriNotionPages(
tasks: DandoriTask[],
options: GenerateDandoriNotionDatabaseItemsOptions,
): Promise<void> {
const logger = getLogger();
const client = new Client({
auth: process.env.NOTION_TOKEN,
logger: (
level: LogLevel,
message: string,
extraInfo: Record<string, unknown>,
) => {
logger[level](message, extraInfo);
},
});
const createPages = tasks.map((task) => () => {
const pageParams = createPageParams(task, options);
Expand Down
18 changes: 9 additions & 9 deletions packages/ui/templates/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,62 @@ export const tasks: DandoriTask[] = [
{
id: "1",
name: "task1",
deadline: "2021-01-01",
deadline: "2050-01-01",
description: "task1-description",
fromTaskIdList: [],
status: "done",
status: "todo",
},
{
id: "2",
name: "task2",
deadline: "2021-01-02",
deadline: "2050-01-02",
description: "task2-description",
fromTaskIdList: ["1"],
status: "doing",
},
{
id: "3",
name: "task3",
deadline: "2021-01-03",
deadline: "2050-01-03",
description: "task3-description",
fromTaskIdList: ["1"],
status: "doing",
},
{
id: "4",
name: "task4",
deadline: "2021-01-04",
deadline: "2050-01-04",
description: "task4-description",
fromTaskIdList: ["2", "3"],
status: "todo",
},
{
id: "5",
name: "task5",
deadline: "2021-01-05",
deadline: "2050-01-05",
description: "task5-description",
fromTaskIdList: [],
},
{
id: "6",
name: "task6",
deadline: "2021-01-06",
deadline: "2050-01-06",
description: "task6-description",
fromTaskIdList: ["5"],
status: "doing",
},
{
id: "7",
name: "task7",
deadline: "2021-01-07",
deadline: "2050-01-07",
description: "task7-description",
fromTaskIdList: ["5"],
status: "doing",
},
{
id: "8",
name: "task8",
deadline: "2021-01-08",
deadline: "2050-01-08",
description: "task8-description",
fromTaskIdList: ["6", "7"],
status: "done",
Expand Down

0 comments on commit 1eb343c

Please sign in to comment.