Skip to content

Commit

Permalink
Merge pull request #4211 from owid/fix-unpublished-chart-delete
Browse files Browse the repository at this point in the history
🐛 fix unpublished chart delete
  • Loading branch information
ikesau authored Dec 5, 2024
2 parents 4736d04 + 86fd13d commit ac960f3
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions adminSiteServer/apiRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1081,12 +1081,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=?`, [
Expand Down

0 comments on commit ac960f3

Please sign in to comment.