Prevent deleting built-in layout ID's as autoscreens depends on them
This commit is contained in:
parent
6bc30eb5cb
commit
91939a2be0
|
@ -1,4 +1,7 @@
|
||||||
const { EMPTY_LAYOUT } = require("../../constants/layouts")
|
const {
|
||||||
|
EMPTY_LAYOUT,
|
||||||
|
BASE_LAYOUT_PROP_IDS,
|
||||||
|
} = require("../../constants/layouts")
|
||||||
const CouchDB = require("../../db")
|
const CouchDB = require("../../db")
|
||||||
const { generateLayoutID, getScreenParams } = require("../../db/utils")
|
const { generateLayoutID, getScreenParams } = require("../../db/utils")
|
||||||
|
|
||||||
|
@ -26,15 +29,19 @@ exports.destroy = async function (ctx) {
|
||||||
const layoutId = ctx.params.layoutId,
|
const layoutId = ctx.params.layoutId,
|
||||||
layoutRev = ctx.params.layoutRev
|
layoutRev = ctx.params.layoutRev
|
||||||
|
|
||||||
const layoutsUsedByScreens = (
|
if (Object.values(BASE_LAYOUT_PROP_IDS).includes(layoutId)) {
|
||||||
await db.allDocs(
|
ctx.throw(400, "Cannot delete a built-in layout")
|
||||||
getScreenParams(null, {
|
} else {
|
||||||
include_docs: true,
|
const layoutsUsedByScreens = (
|
||||||
})
|
await db.allDocs(
|
||||||
)
|
getScreenParams(null, {
|
||||||
).rows.map(element => element.doc.layoutId)
|
include_docs: true,
|
||||||
if (layoutsUsedByScreens.includes(layoutId)) {
|
})
|
||||||
ctx.throw(400, "Cannot delete a layout that's being used by a screen")
|
)
|
||||||
|
).rows.map(element => element.doc.layoutId)
|
||||||
|
if (layoutsUsedByScreens.includes(layoutId)) {
|
||||||
|
ctx.throw(400, "Cannot delete a layout that's being used by a screen")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await db.remove(layoutId, layoutRev)
|
await db.remove(layoutId, layoutRev)
|
||||||
|
|
Loading…
Reference in New Issue