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 { 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)
: [];

View File

@ -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<Famille[]> {
await checkFamilyDbSchema(notionClient, familiesDbId);
await checkEventDbSchema(notionClient, familEventsDbId);
const eventPages = (
await queryAllDbResults(notionClient, {
database_id: familEventsDbId,

View File

@ -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,

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 { typesEvenements } from "../../data/TypeEvenement";
import { typesEvenements } from "../../../data/TypeEvenement";
import { checkDbPropertyOptionsMatchesType } from "./checkDbPropertyOptionsMatchesType";
import { DatabaseObjectResponse } from "@notionhq/client/build/src/api-endpoints";

View File

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