mirror of https://github.com/Budibase/budibase.git
5 changed files with 57 additions and 4 deletions
@ -0,0 +1,19 @@ |
|||||
|
const CouchDB = require("../db") |
||||
|
const { createRoutingView } = require("./routingUtils") |
||||
|
const { ViewNames, getQueryIndex } = require("../db/utils") |
||||
|
|
||||
|
exports.getRoutingInfo = async appId => { |
||||
|
const db = new CouchDB(appId) |
||||
|
try { |
||||
|
const allRouting = await db.query(getQueryIndex(ViewNames.ROUTING)) |
||||
|
return allRouting.rows.map(row => row.value) |
||||
|
} catch (err) { |
||||
|
// check if the view doesn't exist, it should for all new instances
|
||||
|
if (err != null && err.name === "not_found") { |
||||
|
await createRoutingView(appId) |
||||
|
return exports.getRoutingInfo(appId) |
||||
|
} else { |
||||
|
throw err |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
const CouchDB = require("../db") |
||||
|
const { DocumentTypes, SEPARATOR, ViewNames } = require("../db/utils") |
||||
|
const SCREEN_PREFIX = DocumentTypes.SCREEN + SEPARATOR |
||||
|
|
||||
|
exports.createRoutingView = async appId => { |
||||
|
const db = new CouchDB(appId) |
||||
|
const designDoc = await db.get("_design/database") |
||||
|
const view = { |
||||
|
map: function(doc) { |
||||
|
if (doc._id.startsWith(SCREEN_PREFIX)) { |
||||
|
emit(doc._id, { |
||||
|
routing: doc.routing, |
||||
|
}) |
||||
|
} |
||||
|
}.toString(), |
||||
|
} |
||||
|
designDoc.views = { |
||||
|
...designDoc.views, |
||||
|
[ViewNames.ROUTING]: view, |
||||
|
} |
||||
|
await db.put(designDoc) |
||||
|
} |
||||
Loading…
Reference in new issue