Add allLinkDocs utils

This commit is contained in:
Adria Navarro 2023-12-29 13:03:59 +01:00
parent 4a481877de
commit e1c37e75a4
1 changed files with 17 additions and 2 deletions

View File

@ -1,5 +1,5 @@
import newid from "./newid"
import { db as dbCore } from "@budibase/backend-core"
import { context, db as dbCore } from "@budibase/backend-core"
import {
DocumentType,
FieldSchema,
@ -7,6 +7,7 @@ import {
VirtualDocumentType,
INTERNAL_TABLE_SOURCE_ID,
DatabaseQueryOpts,
LinkDocument,
} from "@budibase/types"
import { FieldTypes } from "../constants"
@ -127,10 +128,24 @@ export function generateLinkID(
/**
* Gets parameters for retrieving link docs, this is a utility function for the getDocParams function.
*/
export function getLinkParams(otherProps: any = {}) {
function getLinkParams(otherProps: Partial<DatabaseQueryOpts> = {}) {
return getDocParams(DocumentType.LINK, null, otherProps)
}
/**
* Gets all the link docs document from the current app db.
*/
export async function allLinkDocs() {
const db = context.getAppDB()
const response = await db.allDocs<LinkDocument>(
getLinkParams({
include_docs: true,
})
)
return response.rows.map(row => row.doc!)
}
/**
* Generates a new layout ID.
* @returns The new layout ID which the layout doc can be stored under.