Skip to content

Commit

Permalink
🐛 fix unpublished chart delete
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesau committed Nov 25, 2024
1 parent 5fe6edc commit 86fd13d
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 @@ -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=?`, [
Expand Down

0 comments on commit 86fd13d

Please sign in to comment.