1
0
Fork 0
mirror of synced 2024-06-28 02:50:50 +12:00

Finishing up routing structure, now available on /api/routing.

This commit is contained in:
mike12345567 2020-11-17 18:12:21 +00:00
parent d63054a426
commit e20a26a84d

View file

@ -2,8 +2,38 @@ const { getRoutingInfo } = require("../../utilities/routing")
const { AccessController } = require("../../utilities/security/accessLevels")
async function getRoutingStructure(appId) {
let baseRouting = await getRoutingInfo(appId)
return baseRouting
const screenRoutes = await getRoutingInfo(appId)
const routing = {}
for (let screenRoute of screenRoutes) {
const fullpath = screenRoute.routing.route
// replace the first value with the home route
const subpaths = ["/"].concat(fullpath.split("/").splice(1))
// special case for when it is simply the home route "/", this creates a weird scenario
if (subpaths[1] === "") {
subpaths.splice(1, 1)
}
const accessLevel = screenRoute.routing.accessLevelId
// iterate through the tree initially to flesh out all the required subpaths
let currentPath = routing,
nextSubpath = routing
for (let subpath of subpaths) {
if (!nextSubpath[subpath]) {
nextSubpath[subpath] = {
subpaths: {},
}
}
currentPath = nextSubpath ? nextSubpath : currentPath[subpath]
nextSubpath = currentPath[subpath].subpaths
}
const correctPath = currentPath[subpaths[subpaths.length - 1]]
if (!correctPath.screens) {
correctPath.screens = {}
}
correctPath.screens[accessLevel] = screenRoute.id
correctPath.fullpath = fullpath
}
return { routes: routing }
}
exports.fetch = async ctx => {
@ -14,4 +44,5 @@ exports.clientFetch = async ctx => {
const routing = getRoutingStructure(ctx.appId)
// use the access controller to pick which access level is applicable to this user
const accessController = new AccessController(ctx.appId)
// TODO: iterate through the routes and pick which the user can access
}