From c9ab2c4fcbef6b0372a13b51ed3074d91ac29b5e Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 11 Aug 2022 15:29:51 +0100 Subject: [PATCH] Add fetch implementation for plugins and util for plugin params --- packages/server/src/api/controllers/plugin.ts | 12 ++++++++++-- packages/server/src/db/utils.js | 7 +++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/server/src/api/controllers/plugin.ts b/packages/server/src/api/controllers/plugin.ts index f742c7f10c..f76d2871b0 100644 --- a/packages/server/src/api/controllers/plugin.ts +++ b/packages/server/src/api/controllers/plugin.ts @@ -1,7 +1,7 @@ import { ObjectStoreBuckets } from "../../constants" import { extractPluginTarball } from "../../utilities/fileSystem" import { getGlobalDB } from "@budibase/backend-core/tenancy" -import { generatePluginID } from "../../db/utils" +import { generatePluginID, getPluginParams } from "../../db/utils" import { uploadDirectory } from "@budibase/backend-core/objectStore" export async function upload(ctx: any) { @@ -67,6 +67,14 @@ export async function upload(ctx: any) { } } -export async function fetch(ctx: any) {} +export async function fetch(ctx: any) { + const db = getGlobalDB() + const response = await db.allDocs( + getPluginParams(null, { + include_docs: true, + }) + ) + ctx.body = response.rows.map((row: any) => row.doc) +} export async function destroy(ctx: any) {} diff --git a/packages/server/src/db/utils.js b/packages/server/src/db/utils.js index ea3c0dadf2..ef40e05f7b 100644 --- a/packages/server/src/db/utils.js +++ b/packages/server/src/db/utils.js @@ -384,3 +384,10 @@ exports.getMultiIDParams = ids => { include_docs: true, } } + +/** + * Gets parameters for retrieving automations, this is a utility function for the getDocParams function. + */ +exports.getPluginParams = (pluginId = null, otherProps = {}) => { + return getDocParams(DocumentTypes.PLUGIN, pluginId, otherProps) +}