statistiques/src/notion/publish/v2/publishStatsToPage.ts

25 lines
759 B
TypeScript
Raw Normal View History

2024-09-17 16:01:16 +02:00
import { Client } from "@notionhq/client";
2024-09-05 09:23:27 +02:00
import {
StatGroupDesc,
StatsType,
2024-09-17 13:54:59 +02:00
} from "../../../statistiques/v2/desc/StatsDesc";
2024-09-17 16:01:16 +02:00
import { createStatGroupChildrenListItemBlock } from "./createStatGroupListItemBlock";
import { updatePageContent } from "./updatePageContent";
2024-09-20 12:55:26 +02:00
import { createParagraphBlock } from "../blocks/createParagraphBlock";
2024-09-05 09:23:27 +02:00
export async function publishStatsToPage<D extends StatGroupDesc>(
notionClient: Client,
statsPageId: string,
2024-09-17 16:01:16 +02:00
pageHeader: string,
2024-09-05 09:23:27 +02:00
descriptor: D,
stats: StatsType<D>
) {
2024-09-17 16:01:16 +02:00
const statsBlocks = createStatGroupChildrenListItemBlock(descriptor, stats);
2024-09-05 09:23:27 +02:00
2024-09-17 16:01:16 +02:00
const textBlock = createParagraphBlock(pageHeader);
await updatePageContent(notionClient, statsPageId, [
textBlock,
...statsBlocks,
]);
2024-09-05 09:23:27 +02:00
}