More typing fixes.
This commit is contained in:
parent
bc3658e2cb
commit
fe9e4d1c5a
|
@ -10,6 +10,7 @@ import {
|
|||
} from "@budibase/types"
|
||||
import sdk from "../../sdk"
|
||||
import * as pro from "@budibase/pro"
|
||||
import { isAutomationResults } from "../../automations/triggers"
|
||||
|
||||
const toJsonSchema = require("to-json-schema")
|
||||
const validate = require("jsonschema").validate
|
||||
|
@ -94,12 +95,16 @@ export async function trigger(ctx: BBContext) {
|
|||
{ getResponses: true }
|
||||
)
|
||||
|
||||
let collectedValue = response.steps.find(
|
||||
(step: any) => step.stepId === AutomationActionStepId.COLLECT
|
||||
)
|
||||
if (triggers.isAutomationResults(response)) {
|
||||
let collectedValue = response.steps.find(
|
||||
(step: any) => step.stepId === AutomationActionStepId.COLLECT
|
||||
)
|
||||
|
||||
ctx.status = 200
|
||||
ctx.body = collectedValue.outputs
|
||||
ctx.status = 200
|
||||
ctx.body = collectedValue?.outputs
|
||||
} else {
|
||||
ctx.throw(400, "Automation did not have a collect block.")
|
||||
}
|
||||
} else {
|
||||
await triggers.externalTrigger(target, {
|
||||
body: ctx.request.body,
|
||||
|
|
|
@ -3,7 +3,6 @@ import {
|
|||
AutomationStepDefinition,
|
||||
AutomationStepType,
|
||||
AutomationIOType,
|
||||
AutomationResults,
|
||||
Automation,
|
||||
AutomationCustomIOType,
|
||||
TriggerAutomationStepInputs,
|
||||
|
@ -78,7 +77,7 @@ export async function run({
|
|||
const db = context.getAppDB()
|
||||
let automation = await db.get<Automation>(inputs.automation.automationId)
|
||||
|
||||
const response: AutomationResults = await triggers.externalTrigger(
|
||||
const response = await triggers.externalTrigger(
|
||||
automation,
|
||||
{
|
||||
fields: { ...fieldParams },
|
||||
|
@ -88,9 +87,13 @@ export async function run({
|
|||
{ getResponses: true }
|
||||
)
|
||||
|
||||
return {
|
||||
success: true,
|
||||
value: response.steps,
|
||||
if (triggers.isAutomationResults(response)) {
|
||||
return {
|
||||
success: true,
|
||||
value: response.steps,
|
||||
}
|
||||
} else {
|
||||
throw new Error("Automation did not have a collect block")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -148,6 +148,14 @@ function rowPassesFilters(row: Row, filters: SearchFilters) {
|
|||
return filteredRows.length > 0
|
||||
}
|
||||
|
||||
export function isAutomationResults(
|
||||
response: AutomationResults | DidNotTriggerResponse | AutomationJob
|
||||
): response is AutomationResults {
|
||||
return (
|
||||
response !== null && "steps" in response && Array.isArray(response.steps)
|
||||
)
|
||||
}
|
||||
|
||||
export async function externalTrigger(
|
||||
automation: Automation,
|
||||
params: {
|
||||
|
|
|
@ -621,7 +621,7 @@ export default class TestConfiguration {
|
|||
}
|
||||
|
||||
async unpublish() {
|
||||
const response = await this._req(appController.unpublish, {
|
||||
const response = await this._req(appController.unpublish, undefined, {
|
||||
appId: this.appId,
|
||||
})
|
||||
this.prodAppId = undefined
|
||||
|
|
Loading…
Reference in New Issue