refactor: deplace checkDbSchemas to separate file

wip-related-pages
Sébastien Arod 2024-09-08 16:50:51 +02:00
parent e718874a3a
commit 77def4fa95
6 changed files with 24 additions and 16 deletions

View File

@ -12,6 +12,7 @@ import { computeStatsGenerales } from "./statistiques/v2/generales/computeStatsG
import { statsGeneralesDesc } from "./statistiques/v2/generales/StatsGenerales"; import { statsGeneralesDesc } from "./statistiques/v2/generales/StatsGenerales";
import { computeStatsSociales } from "./statistiques/v2/sociales/computeStatsSociales"; import { computeStatsSociales } from "./statistiques/v2/sociales/computeStatsSociales";
import { statsSocialesDesc } from "./statistiques/v2/sociales/StatsSociales"; import { statsSocialesDesc } from "./statistiques/v2/sociales/StatsSociales";
import { checkDbSchemas } from "./notion/fetch/schemaCheck/checkDbSchemas";
type ProcessOptions = { type ProcessOptions = {
dryRun: boolean; dryRun: boolean;
@ -40,8 +41,12 @@ function buildProcessOptions(): ProcessOptions {
auth: options.notionApiToken, auth: options.notionApiToken,
}); });
const doFetch = true; console.log("Checking DB schemas...");
await checkDbSchemas(notionClient);
console.log("Fetching families..."); console.log("Fetching families...");
const doFetch = true;
const familles = doFetch const familles = doFetch
? await fetchFamiliesWithEventsFromNotion(notionClient) ? await fetchFamiliesWithEventsFromNotion(notionClient)
: []; : [];

View File

@ -20,18 +20,12 @@ import {
propPenal, propPenal,
propSocial, propSocial,
} from "./dbfamilleDesc"; } from "./dbfamilleDesc";
import { checkFamilyDbSchema } from "./checkFamilyDbSchema";
import { checkEventDbSchema } from "./checkEventDbSchema";
import { StatutPenal } from "../../data/StatutPenal"; import { StatutPenal } from "../../data/StatutPenal";
import { StatutSocial } from "../../data/StatutSocial"; import { StatutSocial } from "../../data/StatutSocial";
export async function fetchFamiliesWithEventsFromNotion( export async function fetchFamiliesWithEventsFromNotion(
notionClient: Client notionClient: Client
): Promise<Famille[]> { ): Promise<Famille[]> {
await checkFamilyDbSchema(notionClient, familiesDbId);
await checkEventDbSchema(notionClient, familEventsDbId);
const eventPages = ( const eventPages = (
await queryAllDbResults(notionClient, { await queryAllDbResults(notionClient, {
database_id: familEventsDbId, database_id: familEventsDbId,

View File

@ -2,7 +2,7 @@ import {
DatabaseObjectResponse, DatabaseObjectResponse,
GetDatabaseResponse, GetDatabaseResponse,
} from "@notionhq/client/build/src/api-endpoints"; } from "@notionhq/client/build/src/api-endpoints";
import { richTextToPlainText } from "../utils/text/richTextToPlainText"; import { richTextToPlainText } from "../../utils/text/richTextToPlainText";
export function checkDbPropertyOptionsMatchesType( export function checkDbPropertyOptionsMatchesType(
db: DatabaseObjectResponse, db: DatabaseObjectResponse,

View File

@ -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);
}

View File

@ -1,5 +1,5 @@
import { Client } from "@notionhq/client"; import { Client } from "@notionhq/client";
import { typesEvenements } from "../../data/TypeEvenement"; import { typesEvenements } from "../../../data/TypeEvenement";
import { checkDbPropertyOptionsMatchesType } from "./checkDbPropertyOptionsMatchesType"; import { checkDbPropertyOptionsMatchesType } from "./checkDbPropertyOptionsMatchesType";
import { DatabaseObjectResponse } from "@notionhq/client/build/src/api-endpoints"; import { DatabaseObjectResponse } from "@notionhq/client/build/src/api-endpoints";

View File

@ -1,11 +1,11 @@
import { Client } from "@notionhq/client"; import { Client } from "@notionhq/client";
import { contexteEntreeDCs } from "../../data/ContexteEntreeDC"; import { contexteEntreeDCs } from "../../../data/ContexteEntreeDC";
import { statutsFamille } from "../../data/StatutFamille"; import { statutsFamille } from "../../../data/StatutFamille";
import { checkDbPropertyOptionsMatchesType } from "./checkDbPropertyOptionsMatchesType"; import { checkDbPropertyOptionsMatchesType } from "./checkDbPropertyOptionsMatchesType";
import { propContexteEntree, propPenal, propSocial } from "./dbfamilleDesc"; import { propContexteEntree, propPenal, propSocial } from "../dbfamilleDesc";
import { optionsStatutSocial } from "../../data/StatutSocial"; import { optionsStatutSocial } from "../../../data/StatutSocial";
import { optionsStatutPenal } from "../../data/StatutPenal"; import { optionsStatutPenal } from "../../../data/StatutPenal";
import { propStatut } from "./dbfamilleDesc"; import { propStatut } from "../dbfamilleDesc";
import { DatabaseObjectResponse } from "@notionhq/client/build/src/api-endpoints"; import { DatabaseObjectResponse } from "@notionhq/client/build/src/api-endpoints";
export async function checkFamilyDbSchema( export async function checkFamilyDbSchema(
@ -21,7 +21,6 @@ export async function checkFamilyDbSchema(
propContexteEntree, propContexteEntree,
contexteEntreeDCs contexteEntreeDCs
); );
checkDbPropertyOptionsMatchesType(familyDb, propPenal, optionsStatutPenal); checkDbPropertyOptionsMatchesType(familyDb, propPenal, optionsStatutPenal);
checkDbPropertyOptionsMatchesType(familyDb, propSocial, optionsStatutSocial); checkDbPropertyOptionsMatchesType(familyDb, propSocial, optionsStatutSocial);
} }