Routing API typing.
This commit is contained in:
parent
23d9808cb6
commit
efcdd360e3
|
@ -9,7 +9,7 @@ import { getUserMetadataParams, InternalTables } from "../../db/utils"
|
|||
import {
|
||||
AccessibleRolesResponse,
|
||||
Database,
|
||||
DestroyRoleResponse,
|
||||
DeleteRoleResponse,
|
||||
FetchRolesResponse,
|
||||
FindRoleResponse,
|
||||
Role,
|
||||
|
@ -199,7 +199,7 @@ export async function save(ctx: UserCtx<SaveRoleRequest, SaveRoleResponse>) {
|
|||
builderSocket?.emitRoleUpdate(ctx, role)
|
||||
}
|
||||
|
||||
export async function destroy(ctx: UserCtx<void, DestroyRoleResponse>) {
|
||||
export async function destroy(ctx: UserCtx<void, DeleteRoleResponse>) {
|
||||
const db = context.getAppDB()
|
||||
let roleId = ctx.params.roleId as string
|
||||
if (roles.isBuiltin(roleId)) {
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
import { getRoutingInfo } from "../../utilities/routing"
|
||||
import { roles } from "@budibase/backend-core"
|
||||
import { UserCtx } from "@budibase/types"
|
||||
import {
|
||||
FetchClientScreenRoutingResponse,
|
||||
FetchScreenRoutingResponse,
|
||||
ScreenRoutingJson,
|
||||
UserCtx,
|
||||
} from "@budibase/types"
|
||||
|
||||
const URL_SEPARATOR = "/"
|
||||
|
||||
class Routing {
|
||||
json: any
|
||||
json: ScreenRoutingJson
|
||||
|
||||
constructor() {
|
||||
this.json = {}
|
||||
}
|
||||
|
@ -43,7 +49,7 @@ class Routing {
|
|||
* @returns The routing structure, this is the full structure designed for use in the builder,
|
||||
* if the client routing is required then the updateRoutingStructureForUserRole should be used.
|
||||
*/
|
||||
async function getRoutingStructure() {
|
||||
async function getRoutingStructure(): Promise<{ routes: ScreenRoutingJson }> {
|
||||
const screenRoutes = await getRoutingInfo()
|
||||
const routing = new Routing()
|
||||
|
||||
|
@ -56,11 +62,13 @@ async function getRoutingStructure() {
|
|||
return { routes: routing.json }
|
||||
}
|
||||
|
||||
export async function fetch(ctx: UserCtx) {
|
||||
export async function fetch(ctx: UserCtx<void, FetchScreenRoutingResponse>) {
|
||||
ctx.body = await getRoutingStructure()
|
||||
}
|
||||
|
||||
export async function clientFetch(ctx: UserCtx) {
|
||||
export async function clientFetch(
|
||||
ctx: UserCtx<void, FetchClientScreenRoutingResponse>
|
||||
) {
|
||||
const routing = await getRoutingStructure()
|
||||
let roleId = ctx.user?.role?._id
|
||||
const roleIds = roleId ? await roles.getUserRoleIdHierarchy(roleId) : []
|
||||
|
|
|
@ -1,24 +1,19 @@
|
|||
import { createRoutingView } from "../../db/views/staticViews"
|
||||
import { ViewName, getQueryIndex, UNICODE_MAX } from "../../db/utils"
|
||||
import { context } from "@budibase/backend-core"
|
||||
import { ScreenRouting, Document } from "@budibase/types"
|
||||
import { ScreenRoutesViewOutput } from "@budibase/types"
|
||||
|
||||
interface ScreenRoutesView extends Document {
|
||||
id: string
|
||||
routing: ScreenRouting
|
||||
}
|
||||
|
||||
export async function getRoutingInfo(): Promise<ScreenRoutesView[]> {
|
||||
export async function getRoutingInfo(): Promise<ScreenRoutesViewOutput[]> {
|
||||
const db = context.getAppDB()
|
||||
try {
|
||||
const allRouting = await db.query<ScreenRoutesView>(
|
||||
const allRouting = await db.query<ScreenRoutesViewOutput>(
|
||||
getQueryIndex(ViewName.ROUTING),
|
||||
{
|
||||
startkey: "",
|
||||
endkey: UNICODE_MAX,
|
||||
}
|
||||
)
|
||||
return allRouting.rows.map(row => row.value as ScreenRoutesView)
|
||||
return allRouting.rows.map(row => row.value)
|
||||
} catch (err: any) {
|
||||
// check if the view doesn't exist, it should for all new instances
|
||||
/* istanbul ignore next */
|
||||
|
|
|
@ -13,3 +13,4 @@ export * from "./component"
|
|||
export * from "./integration"
|
||||
export * from "./metadata"
|
||||
export * from "./query"
|
||||
export * from "./screen"
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
import { ScreenRoutingJson } from "../../../documents"
|
||||
|
||||
export interface FetchScreenRoutingResponse {
|
||||
routes: ScreenRoutingJson
|
||||
}
|
||||
|
||||
export interface FetchClientScreenRoutingResponse
|
||||
extends FetchScreenRoutingResponse {}
|
|
@ -18,7 +18,7 @@ export interface FindRoleResponse extends Role {}
|
|||
|
||||
export type FetchRolesResponse = Role[]
|
||||
|
||||
export interface DestroyRoleResponse {
|
||||
export interface DeleteRoleResponse {
|
||||
message: string
|
||||
}
|
||||
|
||||
|
|
|
@ -24,3 +24,20 @@ export interface Screen extends Document {
|
|||
name?: string
|
||||
pluginAdded?: boolean
|
||||
}
|
||||
|
||||
export interface ScreenRoutesViewOutput extends Document {
|
||||
id: string
|
||||
routing: ScreenRouting
|
||||
}
|
||||
|
||||
export type ScreenRoutingJson = Record<
|
||||
string,
|
||||
{
|
||||
subpaths: Record<
|
||||
string,
|
||||
{
|
||||
screens: Record<string, string>
|
||||
}
|
||||
>
|
||||
}
|
||||
>
|
||||
|
|
Loading…
Reference in New Issue