From 86fd13d2892ac29652cc54a7ee11ac75b2d376cc Mon Sep 17 00:00:00 2001 From: Ike Saunders Date: Mon, 25 Nov 2024 10:04:29 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20unpublished=20chart=20dele?= =?UTF-8?q?te?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adminSiteServer/apiRouter.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/adminSiteServer/apiRouter.ts b/adminSiteServer/apiRouter.ts index c9288112f5f..bef706217c6 100644 --- a/adminSiteServer/apiRouter.ts +++ b/adminSiteServer/apiRouter.ts @@ -1066,12 +1066,14 @@ deleteRouteWithRWTransaction( "/charts/:chartId", async (req, res, trx) => { const chart = await expectChartById(trx, req.params.chartId) - const links = await getPublishedLinksTo(trx, [chart.slug!]) - if (links.length) { - const sources = links.map((link) => link.sourceSlug).join(", ") - throw new Error( - `Cannot delete chart in-use in the following published documents: ${sources}` - ) + if (chart.slug) { + const links = await getPublishedLinksTo(trx, [chart.slug]) + if (links.length) { + const sources = links.map((link) => link.sourceSlug).join(", ") + throw new Error( + `Cannot delete chart in-use in the following published documents: ${sources}` + ) + } } await db.knexRaw(trx, `DELETE FROM chart_dimensions WHERE chartId=?`, [