From 77def4fa9500c47181c67c906f7146d6e7064ad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Arod?= Date: Sun, 8 Sep 2024 16:50:51 +0200 Subject: [PATCH] refactor: deplace checkDbSchemas to separate file --- src/index.ts | 7 ++++++- .../fetch/fetchFamiliesWithEventsFromNotion.ts | 6 ------ .../checkDbPropertyOptionsMatchesType.ts | 2 +- src/notion/fetch/schemaCheck/checkDbSchemas.ts | 10 ++++++++++ .../fetch/{ => schemaCheck}/checkEventDbSchema.ts | 2 +- .../fetch/{ => schemaCheck}/checkFamilyDbSchema.ts | 13 ++++++------- 6 files changed, 24 insertions(+), 16 deletions(-) rename src/notion/fetch/{ => schemaCheck}/checkDbPropertyOptionsMatchesType.ts (95%) create mode 100644 src/notion/fetch/schemaCheck/checkDbSchemas.ts rename src/notion/fetch/{ => schemaCheck}/checkEventDbSchema.ts (89%) rename src/notion/fetch/{ => schemaCheck}/checkFamilyDbSchema.ts (66%) diff --git a/src/index.ts b/src/index.ts index 178f4f6..8311492 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,6 +12,7 @@ import { computeStatsGenerales } from "./statistiques/v2/generales/computeStatsG import { statsGeneralesDesc } from "./statistiques/v2/generales/StatsGenerales"; import { computeStatsSociales } from "./statistiques/v2/sociales/computeStatsSociales"; import { statsSocialesDesc } from "./statistiques/v2/sociales/StatsSociales"; +import { checkDbSchemas } from "./notion/fetch/schemaCheck/checkDbSchemas"; type ProcessOptions = { dryRun: boolean; @@ -40,8 +41,12 @@ function buildProcessOptions(): ProcessOptions { auth: options.notionApiToken, }); - const doFetch = true; + console.log("Checking DB schemas..."); + await checkDbSchemas(notionClient); + console.log("Fetching families..."); + const doFetch = true; + const familles = doFetch ? await fetchFamiliesWithEventsFromNotion(notionClient) : []; diff --git a/src/notion/fetch/fetchFamiliesWithEventsFromNotion.ts b/src/notion/fetch/fetchFamiliesWithEventsFromNotion.ts index 9798bb9..1f70835 100644 --- a/src/notion/fetch/fetchFamiliesWithEventsFromNotion.ts +++ b/src/notion/fetch/fetchFamiliesWithEventsFromNotion.ts @@ -20,18 +20,12 @@ import { propPenal, propSocial, } from "./dbfamilleDesc"; -import { checkFamilyDbSchema } from "./checkFamilyDbSchema"; -import { checkEventDbSchema } from "./checkEventDbSchema"; import { StatutPenal } from "../../data/StatutPenal"; import { StatutSocial } from "../../data/StatutSocial"; export async function fetchFamiliesWithEventsFromNotion( notionClient: Client ): Promise { - await checkFamilyDbSchema(notionClient, familiesDbId); - - await checkEventDbSchema(notionClient, familEventsDbId); - const eventPages = ( await queryAllDbResults(notionClient, { database_id: familEventsDbId, diff --git a/src/notion/fetch/checkDbPropertyOptionsMatchesType.ts b/src/notion/fetch/schemaCheck/checkDbPropertyOptionsMatchesType.ts similarity index 95% rename from src/notion/fetch/checkDbPropertyOptionsMatchesType.ts rename to src/notion/fetch/schemaCheck/checkDbPropertyOptionsMatchesType.ts index 89eee83..2726f0f 100644 --- a/src/notion/fetch/checkDbPropertyOptionsMatchesType.ts +++ b/src/notion/fetch/schemaCheck/checkDbPropertyOptionsMatchesType.ts @@ -2,7 +2,7 @@ import { DatabaseObjectResponse, GetDatabaseResponse, } from "@notionhq/client/build/src/api-endpoints"; -import { richTextToPlainText } from "../utils/text/richTextToPlainText"; +import { richTextToPlainText } from "../../utils/text/richTextToPlainText"; export function checkDbPropertyOptionsMatchesType( db: DatabaseObjectResponse, diff --git a/src/notion/fetch/schemaCheck/checkDbSchemas.ts b/src/notion/fetch/schemaCheck/checkDbSchemas.ts new file mode 100644 index 0000000..20bddea --- /dev/null +++ b/src/notion/fetch/schemaCheck/checkDbSchemas.ts @@ -0,0 +1,10 @@ +import { Client } from "@notionhq/client"; +import { checkEventDbSchema } from "./checkEventDbSchema"; +import { checkFamilyDbSchema } from "./checkFamilyDbSchema"; +import { familiesDbId } from "../dbfamilleDesc"; +import { familEventsDbId } from "../dbIds"; + +export async function checkDbSchemas(notionClient: Client) { + await checkFamilyDbSchema(notionClient, familiesDbId); + await checkEventDbSchema(notionClient, familEventsDbId); +} diff --git a/src/notion/fetch/checkEventDbSchema.ts b/src/notion/fetch/schemaCheck/checkEventDbSchema.ts similarity index 89% rename from src/notion/fetch/checkEventDbSchema.ts rename to src/notion/fetch/schemaCheck/checkEventDbSchema.ts index 283a866..33a7a60 100644 --- a/src/notion/fetch/checkEventDbSchema.ts +++ b/src/notion/fetch/schemaCheck/checkEventDbSchema.ts @@ -1,5 +1,5 @@ import { Client } from "@notionhq/client"; -import { typesEvenements } from "../../data/TypeEvenement"; +import { typesEvenements } from "../../../data/TypeEvenement"; import { checkDbPropertyOptionsMatchesType } from "./checkDbPropertyOptionsMatchesType"; import { DatabaseObjectResponse } from "@notionhq/client/build/src/api-endpoints"; diff --git a/src/notion/fetch/checkFamilyDbSchema.ts b/src/notion/fetch/schemaCheck/checkFamilyDbSchema.ts similarity index 66% rename from src/notion/fetch/checkFamilyDbSchema.ts rename to src/notion/fetch/schemaCheck/checkFamilyDbSchema.ts index 64c9b3f..61c87b3 100644 --- a/src/notion/fetch/checkFamilyDbSchema.ts +++ b/src/notion/fetch/schemaCheck/checkFamilyDbSchema.ts @@ -1,11 +1,11 @@ import { Client } from "@notionhq/client"; -import { contexteEntreeDCs } from "../../data/ContexteEntreeDC"; -import { statutsFamille } from "../../data/StatutFamille"; +import { contexteEntreeDCs } from "../../../data/ContexteEntreeDC"; +import { statutsFamille } from "../../../data/StatutFamille"; import { checkDbPropertyOptionsMatchesType } from "./checkDbPropertyOptionsMatchesType"; -import { propContexteEntree, propPenal, propSocial } from "./dbfamilleDesc"; -import { optionsStatutSocial } from "../../data/StatutSocial"; -import { optionsStatutPenal } from "../../data/StatutPenal"; -import { propStatut } from "./dbfamilleDesc"; +import { propContexteEntree, propPenal, propSocial } from "../dbfamilleDesc"; +import { optionsStatutSocial } from "../../../data/StatutSocial"; +import { optionsStatutPenal } from "../../../data/StatutPenal"; +import { propStatut } from "../dbfamilleDesc"; import { DatabaseObjectResponse } from "@notionhq/client/build/src/api-endpoints"; export async function checkFamilyDbSchema( @@ -21,7 +21,6 @@ export async function checkFamilyDbSchema( propContexteEntree, contexteEntreeDCs ); - checkDbPropertyOptionsMatchesType(familyDb, propPenal, optionsStatutPenal); checkDbPropertyOptionsMatchesType(familyDb, propSocial, optionsStatutSocial); }