From 5b90d2c21be7622c7fd72afd76528237c752022d Mon Sep 17 00:00:00 2001 From: Marcel Gerber Date: Mon, 27 Jan 2025 13:26:46 +0100 Subject: [PATCH] enhance(gdocs): validate narrative chart components --- db/model/Gdoc/GdocBase.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/db/model/Gdoc/GdocBase.ts b/db/model/Gdoc/GdocBase.ts index 46dbafaebb..64e0c4fb00 100644 --- a/db/model/Gdoc/GdocBase.ts +++ b/db/model/Gdoc/GdocBase.ts @@ -803,6 +803,9 @@ export class GdocBase implements OwidGdocBaseInterface { const chartIdsBySlug = await mapSlugsToIds(knex) const publishedExplorersBySlug = await db.getPublishedExplorersBySlug(knex) + const chartViewNames = await getChartViewsInfo(knex) + .then((cv) => cv.map((c) => c.name)) + .then((chartViewNames) => new Set(chartViewNames)) const linkErrors: OwidGdocErrorMessage[] = [] for (const link of this.links) { @@ -847,6 +850,16 @@ export class GdocBase implements OwidGdocBaseInterface { } break } + case OwidGdocLinkType.ChartView: { + if (!chartViewNames.has(link.target)) { + linkErrors.push({ + property: "content", + message: `Narrative chart with name ${link.target} does not exist`, + type: OwidGdocErrorMessageType.Error, + }) + } + break + } } }