feat: ajoute la date de mise à jour des stats
parent
5279983ae8
commit
39eb9b08b4
|
@ -27,9 +27,11 @@ import { computeELStats } from "./statistiques/computeELStats";
|
||||||
console.log(consistencyIssues);
|
console.log(consistencyIssues);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const currentDate = new Date(Date.now());
|
||||||
|
|
||||||
console.log("Building statistics...");
|
console.log("Building statistics...");
|
||||||
const resistantCountStats = computeELStats(families);
|
const resistantCountStats = computeELStats(families);
|
||||||
|
|
||||||
console.log("Publishing statistics...");
|
console.log("Publishing statistics...");
|
||||||
publishStatisticsToNotion(resistantCountStats, notionClient);
|
publishStatisticsToNotion(resistantCountStats, currentDate, notionClient);
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import { Client } from "@notionhq/client";
|
import { Client, isFullBlock } from "@notionhq/client";
|
||||||
import { ELStats } from "../../statistiques/ELStats";
|
import { ELStats } from "../../statistiques/ELStats";
|
||||||
|
import { listAllChildrenBlocks } from "../utils/listAllChildrenBlocks";
|
||||||
|
import { richTextToPlainText } from "../utils/text/richTextToPlainText";
|
||||||
import { publishPeriodStats } from "./publishPeriodStats";
|
import { publishPeriodStats } from "./publishPeriodStats";
|
||||||
import { publishStatsActuelles } from "./publishStatsActuelles";
|
import { publishStatsActuelles } from "./publishStatsActuelles";
|
||||||
|
|
||||||
|
@ -10,11 +12,52 @@ const yearStatsDb = "4b19a72aa07840eab948525ea41878ee";
|
||||||
const monthStatsDb = "8418a8a4a7544f6a8c54e6003be7efe5";
|
const monthStatsDb = "8418a8a4a7544f6a8c54e6003be7efe5";
|
||||||
export async function publishStatisticsToNotion(
|
export async function publishStatisticsToNotion(
|
||||||
stats: ELStats,
|
stats: ELStats,
|
||||||
|
currentDate: Date,
|
||||||
notionClient: Client
|
notionClient: Client
|
||||||
) {
|
) {
|
||||||
|
await updateUpdateDate(notionClient, currentDate);
|
||||||
await publishStatsActuelles(notionClient, stats.actuelles);
|
await publishStatsActuelles(notionClient, stats.actuelles);
|
||||||
|
|
||||||
await publishPeriodStats(notionClient, yearStatsDb, stats.annees);
|
await publishPeriodStats(notionClient, yearStatsDb, stats.annees);
|
||||||
|
|
||||||
await publishPeriodStats(notionClient, monthStatsDb, stats.mois);
|
await publishPeriodStats(notionClient, monthStatsDb, stats.mois);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function updateUpdateDate(notionClient: Client, updateDate: Date) {
|
||||||
|
const childrenBlocks = (
|
||||||
|
await listAllChildrenBlocks(notionClient, {
|
||||||
|
block_id: statsPageId,
|
||||||
|
})
|
||||||
|
).filter(isFullBlock);
|
||||||
|
|
||||||
|
const blockTextPrefix = "Dernière mise à jour des statistiques : ";
|
||||||
|
const block = childrenBlocks.find(
|
||||||
|
(b) =>
|
||||||
|
b.type === "paragraph" &&
|
||||||
|
richTextToPlainText(b.paragraph.rich_text).startsWith(blockTextPrefix)
|
||||||
|
);
|
||||||
|
if (!block) {
|
||||||
|
console.log(`Could not find block starting with "${blockTextPrefix}"`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await notionClient.blocks.update({
|
||||||
|
block_id: block?.id,
|
||||||
|
paragraph: {
|
||||||
|
rich_text: [
|
||||||
|
{
|
||||||
|
text: {
|
||||||
|
content: blockTextPrefix,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
mention: {
|
||||||
|
date: {
|
||||||
|
start: updateDate.toISOString(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue