From 2b36b0337f563b95070241affdf70553f177fbb5 Mon Sep 17 00:00:00 2001 From: Conor Webb Date: Thu, 22 Feb 2024 13:32:16 +0000 Subject: [PATCH] Refactored based on feedback. Added a check to find. --- .../server/src/api/controllers/integration.ts | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/server/src/api/controllers/integration.ts b/packages/server/src/api/controllers/integration.ts index 935148ff2f..02cb869fe0 100644 --- a/packages/server/src/api/controllers/integration.ts +++ b/packages/server/src/api/controllers/integration.ts @@ -1,21 +1,37 @@ import { getDefinition, getDefinitions } from "../../integrations" import { BBContext } from "@budibase/types" -export async function fetch(ctx: BBContext) { +async function fetchDefinitions(ctx: BBContext) { try { const definitions = await getDefinitions() delete definitions.AIRTABLE ctx.status = 200 ctx.body = definitions + + return definitions } catch (error) { console.error("Error fetching definitions:", error) ctx.status = 500 ctx.body = { error: "Internal server error" } + + return {} } } +export async function fetch(ctx: BBContext) { + await fetchDefinitions(ctx) +} + export async function find(ctx: BBContext) { const def = await getDefinition(ctx.params.type) - ctx.body = def - ctx.status = 200 + if (ctx.params.type in await fetchDefinitions(ctx)) { + ctx.body = def; + ctx.status = 200; + } else { + ctx.status = 400; + ctx.body = { + message: `Cannot find definition '${ctx.params.type}'`, + status: 400, + }; + } }