-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15112 from Budibase/chore/api-typing-2
App service API typing - D -> R
- Loading branch information
Showing
47 changed files
with
426 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,32 @@ | ||
import { getDefinition, getDefinitions } from "../../integrations" | ||
import { SourceName, UserCtx } from "@budibase/types" | ||
import { | ||
SourceName, | ||
UserCtx, | ||
FetchIntegrationsResponse, | ||
FindIntegrationResponse, | ||
} from "@budibase/types" | ||
|
||
const DISABLED_EXTERNAL_INTEGRATIONS = [ | ||
SourceName.AIRTABLE, | ||
SourceName.BUDIBASE, | ||
] | ||
|
||
export async function fetch(ctx: UserCtx) { | ||
export async function fetch(ctx: UserCtx<void, FetchIntegrationsResponse>) { | ||
const definitions = await getDefinitions() | ||
for (let disabledIntegration of DISABLED_EXTERNAL_INTEGRATIONS) { | ||
delete definitions[disabledIntegration] | ||
} | ||
ctx.body = definitions | ||
} | ||
|
||
export async function find(ctx: UserCtx) { | ||
export async function find(ctx: UserCtx<void, FindIntegrationResponse>) { | ||
const sourceType = ctx.params?.type | ||
if (DISABLED_EXTERNAL_INTEGRATIONS.indexOf(sourceType) !== -1) { | ||
ctx.throw(400, `Invalid source type - ${sourceType} is not supported.`) | ||
} | ||
ctx.body = await getDefinition(ctx.params.type) | ||
const integration = await getDefinition(ctx.params.type) | ||
if (!integration) { | ||
ctx.throw(404, "Integration not found") | ||
} | ||
ctx.body = integration | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,45 @@ | ||
import { MetadataTypes } from "../../constants" | ||
import { generateMetadataID } from "../../db/utils" | ||
import { saveEntityMetadata, deleteEntityMetadata } from "../../utilities" | ||
import { context } from "@budibase/backend-core" | ||
import { BBContext } from "@budibase/types" | ||
import { | ||
UserCtx, | ||
MetadataType, | ||
GetMetadataTypesResponse, | ||
SaveMetadataRequest, | ||
SaveMetadataResponse, | ||
DeleteMetadataResponse, | ||
FindMetadataResponse, | ||
} from "@budibase/types" | ||
|
||
export async function getTypes(ctx: BBContext) { | ||
export async function getTypes(ctx: UserCtx<void, GetMetadataTypesResponse>) { | ||
ctx.body = { | ||
types: MetadataTypes, | ||
types: MetadataType, | ||
} | ||
} | ||
|
||
export async function saveMetadata(ctx: BBContext) { | ||
export async function saveMetadata( | ||
ctx: UserCtx<SaveMetadataRequest, SaveMetadataResponse> | ||
) { | ||
const { type, entityId } = ctx.params | ||
if (type === MetadataTypes.AUTOMATION_TEST_HISTORY) { | ||
if (type === MetadataType.AUTOMATION_TEST_HISTORY) { | ||
ctx.throw(400, "Cannot save automation history type") | ||
} | ||
ctx.body = await saveEntityMetadata(type, entityId, ctx.request.body) | ||
} | ||
|
||
export async function deleteMetadata(ctx: BBContext) { | ||
export async function deleteMetadata( | ||
ctx: UserCtx<void, DeleteMetadataResponse> | ||
) { | ||
const { type, entityId } = ctx.params | ||
await deleteEntityMetadata(type, entityId) | ||
ctx.body = { | ||
message: "Metadata deleted successfully", | ||
} | ||
} | ||
|
||
export async function getMetadata(ctx: BBContext) { | ||
export async function getMetadata(ctx: UserCtx<void, FindMetadataResponse>) { | ||
const { type, entityId } = ctx.params | ||
const db = context.getAppDB() | ||
const id = generateMetadataID(type, entityId) | ||
try { | ||
ctx.body = await db.get(id) | ||
} catch (err: any) { | ||
if (err.status === 404) { | ||
ctx.body = {} | ||
} else { | ||
ctx.throw(err.status, err) | ||
} | ||
} | ||
ctx.body = (await db.tryGet(id)) || {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.