initial work towards page refactor.
This commit is contained in:
parent
1c0966ffc4
commit
b2da94c490
|
@ -20,29 +20,13 @@ exports.fetch = async ctx => {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.find = async ctx => {
|
|
||||||
const appId = ctx.user.appId
|
|
||||||
const db = new CouchDB(appId)
|
|
||||||
|
|
||||||
const screens = await db.allDocs(
|
|
||||||
getScreenParams(ctx.params.pageId, {
|
|
||||||
include_docs: true,
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
ctx.body = await new AccessController(appId).checkScreensAccess(
|
|
||||||
screens,
|
|
||||||
ctx.user.accessLevel._id
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.save = async ctx => {
|
exports.save = async ctx => {
|
||||||
const appId = ctx.user.appId
|
const appId = ctx.user.appId
|
||||||
const db = new CouchDB(appId)
|
const db = new CouchDB(appId)
|
||||||
const screen = ctx.request.body
|
const screen = ctx.request.body
|
||||||
|
|
||||||
if (!screen._id) {
|
if (!screen._id) {
|
||||||
screen._id = generateScreenID(ctx.params.pageId)
|
screen._id = generateScreenID()
|
||||||
}
|
}
|
||||||
delete screen._css
|
delete screen._css
|
||||||
const response = await db.put(screen)
|
const response = await db.put(screen)
|
||||||
|
|
|
@ -30,9 +30,8 @@ function generateSaveValidation() {
|
||||||
|
|
||||||
router
|
router
|
||||||
.get("/api/screens", authorized(BUILDER), controller.fetch)
|
.get("/api/screens", authorized(BUILDER), controller.fetch)
|
||||||
.get("/api/screens/:pageId", authorized(BUILDER), controller.find)
|
|
||||||
.post(
|
.post(
|
||||||
"/api/screens/:pageId",
|
"/api/screens",
|
||||||
authorized(BUILDER),
|
authorized(BUILDER),
|
||||||
generateSaveValidation(),
|
generateSaveValidation(),
|
||||||
controller.save
|
controller.save
|
||||||
|
|
|
@ -179,14 +179,6 @@ exports.getAccessLevelParams = (accessLevelId = null, otherProps = {}) => {
|
||||||
return getDocParams(DocumentTypes.ACCESS_LEVEL, accessLevelId, otherProps)
|
return getDocParams(DocumentTypes.ACCESS_LEVEL, accessLevelId, otherProps)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates a new webhook ID.
|
|
||||||
* @returns {string} The new webhook ID which the webhook doc can be stored under.
|
|
||||||
*/
|
|
||||||
exports.generateWebhookID = () => {
|
|
||||||
return `${DocumentTypes.WEBHOOK}${SEPARATOR}${newid()}`
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a new page ID.
|
* Generates a new page ID.
|
||||||
* @returns {string} The new page ID which the page doc can be stored under.
|
* @returns {string} The new page ID which the page doc can be stored under.
|
||||||
|
@ -206,15 +198,23 @@ exports.getPageParams = (pageId = null, otherProps = {}) => {
|
||||||
* Generates a new screen ID.
|
* Generates a new screen ID.
|
||||||
* @returns {string} The new screen ID which the screen doc can be stored under.
|
* @returns {string} The new screen ID which the screen doc can be stored under.
|
||||||
*/
|
*/
|
||||||
exports.generateScreenID = pageId => {
|
exports.generateScreenID = () => {
|
||||||
return `${DocumentTypes.SCREEN}${SEPARATOR}${pageId}${SEPARATOR}${newid()}`
|
return `${DocumentTypes.SCREEN}${SEPARATOR}${newid()}`
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets parameters for retrieving screens for a particular page, this is a utility function for the getDocParams function.
|
* Gets parameters for retrieving screens, this is a utility function for the getDocParams function.
|
||||||
*/
|
*/
|
||||||
exports.getScreenParams = (pageId = null, otherProps = {}) => {
|
exports.getScreenParams = (screenId = null, otherProps = {}) => {
|
||||||
return getDocParams(DocumentTypes.SCREEN, pageId, otherProps)
|
return getDocParams(DocumentTypes.SCREEN, screenId, otherProps)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a new webhook ID.
|
||||||
|
* @returns {string} The new webhook ID which the webhook doc can be stored under.
|
||||||
|
*/
|
||||||
|
exports.generateWebhookID = () => {
|
||||||
|
return `${DocumentTypes.WEBHOOK}${SEPARATOR}${newid()}`
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue