mirror of
https://framagit.org/enfance-libre/statistiques
synced 2025-12-08 01:33:44 +00:00
51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
|
|
import { Client } from "@notionhq/client";
|
||
|
|
import {
|
||
|
|
PageObjectResponse,
|
||
|
|
QueryDatabaseParameters,
|
||
|
|
} from "@notionhq/client/build/src/api-endpoints";
|
||
|
|
import { Family, FamilyStatus } from "../../data/Family";
|
||
|
|
import { datePropertyToDate } from "../utils/properties/datePropertyToDate";
|
||
|
|
import { statusPropertyToText } from "../utils/properties/statusPropertyToText";
|
||
|
|
import { titlePropertyToText } from "../utils/properties/titlePropertyToText copy";
|
||
|
|
import { queryAllDbResults } from "../utils/queryAllDbResults";
|
||
|
|
import { assertFullPage } from "../utils/types/assertFullPage";
|
||
|
|
|
||
|
|
export async function fetchFamiliesWithEventsFromNotion(
|
||
|
|
notionClient: Client
|
||
|
|
): Promise<Family[]> {
|
||
|
|
const familiesDbId: string = "5b69e02b296d4a578f8c8ab7fe8b05da";
|
||
|
|
const dbQuery: QueryDatabaseParameters = {
|
||
|
|
database_id: familiesDbId,
|
||
|
|
/*filter: {
|
||
|
|
property: "Statut",
|
||
|
|
status: {
|
||
|
|
equals: "Résistant.e",
|
||
|
|
},
|
||
|
|
},*/
|
||
|
|
};
|
||
|
|
|
||
|
|
const results = await queryAllDbResults(notionClient, dbQuery);
|
||
|
|
const families: Family[] = await Promise.all(
|
||
|
|
results.map((pageObjectResponse) => {
|
||
|
|
assertFullPage(pageObjectResponse);
|
||
|
|
return buildFamily(pageObjectResponse);
|
||
|
|
})
|
||
|
|
);
|
||
|
|
return families;
|
||
|
|
}
|
||
|
|
|
||
|
|
function buildFamily(page: PageObjectResponse): Family {
|
||
|
|
const pageProperties = page.properties;
|
||
|
|
|
||
|
|
// TODO Fetch Family Events
|
||
|
|
const family: Family = {
|
||
|
|
notionId: page.id,
|
||
|
|
title: titlePropertyToText(pageProperties, ""),
|
||
|
|
status: statusPropertyToText(pageProperties, "Statut") as FamilyStatus,
|
||
|
|
startResistsant: datePropertyToDate(pageProperties, "Intégration"),
|
||
|
|
endResistant: datePropertyToDate(pageProperties, "Sortie"),
|
||
|
|
evenements: [],
|
||
|
|
};
|
||
|
|
return family;
|
||
|
|
}
|