Refactored based on feedback. Added a check to find.
This commit is contained in:
parent
b5d44dfcfd
commit
2b36b0337f
|
@ -1,21 +1,37 @@
|
||||||
import { getDefinition, getDefinitions } from "../../integrations"
|
import { getDefinition, getDefinitions } from "../../integrations"
|
||||||
import { BBContext } from "@budibase/types"
|
import { BBContext } from "@budibase/types"
|
||||||
|
|
||||||
export async function fetch(ctx: BBContext) {
|
async function fetchDefinitions(ctx: BBContext) {
|
||||||
try {
|
try {
|
||||||
const definitions = await getDefinitions()
|
const definitions = await getDefinitions()
|
||||||
delete definitions.AIRTABLE
|
delete definitions.AIRTABLE
|
||||||
ctx.status = 200
|
ctx.status = 200
|
||||||
ctx.body = definitions
|
ctx.body = definitions
|
||||||
|
|
||||||
|
return definitions
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching definitions:", error)
|
console.error("Error fetching definitions:", error)
|
||||||
ctx.status = 500
|
ctx.status = 500
|
||||||
ctx.body = { error: "Internal server error" }
|
ctx.body = { error: "Internal server error" }
|
||||||
|
|
||||||
|
return {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function fetch(ctx: BBContext) {
|
||||||
|
await fetchDefinitions(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
export async function find(ctx: BBContext) {
|
export async function find(ctx: BBContext) {
|
||||||
const def = await getDefinition(ctx.params.type)
|
const def = await getDefinition(ctx.params.type)
|
||||||
ctx.body = def
|
if (ctx.params.type in await fetchDefinitions(ctx)) {
|
||||||
ctx.status = 200
|
ctx.body = def;
|
||||||
|
ctx.status = 200;
|
||||||
|
} else {
|
||||||
|
ctx.status = 400;
|
||||||
|
ctx.body = {
|
||||||
|
message: `Cannot find definition '${ctx.params.type}'`,
|
||||||
|
status: 400,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue